react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

Open database failing in production

Open MorganTrudeau opened this issue 5 years ago • 5 comments

OPEN database fails in production. Database is working as expected in debug mode. Because I am also using typeorm in conjunction with this project I am not sure which library is causing the error.

Expected Behavior

Database should open and initialize tables successfully in production and debug modes.

Current Behavior

Database is opening in debug mode and failing in production

Steps to Reproduce (for bugs)

Using typeorm I have created entities in the following form:

import { EntitySchema } from 'typeorm';
import { StorageModel } from '../models/StorageModel';

export default new EntitySchema({
  name: 'Storage',
  target: StorageModel,
  columns: {
    key: { type: 'text', primary: true },
    value: { type: 'text' },
  },
});

Then I am opening database with the following config:

createConnection({
      name: 'db.sqlite',
      type: 'react-native',
      database: 'react-native',
      location: 'default',
      // logging: ['error', 'query', 'schema'],
      synchronize: true,
      entities: [
        Translation,
        User,
        Post,
        Download,
        Asset,
        Option,
        QueuedRequest,
        Storage,
        HelpItem,
      ],
    });

In debug the database opens correctly and I have used it to create many features. It was going very well until I tried building the release apk. I get the following error in adb logcat...

08-08 19:04:52.174 19954 20022 I ReactNativeJS: OPEN database: react-native
08-08 19:04:52.340 19954 20032 E SQLiteLog: (1) near ")": syntax error
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: SQLitePlugin.executeSql[Batch]() failed
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE "temporary_t" ()
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:895)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:506)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:726)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1428)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1367)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin.executeSqlStatementQuery(SQLitePlugin.java:805)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin.executeSqlBatch(SQLitePlugin.java:712)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin.access$100(SQLitePlugin.java:49)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin$DBRunner.run(SQLitePlugin.java:927)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at java.lang.Thread.run(Thread.java:764)

Context

Using react-native-sqlite-storage with typeorm to build offline support for a react-native app.

Your Environment

  • React Native SQLite Storage Version used: 3.3.10 and also on 3.2.0
  • React Native version used: 0.60.0
  • Operating System and version (simulator or device): LG G6 Android 8.0.0
  • IDE used: Android Studio
  • Link to your project: Private client project SRY

MorganTrudeau avatar Aug 09 '19 02:08 MorganTrudeau

There is a syntax error is the SQL that you're sending. createConnection is not this library's API call.

andpor avatar Aug 09 '19 12:08 andpor

Any update on this one? Experiencing the same issue.

jadenlemmon avatar Aug 30 '19 05:08 jadenlemmon

what is the issue? createConnection is not this library's API call.

andpor avatar Aug 30 '19 17:08 andpor

I have the same issue, while debug is OK and release is failed with the same error.

the-sparrow avatar Oct 31 '19 07:10 the-sparrow

The problems seem to related to Typeform and code minification. This solved my problem: https://github.com/typeorm/typeorm/issues/4561#issuecomment-546010351

Frans-L avatar Jan 24 '20 01:01 Frans-L