GithubHelp home page GithubHelp logo

andpor / react-native-sqlite-storage Goto Github PK

View Code? Open in Web Editor NEW
2.7K 52.0 521.0 13.25 MB

Full featured SQLite3 Native Plugin for React Native (Android and iOS)

License: MIT License

Objective-C 14.22% JavaScript 28.70% Java 45.57% Ruby 0.42% C++ 10.92% C 0.16%

react-native-sqlite-storage's Introduction

react-native-sqlite-storage

SQLite3 Native Plugin for React Native for both Android (Classic and Native), iOS and Windows

Foundation of this library is based on Chris Brody's Cordova SQLite plugin.

Features:

  1. iOS and Android supported via identical JavaScript API.
  2. Android in pure Java and Native modes
  3. SQL transactions
  4. JavaScript interface via plain callbacks or Promises.
  5. Pre-populated SQLite database import from application bundle and sandbox
  6. Windows supports callback API, identical to iOS and Android

There are sample apps provided in test directory that can be used in with the AwesomeProject generated by React Native. All you have to do is to copy one of those files into your AwesomeProject replacing index.ios.js.

Please let me know your projects that use these SQLite React Native modules. I will list them in the reference section. If there are any features that you think would benefit this library please post them.

The library has been tested with React 16.2 (and earlier) and XCode 7,8,9 - it works fine out of the box without any need for tweaks or code changes. For XCode 7,8 vs. XCode 6 the only difference is that sqlite ios library name suffix is tbd instead of dylib.

Version 3.2 is the first version compatible with RN 0.40.

Installation

  npm install --save react-native-sqlite-storage

Then follow the instructions for your platform to link react-native-sqlite-storage into your project

Promises

To enable promises, run

SQLite.enablePromise(true);

iOS

Standard Method

** React Native 0.60 and above ** Run cd ios && pod install && cd ... Linking is not required in React Native 0.60 and above

** React Native 0.59 and below **

Step 1. Install Dependencies

With CocoaPods:

Add this to your Podfile which should be located inside the ios project subdirectory

pod 'React', :path => '../node_modules/react-native'
pod 'react-native-sqlite-storage', :path => '../node_modules/react-native-sqlite-storage'

Or use the sample Podfile included in the package by copying it over to ios subdirectory and replacing AwesomeProject inside of it with the name of your RN project.

Refresh the Pods installation

pod install

OR

pod update

Done, skip to Step 2.

Without CocoaPods:

This command should be executed in the root directory of your RN project

react-native link

rnpm and xcode are dependencies of this project and should get installed with the module but in case there are issue running rnpm link and rnpm/xcode are not already installed you can try to install it globally as follows:

npm -g install rnpm xcode

After linking project should like this:

alt tag

Step 1a. If rnpm link does not work for you you can try manually linking according to the instructions below:

Drag the SQLite Xcode project as a dependency project into your React Native XCode project

alt tag

XCode SQLite libraries dependency set up

Add libSQLite.a (from Workspace location) to the required Libraries and Frameworks. Also add sqlite3.0.tbd (XCode 7) or libsqlite3.0.dylib (XCode 6 and earlier) in the same fashion using Required Libraries view (Do not just add them manually as the build paths will not be properly set)

alt tag

Step 2. Application JavaScript require

Add var SQLite = require('react-native-sqlite-storage') to your index.ios.js

alt tag

Step 3. Write application JavaScript code using the SQLite plugin

Add JS application code to use SQLite API in your index.ios.js etc. Here is some sample code. For full working example see test/index.ios.callback.js. Please note that Promise based API is now supported as well with full examples in the working React Native app under test/index.ios.promise.js

errorCB(err) {
  console.log("SQL Error: " + err);
},

successCB() {
  console.log("SQL executed fine");
},

openCB() {
  console.log("Database OPENED");
},

var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
db.transaction((tx) => {
  tx.executeSql('SELECT * FROM Employees a, Departments b WHERE a.department = b.department_id', [], (tx, results) => {
      console.log("Query completed");

      // Get rows with Web SQL Database spec compliance.

      var len = results.rows.length;
      for (let i = 0; i < len; i++) {
        let row = results.rows.item(i);
        console.log(`Employee name: ${row.name}, Dept Name: ${row.deptName}`);
      }

      // Alternatively, you can use the non-standard raw method.

      /*
        let rows = results.rows.raw(); // shallow copy of rows Array

        rows.map(row => console.log(`Employee name: ${row.name}, Dept Name: ${row.deptName}`));
      */
    });
});

How to use (Android):

** React Native 0.60 and above ** If you would like to use the devices SQLite there are no extra steps. However, if you would like to use the SQLite bundled with this library (includes support for FTS5), add the following to your react-native.config.js

module.exports = {
  ...,
  dependencies: {
    ...,
    "react-native-sqlite-storage": {
      platforms: {
        android: {
          sourceDir:
            "../node_modules/react-native-sqlite-storage/platforms/android-native",
          packageImportPath: "import io.liteglue.SQLitePluginPackage;",
          packageInstance: "new SQLitePluginPackage()"
        }
      }
    }
    ...
  }
  ...
};

** React Native 0.59 and below **

Step 1 - Update Gradle Settings (located under Gradle Settings in Project Panel)

// file: android/settings.gradle
...

