Giter Club home page Giter Club logo

react-native-sqlite-2's Introduction

React Native SQLite 2

SQLite3 Native Plugin for React Native for Android, iOS, Windows and macOS. This plugin provides a WebSQL-compatible API to store data in a react native app, by using a SQLite database on the native side.

Inspired by fantastic work done by Nolan Lawson. It should be a drop-in replacement for react-native-sqlite-storage. It works pretty well with PouchDB on React Native app.

Used by

mozilla / notes Inkdrop

Why?

The reason for this plugin is that react-native-sqlite-storage has some problems when used with PouchDB:

This plugin solves these problems.

Newer SQLite3 on Android

Even the latest version of Android is several versions behind the latest version of SQLite, whereas iOS has newer version. React Native SQLite 2 uses sqlite-android which allows you to use the latest version of it with new SQLite features enabled:

Getting started

Add react-native-sqlite-2 to your dependencies:

$ npm install react-native-sqlite-2 --save

Link native dependencies

From react-native 0.60 autolinking will take care of the link step but don't forget to run pod install.

$ react-native link react-native-sqlite-2

iOS/macOS

If using cocoapods in the ios/ directory run

$ pod install

Android

Please make sure AndroidX is enabled in your project by editing android/gradle.properties and adding 2 lines:

android.useAndroidX=true
android.enableJetifier=true

Usage

import SQLite from 'react-native-sqlite-2'

const db = SQLite.openDatabase('test.db', '1.0', '', 1)
db.transaction(function(txn) {
  txn.executeSql('DROP TABLE IF EXISTS Users', [])
  txn.executeSql(
    'CREATE TABLE IF NOT EXISTS Users(user_id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(30))',
    []
  )
  txn.executeSql('INSERT INTO Users (name) VALUES (:name)', ['nora'])
  txn.executeSql('INSERT INTO Users (name) VALUES (:name)', ['takuya'])
  txn.executeSql('SELECT * FROM `users`', [], function(tx, res) {
    for (let i = 0; i < res.rows.length; ++i) {
      console.log('item:', res.rows.item(i))
    }
  })
})

See an example project for more detail.

Using with PouchDB

It can be used with pouchdb-adapter-react-native-sqlite.

import PouchDB from 'pouchdb-react-native'
import SQLite from 'react-native-sqlite-2'
import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite'

const SQLiteAdapter = SQLiteAdapterFactory(SQLite)
PouchDB.plugin(SQLiteAdapter)
var db = new PouchDB('mydb', { adapter: 'react-native-sqlite' })

Foreign key support

As part of database initialization, this library will enable foreign key support automatically on both iOS & Android. Thus, any tables that define foreign key constraints will have them enforced whether or not foreign key support is explicitly enabled/disabled by PRAGMA statements sent via SQL.

Changelog

See CHANGELOG.md

Contributing

See CONTRIBUTING.md

Original Cordova SQLite Bindings from Nolan Lawson

https://github.com/nolanlawson/cordova-plugin-sqlite-2

The issues and limitations for the actual SQLite can be found on this site.

react-native-sqlite-2's People

Contributors

amorgulis avatar beeks avatar chrmod avatar craftzdog avatar damiankrturner avatar dependabot[bot] avatar dergutemoritz avatar eminsr avatar f4z3k4s avatar hnq90 avatar ilmoraunio avatar jgtoriginal avatar jnpdx avatar kant avatar kudo avatar manbir-app-curefit avatar matinzd avatar mzonski avatar obdulia-losantos avatar p2k avatar paulmest avatar punksta avatar sirpy avatar yairopro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-sqlite-2's Issues

How to enable FTS5 module

The Readme says the following

React Native SQLite 2 uses sqlite-android which allows you to use the latest version of it with new SQLite features enabled:

JSON1 extension
Common Table expressions
Indexes on expressions
FTS5 extension

I have tried to send following sql queries :

 CREATE VIRTUAL TABLE email USING fts5(sender, title, body)

but I get following error :

Error: Failed query : CREATE VIRTUAL TABLE email USING fts5(sender, title, body) with params :  : Error: no such module: fts5 (Sqlite code 1 S
QLITE_ERROR), (OS error - 2:No such file or directory)
onError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:176228:35
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:177094:41
onSuccess@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:177279:15
tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27024:16
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27125:27
_callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30579:17
_callImmediatesPass@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30615:19
callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30834:33
callImmediates@[native code]
__callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2591:35
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2368:34
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2574:15
flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2367:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

Some research :
These folks at RNSqliteStorage can successfully use FTS5 but I can't get how.
andpor/react-native-sqlite-storage#387 (comment)

Is there anything I am missing ?

Android issue with syncing large attachments

I'm experiencing an Android issue in RN 60.5 that's not present in the demo RN 59.1.
https://github.com/craftzdog/pouchdb-react-native-demo

