Giter VIP home page Giter VIP logo

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

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.

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

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'

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?

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

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.

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

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);
});

Runnable example

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

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

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.

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?

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;

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. :)

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?

Cannot read property 'open' of undefined

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

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.

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.

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)

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.

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

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)

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.

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 ๐Ÿ‘

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
}

Delete and update

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

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);"

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

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

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)

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");
    });
});

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

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;
    }
}

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.

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.