include ':react-native-sqlite-storage'
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/platforms/android') // react-native-sqlite-storage >= 4.0.0
// IMPORTANT: if you are working with a version less than 4.0.0 the project directory is '../node_modules/react-native-sqlite-storage/src/android'

Step 2 - Update app module Gradle Build script (located under Gradle Settings in Project Panel)

// file: android/app/build.gradle
...

dependencies {
    ...
    implementation project(':react-native-sqlite-storage')
}

Step 3 - Register React Package (this should work on React version but if it does not , try the ReactActivity based approach. Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor

...
import org.pgsqlite.SQLitePluginPackage;

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

    private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")  // this is dependant on how you name you JS files, example assumes index.android.js
                .setJSMainModuleName("index.android")        // this is dependant on how you name you JS files, example assumes index.android.js
                .addPackage(new MainReactPackage())
                .addPackage(new SQLitePluginPackage())       // register SQLite Plugin here
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null); //change "AwesomeProject" to name of your app
        setContentView(mReactRootView);
    }
...

Alternative approach on newer versions of React Native (0.18+). Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor

import org.pgsqlite.SQLitePluginPackage;

public class MainApplication extends Application implements ReactApplication {
  ......

  /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new SQLitePluginPackage(),   // register SQLite Plugin here
        new MainReactPackage());
    }
}

Step 4 - Require and use in Javascript - see full examples (callbacks and Promise) in test directory.

// file: index.android.js

var React = require('react-native');
var SQLite = require('react-native-sqlite-storage')
...

Windows

** RNW 0.63 with Autolinking and above **

No manual steps required

** React Native 0.62 **

Step 1: Update the solution file

Add the SQLitePlugin project to your solution.

  1. Open the solution in Visual Studio 2019
  2. Right-click Solution icon in Solution Explorer > Add > Existing Project
  3. Select node_modules\react-native-sqlite-storage\platforms\windows\SQLitePlugin\SQLitePlugin.vcxproj

Step 2: Update the .vcxproj file

Add a reference to SQLitePlugin to your main application project. From Visual Studio 2019:

  1. Right-click main application project > Add > Reference...
  2. Check SQLitePlugin from Solution Projects

Step 3: Update the pch.h file

Add #include "winrt/SQLitePlugin.h".

Step 4: Register the package in App.cpp

Add PackageProviders().Append(winrt::SQLitePlugin::ReactPackageProvider()); before InitializeComponent();.

Refer to this guide for more details: https://microsoft.github.io/react-native-windows/docs/next/native-modules-using

Setting up your project to import a pre-populated SQLite database from application for iOS

Step 1 - Create 'www' folder.