iOS does not have this issue.

When syncing an attachment (image) of size from 1mb to 10mb it works fine in the demo and successfully syncs. However, when running the identical code using RN 60.5 and any file over 1.6mb, I get an error:

Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'length' of null
TypeError: Cannot read property 'length' of null
    at parseHexString
    at SQLTask.sqlCallback
    at blob
    at onSuccess
    at tryCallOne
    at blob
    at blob
    at _callTimer
    at _callImmediatesPass
    at Object.callImmediates

I'm pretty sure this issue comes from something failing within the WebSQL transaction process:
https://github.com/nolanlawson/node-websql/blob/ab6d7e06e00909046b98250da71248802935a284/lib/websql/WebSQLTransaction.js#L54

I have the same setup in the demo app and the RN 60.5 test app with the same code MainApplication.java change:

try {
  Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
  field.setAccessible(true);
  field.set(null, 100 * 1024 * 1024); //the 100MB is the new size
} catch (Exception e) {
  if (e != null) {
    e.printStackTrace();
  }
}

There also seems to be an identical issue listed here, but this from 2016:
pouchdb/pouchdb#5500 (comment)

I have searched for differences between RN 59.1 and 60.5, but can't find any reason why there would be a difference.

Nothing happen when call to executeSql

Sometime in Android device, txn.executeSql not return anything, ( even error or success functions are not triggering ) . this is my code.

namespace DbConnection {
    export function getInstance() {
        return SQLite.openDatabase('test.db', '1.0', 'Test DB', 200000);
    }
}

class AdsDB {

    adsQueue: AdsQueue;

    constructor() {

    }

    successCB() {
        alert('DONE');
    }

    openCB() {
        // alert('DB Opened');
    }

    errorCB(error) {
        alert(JSON.stringify(error));
        return false;
    }


    getNextTrack(round: number, callback: (error: any, response?: any) => void) {
        DbConnection.getInstance().transaction((txn) => {

        -------------> GETTING TO HERE
    
            txn.executeSql(`SELECT * FROM PlayList WHERE round=:round AND playing_status=:playing_status
            AND played_count <= max_playable_count ORDER BY priority limit 1`, [round, 'PENDING'], (tx, res) => {

                ------------>  NOT GETTING TO HERE ..

                callback(undefined, res.rows.item(0));
            }, (error) => {
                ------------>  NOT GETTING TO HERE AS WELL ..
                callback(error);
            });
        });
    }
}

Plugin usage with pouchdb

Hi

How do we use this plugin with pouchdb? This doesn't seem to be working:

import PouchDB from 'pouchdb-react-native';
PouchDB.plugin(require('react-native-sqlite-2'));
testdb = new PouchDB('test', {adapter:'websql'});

Thanks

App startup time slow down

This library is great and I'm using in my app. Having cross platform access to full and updated SQLite, locally is powerful.

But I have issue with app startup time now, looking for pointers on how this could be optimized.

Before installing and linking on my RN app (0.61.5), cold app start from iOS home screen, TTI to first screen, was 1.9s. With react-native-sqlite-2 added and linked, TTI jumped to 4.8s. This is without import in JS code, so inline requires vs import makes no difference. The slowdown is just in the native library being linked in Xcode and binary generated.

Any idea why the significant slowdown, even on empty database, just by having the library natively linked?

Inserting Null into a Table on Android using Bound Parameters inserts the String "NULL" instead.

Greetings,

Whenever you attempt to insert a NULL value as a column on a table on an Android device, a String of "NULL" gets inserted instead.

For example, consider the behavior of the following test case.

db.transaction((tx) => {
  tx.executeSql('CREATE TABLE IF NOT EXISTS null_test (id INTEGER PRIMARY KEY, value STRING)', []);
  tx.executeSql('INSERT INTO null_test (value) VALUES (?)', [null]);
  tx.executeSql('SELECT value FROM null_test', [],
    (_, result) => {
      const { rows } = result;
      for (let i = 0; i < rows.length; i += 1) {
        const item = rows.item(i);
        console.log(i, item); // 0 {value: "NULL"}
      }
    });
  tx.executeSql('SELECT COUNT(*) as count FROM null_test WHERE value IS NULL', [],
    (_, result) => {
      const { rows } = result;
      for (let i = 0; i < rows.length; i += 1) {
        const item = rows.item(i);
        console.log(i, item); // 0 {count: 0}
      }
  });
  tx.executeSql('DROP TABLE IF EXISTS null_test', []);
});

One would expect the answers to be {value: null} and {count: 1} instead. This issue, ultimately, stems from the convertParamsToStringArray function, and more specifically it's use in the doUpdateInBackgroundAndPossiblyThrow method.

