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

Error on query with RETURNING keyword on Android

Open kshehata opened this issue 1 year ago • 1 comments

My app works perfectly on iOS, and I'm trying to port it to Android. Any time I run a query with the Returning keyword I get the error below:

unknown error (code 0 SQLITE_OK): Queries can be performed using SQLiteDatabase query or rawQuery methods only.

I tried adding a react-native.config.js file as per the instructions, but I get the same error. I really don't want to have different code for Android and iOS. How do I get these queries to work? Is there a "raw query" mode?

Expected Behavior

db.executeSql("INSERT INTO MyTable VALUES (...) RETURNING rowid");

Should add a new row to the table and return the rowid, exactly as it does on iOS.

Current Behavior

Get error above, no rowid.

Possible Solution

Make it work the same as iOS?

Or if that's not possible, make a executeRawSql() interface?

Steps to Reproduce (for bugs)

As above, create a table, and try to insert a row and return the rowid. On Android it returns an error. On iOS it works.

Context

Seems like iOS and Android interfaces differ.

Your Environment

  • React Native SQLite Storage Version used: 6.0.1
  • React Native version used: 0.72.6
  • Operating System and version (simulator or device): Android Studio Pixel 3A emulator, Android 34 (upside down cake)
  • IDE used: Android Studio / command line React Native Tools
  • Link to your project:

Debug logs

kshehata avatar May 19 '24 10:05 kshehata

As a workaround, I've gotten rid of the RETURNING statements, so now it does:

await db.executeSql("INSERT INTO MyTable VALUES (...)", ...);
const rowid = await db.executeSql("SELECT last_insert_rowid() as rowid");

This seems to do the job for now, but still frustrating that they're different.

kshehata avatar May 19 '24 11:05 kshehata