Create a folder called 'www' (yes must be called precisely that else things won't work) in the project folder via Finder

Step 2 - Create the database file

Copy/paste your pre-populated database file into the 'www' folder. Give it the same name you are going to use in openDatabase call in your application

Step 3 - Add file to project

in XCode, right click on the main folder and select Add Files to 'your project name'

alt tag

Step 4 - Choose files to add

In the Add Files dialog, navigate to the 'www' directory you created in Step 1, select it, make sure you check the option to Create Folder Reference

alt tag

Step 5 - Verify project structure

Ensure your project structure after previous steps are executed looks like this

alt tag

Step 6 - Adjust openDatabase call

Modify you openDatabase call in your application adding createFromLocation param. If you named your database file in step 2 'testDB' the openDatabase call should look like something like this:

  ...
  1.SQLite.openDatabase({name : "testDB", createFromLocation : 1}, okCallback,errorCallback);
  // default - if your folder is called www and data file is named the same as the dbName - testDB in this example
  2.SQLite.openDatabase({name : "testDB", createFromLocation : "~data/mydbfile.sqlite"}, okCallback,errorCallback);
  // if your folder is called data rather than www or your filename does not match the name of the db
  3.SQLite.openDatabase({name : "testDB", createFromLocation : "/data/mydbfile.sqlite"}, okCallback,errorCallback);
  // if your folder is not in app bundle but in app sandbox i.e. downloaded from some remote location.
  ...

For Android, the www directory is always relative to the assets directory for the app: src/main/assets

Enjoy!

Opening a database

Opening a database is slightly different between iOS and Android. Where as on Android the location of the database file is fixed, there are three choices of where the database file can be located on iOS. The 'location' parameter you provide to openDatabase call indicated where you would like the file to be created. This parameter is neglected on Android.

WARNING: the default location on iOS has changed in version 3.0.0 - it is now a no-sync location as mandated by Apple so the release is backward incompatible.

To open a database in default no-sync location (affects iOS only)::

SQLite.openDatabase({name: 'my.db', location: 'default'}, successcb, errorcb);

To specify a different location (affects iOS only):

SQLite.openDatabase({name: 'my.db', location: 'Library'}, successcb, errorcb);

where the location option may be set to one of the following choices:

  • default: Library/LocalDatabase subdirectory - NOT visible to iTunes and NOT backed up by iCloud
  • Library: Library subdirectory - backed up by iCloud, NOT visible to iTunes
  • Documents: Documents subdirectory - visible to iTunes and backed up by iCloud
  • Shared: app group's shared container - see next section

The original webSql style openDatabase still works and the location will implicitly default to 'default' option:

SQLite.openDatabase("myDatabase.db", "1.0", "Demo", -1);

Opening a database in an App Group's Shared Container (iOS)

If you have an iOS app extension which needs to share access to the same DB instance as your main app, you must use the shared container of a registered app group.

Assuming you have already set up an app group and turned on the "App Groups" entitlement of both the main app and app extension, setting them to the same app group name, the following extra steps must be taken:

Step 1 - supply your app group name in all needed Info.plists

In both ios/MY_APP_NAME/Info.plist and ios/MY_APP_EXT_NAME/Info.plist (along with any other app extensions you may have), you simply need to add the AppGroupName key to the main dictionary with your app group name as the string value:

<plist version="1.0">
<dict>
  <!-- ... -->
  <key>AppGroupName</key>
  <string>MY_APP_GROUP_NAME</string>
  <!-- ... -->
</dict>
</plist>

Step 2 - set shared database location

When calling SQLite.openDatabase in your React Native code, you need to set the location param to 'Shared':

SQLite.openDatabase({name: 'my.db', location: 'Shared'}, successcb, errorcb);

Importing a pre-populated database.

You can import an existing - prepopulated database file into your application. Depending on your instructions in openDatabase call, the sqlite-storage will look at different places to locate you pre-populated database file.

Use this flavor of openDatabase call, if your folder is called www and data file is named the same as the dbName - testDB in this example

SQLite.openDatabase({name : "testDB", createFromLocation : 1}, okCallback,errorCallback);

Use this flavor of openDatabase call if your folder is called data rather than www or your filename does not match the name of the db. In this case db is named testDB but the file is mydbfile.sqlite which is located in a data subdirectory of www

SQLite.openDatabase({name : "testDB", createFromLocation : "~data/mydbfile.sqlite"}, okCallback,errorCallback);

Use this flavor of openDatabase call if your folder is not in application bundle but in app sandbox i.e. downloaded from some remote location. In this case the source file is located in data subdirectory of Documents location (iOS) or FilesDir (Android).

SQLite.openDatabase({name : "testDB", createFromLocation : "/data/mydbfile.sqlite"}, okCallback,errorCallback);

Additional options for pre-populated database file

You can provide additional instructions to sqlite-storage to tell it how to handle your pre-populated database file. By default, the source file is copied over to the internal location which works in most cases but sometimes this is not really an option particularly when the source db file is large. In such situations you can tell sqlite-storage you do not want to copy the file but rather use it in read-only fashion via direct access. You accomplish this by providing an additional optional readOnly parameter to openDatabase call

SQLite.openDatabase({name : "testDB", readOnly: true, createFromLocation : "/data/mydbfile.sqlite"}, okCallback,errorCallback);

Note that in this case, the source db file will be open in read-only mode and no updates will be allowed. You cannot delete a database that was open with readOnly option. For Android, the read only option works with pre-populated db files located in FilesDir directory because all other assets are never physically located on the file system but rather read directly from the app bundle.

Attaching another database

Sqlite3 offers the capability to attach another database to an existing database-instance, i.e. for making cross database JOINs available. This feature allows to SELECT and JOIN tables over multiple databases with only one statement and only one database connection. To archieve this, you need to open both databases and to call the attach()-method of the destination (or master) -database to the other ones.

let dbMaster, dbSecond;

dbSecond = SQLite.openDatabase({name: 'second'},
  (db) => {
    dbMaster = SQLite.openDatabase({name: 'master'},
      (db) => {
        dbMaster.attach( "second", "second", () => console.log("Database attached successfully"), () => console.log("ERROR"))
      },
      (err) => console.log("Error on opening database 'master'", err)
    );
  },
  (err) => console.log("Error on opening database 'second'", err)
);

The first argument of attach() is the name of the database, which is used in SQLite.openDatabase(). The second argument is the alias, that is used to query on tables of the attached database.

The following statement would select data from the master database and include the "second"-database within a simple SELECT/JOIN-statement:

SELECT * FROM user INNER JOIN second.subscriptions s ON s.user_id = user.id

To detach a database, just use the detach()-method:

dbMaster.detach( 'second', successCallback, errorCallback );

For sure, their is also Promise-support available for attach() and detach(), as shown in the example-application under the directory "examples".

Original Cordova SQLite Bindings from Chris Brody and Davide Bertola

https://github.com/litehelpers/Cordova-sqlite-storage

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

Issues

  1. Android binds all numeric SQL input values to double. This is due to the underlying React Native limitation where only a Numeric type is available on the interface point making it ambiguous to distinguish integers from doubles. Once I figure out the proper way to do this I will update the codebase [(Issue #4141)] (facebook/react-native#4141).

react-native-sqlite-storage's People

Contributors

abdurrahmanekr avatar ahizzle avatar alpha0010 avatar andpor avatar azeemhassni avatar barbarosh avatar carlosroberto555 avatar clytras avatar daleljefferson avatar damiencornu avatar dantman avatar davidkuennen avatar deongroenewald avatar dryganets avatar eduardoledo avatar enieber avatar ferbeb avatar frolovdev avatar gvanderclay avatar harkindey avatar itinance avatar jastanton avatar joshwalkerjolt avatar jschloer avatar k-leon avatar lmiller1990 avatar paulmest avatar poltak avatar pori avatar spruce-bruce 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  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

react-native-sqlite-storage's Issues

peerDependency!

npm WARN peerDependencies The peer dependency react-native@>=0.14.0 included from react-native-sqlite-storage will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm ERR! Linux 3.19.0-42-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "--save" "react-native-sqlite-storage"
npm ERR! node v4.2.4
npm ERR! npm  v2.14.12
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants react-native@>=0.14.0

error: constructor SQLitePluginPackage in class SQLitePluginPackage cannot be applied to given types

Hi,
When i try to install the plugin on a fresh android project, I got the following error:

MainActivity.java:40: error: constructor SQLitePluginPackage in class SQLitePluginPackage cannot be applied to given types;
            new SQLitePluginPackage()
            ^
  required: Activity
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error
:app:compileDebugJavaWithJavac FAILED

and this is the dependencies:
"react": "15.2.0",
"react-native": "0.28.0",
"react-native-sqlite-storage": "^3.0.0"

Any Idea about the cause of the issue?
Thank you.

Question about opening an existing database

I have a pre-filled sqlite database, what steps are required to get this to open the provided file vs creating a new one?

my db file is called trivia.sqlite I'm using this to open it:

this.db = sqlite.openDatabase("trivia.sqlite", "1.0", "Trivia DB", 200000, this.openCB, this.errorCB);

It opens fine but when I try to get some data out it says: code 5: 'no such table'

integer overflow

The sqlite integer value should stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
But on android, I tried two of my android phones
create table bbb (b integer)
insert into bbb(b) values (1458743338878) // time millisecond
select * from bbb

It turns out b = -1545541762
I change the type integer to int int8 bigint and it is always the same result. unless I use real.
I'm not sure the problem related to this driver. But on ios it has no problem.

libSQLite.a missing

Having trouble getting or compiling the libSQL.a file. Can you give some pointers on how to obtain the file?

Same for the libsqlite3.0.dylib file. Not sure where to find it.

Thank you

Clearing App Data Issue.

Hello I'm currently having a problem with our app using your module. It was for a function that should clear the App Data of our app. We're returned the error below:

undefined is not an object(evaluating NativeModules SQLite method)

Do you have any idea if this can be resolved?
errrr

SQLite open is not defined

I'm newbie in React Native, i need to store user data in SQLite.

Unfortunately almost all documentations and examples of React Native SQLite usage are in old syntax and i don't know exactly how to use them in newer ES6 Syntax.

here is my code :

'use strict';
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TabBarIOS,
  NavigatorIOS,
} from 'react-native';

import SQLite from 'react-native-sqlite-storage';
SQLite.DEBUG(true);

var Courses = require("./courses.ios");
var Evaluation = require("./evaluation.ios");
var Schedule = require("./schedule.ios");
var More = require("./more.ios");
var Register = require("./register.ios");
var Login = require("./login.ios");
var AuthService = require("./AuthService");

class OpenCampus extends Component {

  constructor(props){
    super(props);
    this.state = {
      selectedTab: 'courses',
      isLoggedIn: false,
    };
  }

  /////// Database
  callDB(){
    SQLite.open("oc.db", function(error, database){
      if (error) {
        console.log("Failed to open database:", error);
        return;
      }
    });
  }
  /////// End Database


  onLogin(results) {
    this.setState({
      isLoggedIn: true,
    });
  }

  render() {
    callDB();

    if(!this.state.isLoggedIn){
      return(
        <Login onLogin={this.onLogin.bind(this)} />
      );
    } else {

      return(
        <TabBarIOS
        selectedTab={this.state.selectedTab}
        >

        <TabBarIOS.Item
        icon={{uri: 'courses.png', scale: 5}}
        title="Courses"
        badge={undefined}
        selected={this.state.selectedTab === 'courses'}
        onPress={() => {
          this.setState({
            selectedTab: 'courses',
          });
        }}>
        <Courses />
        </TabBarIOS.Item>

        <TabBarIOS.Item
        icon={{uri: 'register.png', scale: 5}}
        title="Register"
        badge={undefined}
        selected={this.state.selectedTab === 'register'}
        onPress={() => {
          this.setState({
            selectedTab: 'register',
          });
        }}>
        <Register />
        </TabBarIOS.Item>

        <TabBarIOS.Item
          title="Evaluation"
          icon={{uri: 'evaluate.png', scale: 10}}
          badge={undefined}
          selected={this.state.selectedTab === 'evaluation'}
          onPress={() => {
            this.setState({
              selectedTab: 'evaluation',
            });
          }}>
          <Evaluation />
          </TabBarIOS.Item>

          <TabBarIOS.Item
            title="Schedule"
            icon={{uri: 'schedule.png', scale: 5}}
            badge={undefined}
            selected={this.state.selectedTab === 'schedule'}
            onPress={() => {
              this.setState({
                selectedTab: 'schedule',
              });
            }}>
            <Schedule />
            </TabBarIOS.Item>

            <TabBarIOS.Item
              systemIcon="more"
              badge={undefined}
              selected={this.state.selectedTab === 'more'}
              onPress={() => {
                this.setState({
                  selectedTab: 'more',
                });
              }}>
              <More />
              </TabBarIOS.Item>

        </TabBarIOS>
      );
    }
  }
}

AppRegistry.registerComponent('OpenCampus', () => OpenCampus);

I tried defining and calling it inside render like this :

render(){
SQLite.open("oc.db", function(error, database){
      if (error) {
        console.log("Failed to open database:", error);
        return;
      }
    });
.
.
.

and when i run it in emulator, it says >
_reactNativeSqliteStorage2.default.open is not a function

Im sorry if im asking this in a wrong place.

looking forward to hearing from you

also it would be great if somebody could write a simple usage of SQLite in this syntax (add a value to sqlite, then call it)

Transactions don't rollback when a statement fails and Promises are enabled

When promises are enabled, transactions don't rollback if an executeSql statement fails.

For example:

  try {
    db = await SQLite.openDatabase('test.db');
    await db.transaction(tx => {
        tx.executeSql('INCORRECT SQL');
    });
  }
  catch (e) {
   // Never called, the transaction has been committed
    console.log(e);
  } 

The issue is that this catch block that can abort the transaction is not called when Promises are enabled.
handleStatementFailure does not throw because with promises because an error handler is always provided.

When using callbacks, the transaction is aborted but the error message is incorrectly wrapped in this.

Maybe transaction objects (tx in example above) should be different in a transaction context and not return promises or expect errors/success callbacks (and the transaction method expects all statements to be enlisted synchronously) . Any failure should be available in the error callback/catch promise handler of the encompassing transaction.

Multiple Views

Hello, i have 2 views MainPage, SecondPage

In each view, I again open the database and execute transaction, but when open SecondPage i get error cannot start next transaction: database not open

My logs:

I/ReactNativeJS( 2164): OPEN database: data.sqlite
I/ReactNativeJS( 2164): new transaction is waiting for open operation
I/ReactNativeJS( 2164): DB opened: data.sqlite
I/ReactNativeJS( 2164): Transaction OK
I/ReactNativeJS( 2164): CLOSE database: data.sqlite
I/ReactNativeJS( 2164): closing db with transaction queue length: 0
I/ReactNativeJS( 2164): cannot start next transaction: database not open
I/ReactNativeJS( 2164): Database is closed OK

Please, help me. Thanks

Question: this vs WebSQL (vs IndexedDB shim)?

Is this package an implementation of the WebSQL standard?

I see this in readme: "The original Cordova plugin was written so well and adhered to latest WebSQL API that there was no need to come up with anything much different. So the Cordova plugin was ported to React Native." (emphasis mine)

Does this mean that this package also "adheres to WebSQL API"?

In particular, I am looking into feasibility of porting an existing IndexedDB shim that uses WebSQL as backend. Do you think it makes sense to try to port/reconfigure said shim to use RNSS as backend?

Delete and update

Delete and update operations such as no callback function, how should I determine whether success

Test android-native performance.

@andpor Android-native implementation timing for 20k - 20200ms. Old implementation timing 13000ms. May be problem in verbose mode sqlite-native-driver. How to disable verbose mode ?

11-17 12:20:43.383 28403-28502/com.reactapp V/sqlg: sqlc_st_column_name 0xb3ac4928 1
11-17 12:20:43.383 28403-28502/com.reactapp V/sqlg: sqlc_st_column_type 0xb3ac4928 1
11-17 12:20:43.383 28403-28502/com.reactapp V/sqlg: sqlc_st_column_name 0xb3ac4928 3

How do I register the package in android?

I didn't quite get how to install the Step 4 of the android instalation.
Do I need to change the MainActivity.java file or should I create another file?
Best Regards.

3 errors for installation of native +18

/Users/valleyreign/testSqlite/android/app/src/main/java/com/testsqlite/MainActivity.java:38: error: ';' expected
new SQLitePluginPackage(this)) // register SQLite Plugin here
^
/Users/valleyreign/testSqlite/android/app/src/main/java/com/testsqlite/MainActivity.java:39: error: ';' expected
new MainReactPackage());
^
/Users/valleyreign/testSqlite/android/app/src/main/java/com/testsqlite/MainActivity.java:40: error: reached end of file while parsing
}
^
3 errors
:app:compileDebugJavaWithJavac FAILED