This is also an issue in the original cordova plugin. Ultimately the cause of the issue is the API provided by Android's SQLite library. The compileStatement method allows for the binding of individual parameters, but it doesn't allow for a variable length SELECT statement. Instead, in order to evaluate arbitrary SQL statements for SELECT statements rawQuery must be used. rawQuery only allows for a String[] as bound arguments. As such, it's certainly influenced the decision to use convertParamsToStringArray in both places.

The fix is relatively straight forward, since the plugin is using compileStatement and that allows for individual parameters to be bound, we can just do that, and resolve the issue automatically.

It would likely still be an issue for binding NULL in a SELECT statement, but it's not as a likely for that to occur, and I'm not certain how one gets around that while using any query method.

Thanks for your time, and the plugin,

Expect a Pull Request Shortly,

Thanks,

~ Ayiga

Execution failed for task ':react-native-sqlite-2:processReleaseResources'. > com.android.ide.common.process.ProcessException: Failed to execute aapt

I am unable to run this project on android.

Steps I followed:

react-native init <project-name>
npm i react-native-sqlite-2 --save
react-native link react-native-sqlite-2
react-native run-android

node: v8.11.3
npm: v5.6.0
react-native-cli: 2.0.1
react-native: 0.56.0

For android project build.gradle i have set

classpath 'com.android.tools.build:gradle:2.2.3'

Here's the stacktrace for the error:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':react-native-sqlite-2:processReleaseResources'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:98)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:68)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$RunTasksAction.execute(DefaultGradleLauncher.java:230)
        at org.gradle.initialization.DefaultGradleLauncher$RunTasksAction.execute(DefaultGradleLauncher.java:227)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:161)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:112)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:95)
        at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:66)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:31)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
Caused by: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Failed to execute aapt
        at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:185)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:82)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:115)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:109)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:109)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:90)
        ... 70 more
Caused by: com.android.ide.common.process.ProcessException: Failed to execute aapt
        at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:873)
        at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:178)
        ... 82 more
Caused by: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing '/Users/sagar/Library/Android/sdk/build-tools/23.0.1/aapt' with arguments {package -f --no-crunch -I /Users/sagar/Library/Android/sdk/platforms/android-23/android.jar -M /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/intermediates/manifests/aapt/release/AndroidManifest.xml -S /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/intermediates/res/merged/release -m -J /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/generated/source/r/release --custom-package dog.craftz.sqlite_2 --non-constant-id -0 apk --output-text-symbols /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/intermediates/bundles/release --no-version-vectors}
        at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
        at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
        at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
        at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:871)
        ... 83 more
Caused by: com.android.ide.common.process.ProcessException: Error while executing '/Users/sagar/Library/Android/sdk/build-tools/23.0.1/aapt' with arguments {package -f --no-crunch -I /Users/sagar/Library/Android/sdk/platforms/android-23/android.jar -M /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/intermediates/manifests/aapt/release/AndroidManifest.xml -S /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/intermediates/res/merged/release -m -J /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/generated/source/r/release --custom-package dog.craftz.sqlite_2 --non-constant-id -0 apk --output-text-symbols /Users/sagar/Documents/Interns-POC/pouchdbAndroid/node_modules/react-native-sqlite-2/android/build/intermediates/bundles/release --no-version-vectors}
        at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:75)
        at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:49)
        at com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:78)
        at com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:74)
        at com.google.common.util.concurrent.Futures$6.run(Futures.java:1319)
        at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:457)
        at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
        at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145)
        at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185)
        at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
        at com.android.build.gradle.internal.process.GradleProcessExecutor$1.run(GradleProcessExecutor.java:60)
Caused by: org.gradle.process.internal.ExecException: Process 'command '/Users/sagar/Library/Android/sdk/build-tools/23.0.1/aapt'' finished with non-zero exit value 1
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:369)
        at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:47)
        ... 9 more

A problem occurred configuring project ':app'.

I install and use react-native-sql-2 step by step from site . but i got this error
A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugApk'.
A problem occurred configuring project ':react-native-sqlite-2'.
> Could not resolve all dependencies for configuration ':react-native-sqlite-2:classpath'.
> Could not resolve com.android.tools.build:gradle:1.3.1.
Required by:
KhabarApp:react-native-sqlite-2:unspecified
> Could not resolve com.android.tools.build:gradle:1.3.1.
> Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'.
> Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'.
> Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection timed out: connect
Please Help me Solve this problem . Thanks in advanced.

Could not find com.android.tools.build:gradle:2.3.3

Hello

what should I do?
Today i update gradle 4.6 version, then install and link react-native-sqlite-2 package.

Sync Failed:
Could not find com.android.tools.build:gradle:2.3.3.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.jar
Required by:
project :react-native-sqlite-2

https://jcenter.bintray.com/com/android/tools/build/gradle/ --- The requested path was not found.

json_extract not working on android

