andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.75k stars 521 forks source link

Error on query with RETURNING keyword on Android #575

Open kshehata opened 4 months ago

kshehata commented 4 months ago

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

Debug logs

kshehata commented 4 months ago

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.