Cannot read property 'open' of undefined

Problems with booleans

At line 421:

params.push((v === null || v === void 0 || t === 'number' || t === 'string' ? v : v instanceof Blob ? v.valueOf() : v.toString()));

If it is neither null nor 0 nor number nor string but boolean, then the v instanceof Blob condition is evaluated. There is no Blob in React Native (at least on Android), so this throws, but the exception is caught somewhere down the stack and converted to console warning (took a while to notice!) w/o fixing the problem.

Shimming Blob = function(){} seems to quickfix the exception but doesn't really help handle booleans. WebSQL is supposed to be able to store booleans but the code above will probably end up storing strings "true" and "false", which will both evaluate to true to an application that expects actual booleans returned from the database.

the path for database file

If I create the data file in www directory and add the dir to my project by the Xcode guild, I write the below code:

SQLite.openDatabase({name : "fufm.db", createFromLocation : 1})

I find the logs like:

2016-05-01 18:37:32.774 [info][tid:com.facebook.React.JavaScript] OPEN database: fufm.db
2016-05-01 18:37:32.775 [info][tid:com.facebook.React.JavaScript] SQLite.open({"name":"fufm.db","dblocation":"docs"})
2016-05-01 18:37:32.784 fufmapp[2442:98559] using db location: docs
2016-05-01 18:37:32.784 fufmapp[2442:98559] open full db path: /Users/Bing/Library/Developer/CoreSimulator/Devices/EA31E7E2-57FC-47DE-9FC5-82624C501283/data/Containers/Data/Application/160C3855-0D8B-4820-A8EB-17DA0B783B4C/Documents/fufm.db