I'm storing json data on a table and when running locally on on iOS it all works fine.
But when trying to run on android, it crashes with the message no such function json_extract
This is my query.

SELECT DISTINCT
	json_extract(geometry, '$.coordinates') as coordinates,
	json_extract(geometry, '$.type') as type,
	json_extract(properties, '$.track_line_id') as track_line_id
FROM features
WHERE json_extract(geometry, '$.type') LIKE '%String%'

Is the JSON1 extension not working on android?

Build error on android

Environment

react: 16.3.0-alpha.1
react-native: 0.54.0
react-native-sqlite-2: 1.5.2
npm: 5.7.1
yarn: 1.3.2
Windows: 10

Problem

I'm getting this error on use react-native run-android

:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
C:\Users\hj_ju\Desktop\tableionato-app\android\app\src\main\java\com\apptabelionato\MainApplication.java:6: error: package dog.craftz.sqlite_2 does not exist
import dog.craftz.sqlite_2.RNSqlite2Package;
                          ^
C:\Users\hj_ju\Desktop\tableionato-app\android\app\src\main\java\com\apptabelionato\MainApplication.java:27: error: cannot find symbol
            new RNSqlite2Package()
                ^
  symbol: class RNSqlite2Package
2 errors
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

Steps to reproduce

I just have installed and used react-native link react-native-sqlite-2 and after tried to run project in android simulator

WebSQL threw an error {"framesToPop":1,"code":"SQLiteError"}

I am facing this error recently which it leading to the library.
any idea how solve it?
my packages at the moment (related to sqlite 2 and pouchdb):
"pouchdb-adapter-react-native-sqlite": "^1.0.3",
"pouchdb-find": "^6.4.1",
"pouchdb-react-native": "^6.4.1",
"react": "16.6.1",
"react-native": "0.57.7",
"react-native-sqlite-2": "^1.7.0"

Android version 7

the full stack trace:
screenshot_2019-01-20-22-35-09

Production

I want to know , is craftzdog/react-native-sqlite-2 stable and production-ready?
Can I use this in my next big project?

ExceptionsManager.js:82 WebSQL threw an error Error: Row too big to fit into CursorWindow requiredPos=0, totalRows=1

ExceptionsManager.js:82 WebSQL threw an error Error: Row too big to fit into CursorWindow requiredPos=0, totalRows=1
    at massageError (SQLiteDatabase.js:8)
    at dearrayifyRow (SQLiteDatabase.js:20)
    at arrayMap (index.js:140)
    at map (index.js:1836)
    at onSuccess (SQLiteDatabase.js:86)
    at tryCallOne (core.js:37)
    at core.js:123
    at JSTimers.js:298
    at _callTimer (JSTimers.js:152)
    at _callImmediatesPass (JSTimers.js:200)
    at Object.callImmediates (JSTimers.js:473)
    at MessageQueue.__callImmediates (MessageQueue.js:337)
    at MessageQueue.js:135
    at MessageQueue.__guard (MessageQueue.js:314)
    at MessageQueue.flushedQueue (MessageQueue.js:134)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:130)
    at debuggerWorker.js:80

Slow query

CREATE TABLE
IF NOT EXISTS projects (
 id text PRIMARY KEY NOT NULL,
 name text NOT NULL,
 begin_date text,
 end_date text
)WITHOUT ROWID;

I have about 10k row and want select 100 row using the following query

SELECT * FROM projects WHERE id IN ("id1","id2",...,"id100")

In android 7 phone with 8 core cpu and 8Gig RAM(Also iOS device) (in release mode) . the query take about 2 sec but when I run the query in desktop PC in same database it take only 80ms

I also remove WITHOUT ROWID clause for test

Encryption support

Hi, by using this library, wondering if there's any option to encrypt the entire sqlite at rest?

Performance issues

I'm using this library in conjunction with pouchdb-adapter-react-native-sqlite ultimately to act as a performant backend for RxDB: our use case is supporting potentially offline devices.

I'm encountering a whole bunch of strange performance issues when running on Android specifically -- things seem to be very snappy on iOS.

I managed to get the Android profiler working, and came up with some results that I'm not sure how to interpret. It certainly looks like there are quite a few SQLite threads that are active during times that I'm doing database activity, and when I go look at their behaviour, I see things like String.charAt and looking items up from a hashmap as the source of a lot of the time spent. I'll attach some screenshots from the profiler, but if anyone has experienced this and has any ideas I'd love to hear them. Note that these performance issues do not seem to show up on iOS at all, everything is very snappy.

Screen Shot 2019-11-02 at 6 18 44 PM

Screen Shot 2019-11-02 at 6 18 38 PM

Screen Shot 2019-11-02 at 6 17 20 PM

Screen Shot 2019-11-02 at 6 16 49 PM

Screen Shot 2019-11-02 at 6 16 16 PM

Can't run two queries in same transaction with promises

I'd love to use SQLite in my React Native project, but I'm experiencing this issue:

sqlite.ts

const { default: SQLite } = require("react-native-sqlite-2");

class Sqlite {
	static db: any;
	
	static transact(func: (tx: any) => Promise<void>): Promise<void> {
		return new Promise((resolve, reject) => {
			this.db.transaction((tx: any) => {
				func(tx).then(() => {
					resolve();
				}).catch(e => {
					reject(e);
				});
			});
		});
	}
	
	static runQuery(tx: any, query: string, args: any[] = []): Promise<{ rows: any[] }> {
		return new Promise((resolve, reject) => {
			console.log("executing query", query, args);
			tx.executeSql(query, args, (tx: any, res: any) => {
				console.log("success");
				resolve({
					rows: res.rows,
				});
			 }, () => {
				 console.error("error");
				 reject();
			 });
		});
	}
	
	static async init() {
		this.db = SQLite.openDatabase('test.db', '1.0', 'Test Database', 2 * 1024 * 1024);
		
		console.log("init");
		
		await this.transact(async tx => {
			console.log("running first");
			await this.runQuery(tx, 'CREATE TABLE IF NOT EXISTS LOGS2 (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp TEXT)');

			console.log("running second");
			await this.runQuery(tx, 'SELECT * FROM LOGS2');
			console.log("done with both");
		});
		
		console.log("done with tx");
	}
}

export default Sqlite;

index.ts

import Sqlite from "./sqlite.ts"
Sqlite.init().then(() => {console.log("done with init")}).catch(e => {console.error("error", e)});

Log output is:

init
sqlite.ts:39 running first
sqlite.ts:20 executing query CREATE TABLE IF NOT EXISTS LOGS2 (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp TEXT) []
sqlite.ts:22 success
sqlite.ts:41 running second
sqlite.ts:20 executing query INSERT INTO LOGS2 (timestamp) VALUES (:timestamp) 

But if I remove the second query:

init
sqlite.ts:39 running first
sqlite.ts:20 executing query CREATE TABLE IF NOT EXISTS LOGS2 (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp TEXT) []
sqlite.ts:22 success
sqlite.ts:46 done with tx
App.tsx:84 test

Note that done with both is missing. Looks like an issue with promises, because I can run these two fine using the callback style. Maybe the transaction block closes before the others are run? By the way, I'm running this on Android.

Is there something I'm doing wrong here?

'WebSQL threw an error', { [Error: Error code 19: UNIQUE constraint failed: document-store.id]

Pouchdb 7.0
RN 0.59 iOS

here is the log file . https://gist.github.com/gaodeng/e4ed76b87dcb9858a62dde932c470490

it looks like the id is cutting away when createIndex.

2019-03-15 10:45:44.423539+0800 MoonFM[9420:486945] exec()
2019-03-15 10:45:44.423996+0800 MoonFM[9420:486945] queries: (
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733099996371",
            3,
            3,
            "{\"id\":\"55323361.55261791733099996371\\u0000323241\\u0000\\u000041_http://feeds.americanpublicmedia.org/marketplaceallinone\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"cd59bc6fd89fbeaa980cd2592924f810\",{\"status\":\"available\"},[]]}],\"seq\":3}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733299991947",
            4,
            4,
            "{\"id\":\"55323361.55261791733299991947\\u0000323241\\u0000\\u000041_https://www.npr.org/rss/podcast.php?id=510289\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"fc5106f174c607564213f3a6e68cbe48\",{\"status\":\"available\"},[]]}],\"seq\":4}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733299991947",
            5,
            5,
            "{\"id\":\"55323361.55261791733299991947\\u0000323241\\u0000\\u000041_https://www.npr.org/rss/podcast.php?id=510308\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"931b9c4d5f9c6d5c9faa207db35bcff7\",{\"status\":\"available\"},[]]}],\"seq\":5}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733299991947",
            6,
            6,
            "{\"id\":\"55323361.55261791733299991947\\u0000323241\\u0000\\u000041_https://www.npr.org/rss/podcast.php?id=510298\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"7de7450d3aaa5013f1cd1d0ea8e62d41\",{\"status\":\"available\"},[]]}],\"seq\":6}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733400000837",
            7,
            7,
            "{\"id\":\"55323361.55261791733400000837\\u0000323241\\u0000\\u000041_http://feed.thisamericanlife.org/talpodcast\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"b7b154e01599b8bbd93b6f6dd73be424\",{\"status\":\"available\"},[]]}],\"seq\":7}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733400000837",
            8,
            8,
            "{\"id\":\"55323361.55261791733400000837\\u0000323241\\u0000\\u000041_http://rss.art19.com/the-daily\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"adacaa183f3bf8ad08582d6985d2103d\",{\"status\":\"available\"},[]]}],\"seq\":8}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733400000837",
            9,
            9,
            "{\"id\":\"55323361.55261791733400000837\\u0000323241\\u0000\\u000041_https://feeds.megaphone.fm/stuffyoushouldknow\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"b84fc7b8d6cf80cdd272f75b77d13c12\",{\"status\":\"available\"},[]]}],\"seq\":9}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733400000837",
            10,
            10,
            "{\"id\":\"55323361.55261791733400000837\\u0000323241\\u0000\\u000041_http://nj.lizhi.fm/rss/206682.xml\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"d6e2d3804d875e79e84de7969f875b6e\",{\"status\":\"available\"},[]]}],\"seq\":10}"
        )
    ),
        (
        "INSERT INTO 'document-store' (id, winningseq, max_seq, json) VALUES (?,?,?,?);",
                (
            "55323361.55261791733400000837",
            11,
            11,
            "{\"id\":\"55323361.55261791733400000837\\u0000323241\\u0000\\u000041_http://www.ximalaya.com/album/2947060.xml\\u0000\\u0000\",\"rev_tree\":[{\"pos\":1,\"ids\":[\"bb107dcffa95d2c778787275fcdeffe6\",{\"status\":\"available\"},[]]}],\"seq\":11}"
        )
    )
)