but in real, the db file is in my app's sandbox . what should I pass the parameter to the openDatabase?
I find that in the readme file,there is anther function "SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);"

Runnable example

Would it be possible to include a runnable example please? Thanks for all the hard work on this project.

react-native 0.17 android error

I follow your steps faithfully using the standard project... But I get this:

JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...

FAILURE: Build failed with an exception.

* Where:
Build file '/media/Storage/easyship/android/build.gradle' line: 9

* What went wrong:
A problem occurred evaluating root project 'easyship'.
> Could not find method compile() for arguments [project ':react-native-sqlite-storage'] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@501df9bd.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.629 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

Any idea what that could be and how to solve it?

Any errors in code are suppressed if the call emanated from a DB callback

e.g.

aFunction: function(){
  DBHelper.doSomething("SQL HERE", this.successCB, this.errorCB)
},

successCB: function(response){
  // intentional crash..
  var x = b;
  // this error does not trigger a RSOD.
},

errorCB: function(){
},

Can this 'feature' be disabled? It makes debugging very difficult.

Thanks for a great component ๐Ÿ‘

Has anyone gotten this working in Xcode 7?

Followed the instructions but had to change things slightly here: https://github.com/andpor/react-native-sqlite-storage#step-2-xcode-sqlite-project-dependency-set-up