Dump db

Hello,

Is there any way to dump the database into a file (db or sql file) ?

[Error: No useable methode found:["native","idb","localstorage"]

problem:

react-native use RxDB, I chose react-native-sqlite as an adapter ,When debugging mode is turned off,I got this error '[Error: No useable methode found:["native","idb","localstorage"]',
but Turning on debuge is normal.

code:

import * as RxDB from 'rxdb'
import SQLite from 'react-native-sqlite-2'
import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite'
const SQLiteAdapter = SQLiteAdapterFactory(SQLite)
RxDB.plugin(SQLiteAdapter)

let db = await RxDB.create({
        name: "userId",
        adapter: 'react-native-sqlite',
      })

console:

image

How to pre-populate db in ios ?

Hi,
How to pre-populate db in ios ? I added a www folder and added a pre-populated db there. But Ain't showing up. The test case works just fine. Am I making any mistake locating the db file ? Tried both ~sideline-app.db and ~/www/sideline-app/db
screen shot 2018-07-15 at 6 49 02 pm

screen shot 2018-07-15 at 7 07 10 pm

Add tests

To ensure the stability of this module, we'd like to add tests because any changes may affect each platform implementations.
I believe it would be good to import tests from Nolan's cordova-plugin-sqlite-2.
Since I have a lack of experience in tests for React Native modules, I would appreciate any contribution for it!

ld: symbol(s) not found for architecture x86_64

Getting following linking error:

Undefined symbols for architecture x86_64:
"_sqlite3_bind_double", referenced from:
-[RNSqlite2 bindStatement:withArg:atIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_bind_int64", referenced from:
-[RNSqlite2 bindStatement:withArg:atIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_bind_null", referenced from:
-[RNSqlite2 bindStatement:withArg:atIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_bind_text", referenced from:
-[RNSqlite2 bindStatement:withArg:atIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_close", referenced from:
-[RNSqlite2 dealloc] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_column_bytes", referenced from:
-[RNSqlite2 getSqlValueForColumnType:withStatement:withIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_column_count", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_column_double", referenced from:
-[RNSqlite2 getSqlValueForColumnType:withStatement:withIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_column_int64", referenced from:
-[RNSqlite2 getSqlValueForColumnType:withStatement:withIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_column_name", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_column_text", referenced from:
-[RNSqlite2 getSqlValueForColumnType:withStatement:withIndex:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_column_type", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_errcode", referenced from:
+[RNSqlite2 convertSQLiteErrorToString:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_errmsg", referenced from:
+[RNSqlite2 convertSQLiteErrorToString:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_finalize", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_last_insert_rowid", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_open", referenced from:
-[RNSqlite2 openDatabase:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_prepare_v2", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_step", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_stmt_readonly", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
"_sqlite3_total_changes", referenced from:
-[RNSqlite2 executeSql:withSqlArgs:withDb:withReadOnly:] in libRNSqlite2.a(RNSqlite2.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is anyone facing the same issue for using 'react-native-sqlite-2' for iOS react-native app?

Visual studio issue

For windows , I follow install instruction , It works before well (I installed it for months)

But today I have the following error

Severity Code Description Project File Line Suppression State
Error CS0006 Metadata file 'C:\projects\MyProject\node_modules\react-native-sqlite-2\windows\RNSqlite2\bin\x64\Debug\RNSqlite2.dll' could not be found MyProject CSC 1 Active

I clean / rebuild / unload and load project , but always I have this error

Error: Queries can be performed using SQLiteDatabase query or rawQuery methods only.

I am trying to get column names from table with following code:

db.transaction(txn => {
    txn.executeSql("PRAGMA table_info('table')", [], (txn, res) => {
        console.log(txn, res);
        resolve(res.rows);
    }, (txn, err) => {reject(err)});
});

But I get an exception: Error: Queries can be performed using SQLiteDatabase query or rawQuery methods only.

Unable to install RNSQLITE2

I'm simply trying to yarn add the component to use with pouchdb adapter, but cannot get pass the build issue below.

gypgyp  info it worked if it ends withinfo ok
 it worked if it ends with ok
gyp info using [email protected]
gypgyp  info infousing [email protected] | darwin | x64
 using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3150000/sqlite3.c
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3150000/sqlite3.c
  TOUCH Release/obj.target/deps/action_before_build.stamp
  TOUCH Release/obj.target/deps/action_before_build.stamp
  CC(target) Release/obj.target/sqlite3/gen/sqlite-autoconf-3150000/sqlite3.o
  CC(target) Release/obj.target/sqlite3/gen/sqlite-autoconf-3150000/sqlite3.o
rm: ./Release/.deps/Release/obj.target/sqlite3/gen/sqlite-autoconf-3150000/sqlite3.o.d.raw: No such file or directory
make: *** [Release/obj.target/sqlite3/gen/sqlite-autoconf-3150000/sqlite3.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/Cellar/node/10.4.1/libexec/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp  LIBTOOL-STATIC Release/sqlite3.a
 ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Darwin 17.6.0
gyp ERR! command "/usr/local/Cellar/node/10.4.1/bin/node" "/usr/local/Cellar/node/10.4.1/libexec/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/lib/binding/node-v64-darwin-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/lib/binding/node-v64-darwin-x64"
gyp ERR! cwd /Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3
gyp ERR! node -v v10.4.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'node-gyp build --fallback-to-build --module=/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/lib/binding/node-v64-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/lib/binding/node-v64-darwin-x64' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:961:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
node-pre-gyp ERR! System Darwin 17.6.0
node-pre-gyp ERR! command "/usr/local/Cellar/node/10.4.1/bin/node" "/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3
node-pre-gyp ERR! node -v v10.4.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.38
node-pre-gyp ERR! not ok
Failed to execute 'node-gyp build --fallback-to-build --module=/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/lib/binding/node-v64-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/phinoppix/workspace/pru/awb/workbench/node_modules/sqlite3/lib/binding/node-v64-darwin-x64' (1)
  CXX(target) Release/obj.target/node_sqlite3/src/database.o
In file included from ../src/database.cc:4:
In file included from ../src/database.h:10:
In file included from ../node_modules/nan/nan.h:192:
../node_modules/nan/nan_maybe_43_inl.h:112:15: error: no member named 'ForceSet' in 'v8::Object'
  return obj->ForceSet(isolate->GetCurrentContext(), key, value, attribs);

Versions used:
node = 10.4.1
react-native: 0.55.4
node_modules/nan = 2.10.0
node_modules/sqlite3 = 3.1.13

Use getDatabasePath instead of getFilesDir

I was trying to use Stetho to see the sqlite database and I could not. After looking through the file system, I noticed that you are storing the database files in the context.getFilesDir location, but I suspect tools like Stetho would work better if you used the context.getDatabasePath function instead.

[Windows] Uses private APIs?

When validating with the Windows App Certification Kit, I run into a problem at the check for private APIs.
I cannot upload a windows app to the store, because it tells me, sqlite uses internal APIs, as seen in the error list. Anyone up with a solution for this?

API AreFileApisANSI in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API CreateFileA in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API CreateFileMappingA in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API CreateFileMappingW in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API CreateFileW in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API GetFileSize in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API GetFullPathNameA in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API GetModuleHandleA in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API GetTempPathA in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API GetVersionExA in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API GetVersionExW in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API HeapValidate in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API LoadLibraryA in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API LoadLibraryW in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API LockFile in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API MapViewOfFile in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API UnhandledExceptionFilter in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API UnlockFile in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API VirtualProtect in kernel32.dll is not supported for this application type. sqlite3.dll calls this API.
API __dllonexit in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API __setusermatherr in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _amsg_exit in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _beginthreadex in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _endthreadex in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _errno in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _initterm in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _iob in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _lock in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _onexit in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API _unlock in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API abort in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API calloc in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API fprintf in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API free in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API fwrite in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API localtime in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API malloc in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API memcmp in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API memmove in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API qsort in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API realloc in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API strcmp in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API strlen in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API strncmp in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.
API vfprintf in msvcrt.dll is not supported for this application type. sqlite3.dll calls this API.

Ho to use the result of select in outside

Hi, I'm trying to implement this function that help me to use the result of select in outside but the setState function does not work. So how can I do it please?

selectFromTable(table_name, selected_columns, conditions) {
        console.log('selecting data...')
        let command = new SelectCommand();
        let db_cmd = command.select_from_table(table_name, selected_columns, conditions); //db_cmd = select * from Person for exemple

        var that = this;
        db.transaction((txn) => {
            txn.executeSql(db_cmd, [],  (tx, res) => {
                that.setState({select_res: res});
            });
        });
        return this.state.select_res;
    }

This my solution for promises or callbacks

Callback

selectFromTable(table_name, selected_columns, conditions, callback) {
        console.log('selecting data...')
        let command = new SelectCommand();
        let db_cmd = command.select_from_table(table_name, selected_columns, conditions);

        var that = this;
        db.transaction((txn) => {
            txn.executeSql(db_cmd, [],  (tx, res) => {
                callback(res)
            });
        });
    }

and when I trying to used it I use

db_cmd.selectFromTable('Person', ['*'], null, function(res) {
            console.log(res);
        });

Promises

async selectFromTable(table_name, selected_columns, conditions, callback) {
        console.log('selecting data...')
        let command = new SelectCommand();
        let db_cmd = command.select_from_table(table_name, selected_columns, conditions);

        var result = await db.transaction(async (txn) => {
            var select_res = await txn.executeSql(db_cmd, [],  (tx, res) => {
                select_res = res;
                return select_res;
            });
            result = select_res;
            return result;
        });
        return result;
    }

and when I trying to use it I use

create_data_base = async () => {
        let db_cmd = new DB_Command();
        var res = await db_cmd.selectFromTable('Person', ['*'], null).then((x) => {
            return x;
        });
        console.log(res);
    }

So what should be I do??

@craftzdog
@Kudo
@sammacbeth
@hnq90

undefined is not an object (evaluating 'RNSqlite2.exec')

I've got a problem when starting an SQL transaction. It also appear on your test application. The database is correctly opened and there is no error before the first SQL transaction. It appears regardless of the number and the type of SQL queries.

undefined is not an object (evaluating 'RNSqlite2.exec')
exec
    C:\wamp64\www\reactor\node_modules\react-native-sqlite-2\src\SQLiteDatabase.js:74:12
runBatch
    C:\wamp64\www\reactor\node_modules\websql\lib\websql\WebSQLTransaction.js:54:32
runAllSql
    C:\wamp64\www\reactor\node_modules\websql\lib\websql\WebSQLTransaction.js:96:11
_checkDone
    C:\wamp64\www\reactor\node_modules\websql\lib\websql\WebSQLTransaction.js:133:12
<unknown>
    C:\wamp64\www\reactor\node_modules\websql\lib\websql\WebSQLDatabase.js:62:4
run
    C:\wamp64\www\reactor\node_modules\immediate\lib\index.js:71:11
nextTick
    C:\wamp64\www\reactor\node_modules\immediate\lib\index.js:42:6
<unknown>
    C:\wamp64\www\reactor\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:262:23
_callTimer
    C:\wamp64\www\reactor\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:154:6
callTimers
    C:\wamp64\www\reactor\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:411:17
__callFunction
    C:\wamp64\www\reactor\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:299:47
<unknown>
    C:\wamp64\www\reactor\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26
__guard
    C:\wamp64\www\reactor\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:262:6
callFunctionReturnFlushedQueue
    C:\wamp64\www\reactor\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17

signal SIGABRT when trying to open database

My team recently updated a React Native application to 0.59 and found that our previous PouchDB configuration with SQLite and Cordova adpaters would no longer work. Thanks to your libraries it is now working in general 🎉, but runs into a weird crash that is hard to pin down.

It seems like when we try to load many PouchDB databases (~100 databases), the application will crash with error signal SIGABRT.

// File: RNSqlite2.m

-(NSValue*)openDatabase: (NSString*)dbName {
  logDebug(@"opening DB: %@", dbName);
  NSValue *cachedDB = [cachedDatabases objectForKey:dbName];
  if (cachedDB == nil) {
    logDebug(@"opening new db");
    NSString *fullDbPath = [self getPathForDB: dbName];
    logDebug(@"full path: %@", fullDbPath);
    const char *sqliteName = [fullDbPath UTF8String];
    sqlite3 *db;
    if (sqlite3_open(sqliteName, &db) != SQLITE_OK) {
      logDebug(@"cannot open database: %@", dbName); // shouldn't happen
    };
    cachedDB = [NSValue valueWithPointer:db];

    // **** Thread 499: signal SIGABRT on this line...
    [cachedDatabases setObject: cachedDB forKey: dbName];

  } else {
    logDebug(@"re-using existing db");
  }
  return cachedDB;
}

Screen Shot:
image

Any idea what could be the issue? Or what we could do to help debug this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.