This step shows a "Frameworks" folder with "libsqlite3.0.dylib" under the main project. The Frameworks folder seems to be absent in the Xcode 7 side panel, but I was able to get it to build by going into the project Build Phases and adding "libsqlite3.0.tbd" as it seems that's the new way.

But when I run the example test code I get this:

image

If I completely remove the react-native-sqlite-storage project from my Xcode project I get the same error, so it looks like the JS is trying to reference something in native that doesn't exist.

Running Xcode Version 7.2 (7C68)

Example code index.ios.promise.js no longer works with React Native 0.21

DB changes are lost when Reload JS

Hello!
Great module!
I have a problem when using it on android though.
When I am on debug mode, every time I hit the "Reload JS" option, all the changes that I may have done to the SQLite database are lost. The packager seems to replace the database file in the www folder with the original copy of it.
This is a pain since when you are debugging you want to make changes to the DB and it is quite normal you may want those changes to be preserved on future runs.
Is there a way to prevent this?
Please note that the "close" method is NOT being called in my case. I normally select "Reload JS" at different points of the execution of my app.

Database location issue

Hi there,

Note: Running v2.1.3

I've just been trying to move my database to a non-icloud backed up location in accordance with app submission new rules and also as per the cordova docs here:

with the location option set to one the following choices (affects iOS only):
0 (default): Documents - visible to iTunes and backed up by iCloud
1: Library - backed up by iCloud, NOT visible to iTunes
2: Library/LocalDatabase - NOT visible to iTunes and NOT backed up by iCloud (same as using "default")

I managed to figure that this is achieved via the dblocation:'nosync' setting when opening a database but on the native side this is seemingly ignored and always has the value docs

I've had to hard-code nosync in to the native side in SQLite.m

ReadableMap converter error in react-native 0.14+

in react-native 0.13+ the bridge name spelling mistake
import com.facebook.react.bridge.ReadableMapKeySeyIterator;
but have modifyed in react-native 0.14+
import com.facebook.react.bridge.ReadableMapKeySetIterator;

ExceptionsManager.js:61 db.transaction is not a function

I write the code by readme file, I got a error 'db.transaction is not a function'.
the code is :

var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
db.transaction((tx) => {
  tx.executeSql('SELECT * FROM testdb', [], (tx, results) => {
      console.log("Query completed");
    });
});

Not able to 'select *' in android

I tried going through various examples in https://github.com/litehelpers/Cordova-sqlite-storage too.

I can connect to the db alright and even execute and 'insert into table...' query. But when i then do a 'select * from ' query, i get this error -

Expected receiver of type org.json.JSONArray, but got java.lang.reflect.Field

The code i am trying out right now is -

var SQLite = require('react-native-sqlite-storage');
function errorCB(err) {
  console.log("SQL Error: " + err);
}

function successCB() {
  console.log("SQL executed fine");
}

function openCB() {
  console.log("Database OPENED");
}

var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
db.executeSql("DROP TABLE IF EXISTS tt");
db.executeSql("CREATE TABLE tt (data)");
db.transaction((tx) => {
  tx.executeSql("INSERT INTO tt values (?)", 'something', successCB, errorCB);
}, (err) => {
  console.log('transaction error: ', err.message);
}, () => {
  db.executeSql('select count(*) from tt', [], (res) => {
    console.log('got count: ', JSON.stringify(res.rows.item(0)));
  }, (err) => {
    console.log('error getting count: ', err.message);
  });
});

Am i doing anything incorrect?

A simpler form of above comes back with the same error -

var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
db.executeSql("DROP TABLE IF EXISTS tt");
db.executeSql("CREATE TABLE tt (data)");
db.transaction((tx) => {
  // tx.executeSql("INSERT INTO tt values (?)", 'something', successCB, errorCB);
  tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function(tx, res) {
    console.log('got stringlength: ' + res.rows.item(0).stringlength);
  });
}, (err) => {
  console.log('transaction error: ', err.message);
});

Undefined symbols for architecture x86_64

I get the following error when trying to run via iOS simulator:

Undefined symbols for architecture x86_64:
  "_sqlite3_bind_double", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in SQLite.o
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_int", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in SQLite.o
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_int64", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in SQLite.o
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_null", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in SQLite.o
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_text", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in SQLite.o
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_close", referenced from:
      -[SQLite close:success:error:] in SQLite.o
      -[SQLite dealloc] in SQLite.o
      -[SQLite close:success:error:] in libSQLite.a(SQLite.o)
      -[SQLite dealloc] in libSQLite.a(SQLite.o)
  "_sqlite3_column_blob", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_bytes", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_count", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_double", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_int64", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_name", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_text", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_type", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_create_function", referenced from:
      -[SQLite open:success:error:] in SQLite.o
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_errcode", referenced from:
      +[SQLite captureSQLiteErrorFromDb:] in SQLite.o
      +[SQLite captureSQLiteErrorFromDb:] in libSQLite.a(SQLite.o)
  "_sqlite3_errmsg", referenced from:
      +[SQLite captureSQLiteErrorFromDb:] in SQLite.o
      +[SQLite captureSQLiteErrorFromDb:] in libSQLite.a(SQLite.o)
  "_sqlite3_exec", referenced from:
      -[SQLite open:success:error:] in SQLite.o
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_finalize", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_last_insert_rowid", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_open", referenced from:
      -[SQLite open:success:error:] in SQLite.o
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_prepare_v2", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_result_error", referenced from:
      _sqlite_regexp in SQLite.o
      _sqlite_regexp in libSQLite.a(SQLite.o)
  "_sqlite3_result_int", referenced from:
      _sqlite_regexp in SQLite.o
      _sqlite_regexp in libSQLite.a(SQLite.o)
  "_sqlite3_step", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_threadsafe", referenced from:
      -[SQLite open:success:error:] in SQLite.o
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_total_changes", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in SQLite.o
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_value_text", referenced from:
      _sqlite_regexp in SQLite.o
      _sqlite_regexp in libSQLite.a(SQLite.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've followed the install instructions to link the project and it fails on build. This is with version 2.1.3 running on react native 0.17 with xcode 7.2

Transaction Rollback

I tested rollback transaction if have broken query. On android. I put query to undefined table and got exception but previous query doesn`t rollback. This is problem implemented as a module or SQLite?

crash when reloading in simulator "pointerValue"

With the latest commit, reloading the simulator with an already-loaded DB causes a crash. The stack trace hints that the error is in dealloc (in SQLite.m) and has to do with pointerValue being unrecognized.

This seems to fix it:

-(void)dealloc
{
  int i;
  NSArray *keys = [openDBs allKeys];
  NSDictionary *dbInfo;
  NSString *key;
  sqlite3 *db;

  /* close db the user forgot */
  for (i=0; i<[keys count]; i++) {
    key = [keys objectAtIndex:i];
    dbInfo = [openDBs objectForKey:key];
    db = [((NSValue *) dbInfo[@"dbPointer"]) pointerValue];
    sqlite3_close (db);
  }

#if !__has_feature(objc_arc)
  [openDBs release];
  [appDBPaths release];
  [super dealloc];
#endif
}

Can't execute multiple selects

Hi there,

I'm probably missing something painfully obvious here but for the life of me I can't figure this out. I am executing a select after I open the database - the version select works and returns the version number I expect. I am keeping my own 'Version' table like in the examples.

Once the database is 'ready' - I then do my normal work and proceed to select from the other tables (Service) in this case, but it never returns any data. In actual fact the methods just die during execution.

I've tried this using Promise and Callback methods and the result is the same - it appears I have some sort of stale transaction floating around which is preventing me from getting the data I need.

My code is below - I'm sure it isn't pretty as I've tried various different ways to execute this. If someone could advise me on best practices to avoid issues like this (if its not an actual issue) I'd be very appreciative.

var database_name = "authio-verity.db";
var database_version = "1.0";
var database_displayname = "Authio Database";
var database_size = 200000;
var database_current_version = 0;
var database_latest_version = 1;
var database_ready_callback = null;
var db;

var AuthioDB = {
    openErrorCallback() {
        database_ready_callback(false);
    },

    openDatabase(readyCallback) {
        var that = this;
        database_ready_callback = readyCallback;
        db = SQLite.openDatabase(database_name, database_version, database_displayname, database_size, function() {
            that.populateDatabase(db);
        }, this.openErrorCallback);
    },

    populateDatabase(db){
        var that = this;

        db.executeSql('SELECT version_id FROM Version ORDER BY version_id DESC LIMIT 1', [], function(results) {
            console.log("Post version query (success)");
            var len = results.rows.length;
            for (let i = 0; i < len; i++) {
                let row = results.rows.item(i);
                database_current_version = row.version_id;
            }

            this.setState(this.state);

            db.transaction(that.upgradeTables, function() {
                database_ready_callback(false);
            }, function() {
                database_ready_callback(true);
            });

        }, function() {
            console.log("Post version query (failed)");
            db.transaction(that.upgradeTables, function() {
                database_ready_callback(false);
            }, function() {
                console.log("Upgrade success");
                database_ready_callback(true);
            });
        });

        //database_ready_callback(true);
    },

    upgradeTables(tx) {
        console.log("Database running version "+database_current_version);
        if(database_current_version < 1) {
            tx.executeSql("CREATE TABLE IF NOT EXISTS Version ( " +
                "version_id INTEGER PRIMARY KEY" +
                ");", []);
            tx.executeSql("CREATE TABLE IF NOT EXISTS Service (" +
                "id INTEGER PRIMARY KEY, " +
                "name TEXT" +
                ");", []);
            tx.executeSql("INSERT INTO Version (version_id) VALUES (?)", [1]);
        }
    },

    addService(callback, obj) {
        var that = this;
        db.transaction(tx).then(() => {
            callback(true);
        });
    },

    addAccountTransaction(tx, obj) {
        tx.executeSql("INSERT INTO Service (name) VALUES (?)", [obj.name]);
    },

    getServices(callback) {
        db.executeSql("SELECT id FROM Service", [], function(results) {
            console.log("Got service results "+JSON.stringify(results));
            var len = results.rows.length;
            console.log("len = "+len);
            for (var i = 0; i < len; i++) {
                let row = results.row.item(i);
                console.log("row "+i+" = "+row.id);
            }

            callback(results);
        });
    },

    executeQuery(query, params) {
        console.log("Executing query "+query);
        return db.executeSql(query, params);
    },

    executeQueryCallback(query, params, callbackSuccess, callbackFailure) {
        db.executeSql(query, params, callbackSuccess, callbackFailure);
    },

    executeTransaction(func, callback) {
        console.log("Executing transaction on AuthioDB");
        db.transaction(func).then((results) => {
            callback(true, results);
        }).catch((error) => {
            callback(false);
        });
    },
    closeDatabase(){
        var that = this;
        if (db) {
            console.log("Closing database ...");
            //db.close();
        } else {
        }
    },

    getDbResource() {
        return db;
    }
}

Undefined symbols for architecture x86_64

I build with react-native run-ios in macbook terminal, with npm install react-native-sqlite-storage installed before.

The build process success until the following command:

Ld build/Build/Products/Debug-iphonesimulator/test.app/test normal x86_64

Undefined symbols for architecture x86_64:
  "_sqlite3_bind_double", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_int", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_int64", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_null", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_bind_text", referenced from:
      -[SQLite bindStatement:withArg:atIndex:] in libSQLite.a(SQLite.o)
  "_sqlite3_close", referenced from:
      -[SQLite close:success:error:] in libSQLite.a(SQLite.o)
      -[SQLite dealloc] in libSQLite.a(SQLite.o)
  "_sqlite3_column_blob", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_bytes", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_count", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_double", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_int64", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_name", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_text", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_column_type", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_create_function", referenced from:
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_errcode", referenced from:
      +[SQLite captureSQLiteErrorFromDb:] in libSQLite.a(SQLite.o)
  "_sqlite3_errmsg", referenced from:
      +[SQLite captureSQLiteErrorFromDb:] in libSQLite.a(SQLite.o)
  "_sqlite3_exec", referenced from:
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_finalize", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_last_insert_rowid", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_open", referenced from:
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_prepare_v2", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_result_error", referenced from:
      _sqlite_regexp in libSQLite.a(SQLite.o)
  "_sqlite3_result_int", referenced from:
      _sqlite_regexp in libSQLite.a(SQLite.o)
  "_sqlite3_step", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_threadsafe", referenced from:
      -[SQLite open:success:error:] in libSQLite.a(SQLite.o)
  "_sqlite3_total_changes", referenced from:
      -[SQLite executeSqlWithDict:andArgs:] in libSQLite.a(SQLite.o)
  "_sqlite3_value_text", referenced from:
      _sqlite_regexp in libSQLite.a(SQLite.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

single quote in string

It will cause the compiling error such as
syntax error (code 1): , while compiling

I tried replacing single quote with two single quote, but it has no effect. The library will still use backslash to escape one single quote and drop the other one.

Is there a way to access the raw array from a query result?

It does not appear possible at this moment. I don't believe that feature is part of the Web SQL Database spec, but it would certainly be convenient to be able to do so.

The actual result array is one step away from being completely exposed in item(). I was thinking such a feature could be added to allow others to avoid any unnecessary hacking. Figured this would be okay considering the original spec is abandoned. :)

no such table

Hello, i'm created react-native project and add your component to my project

I have a file structure
struct

also i found copied db file in this path /data/data/com.zrules/databases

But if i run code from example, i have a error
Error handler not provided: ', { message: 'no such table:

Sorry if similar issue exist.

P/S Android platform

Support for opening an existing sqlite file at runtime

I'm developing an app (android first) that needs to fetch a remote database and read data from it. I'm not sure how or if that can be accomplished using this library, but I saw some promising discussions on the cordova-sqlite-storage repo and figured I'd better ask here before writing my own native module.

storesafe/cordova-sqlite-storage#426 implies that this workflow is possible, if one knows the directory that the plugin searches for databases.

Is that also true for this library? Ideally I could copy the db to wherever, then open and use it.

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.