SQLite works with iOS but not with android.

Please provide the following:

  1. SDK Version: 36.0.0
  2. Platforms(Android/iOS/web/all): android and iOS

Hi, I am new to expo, so please bear with me.

Snackbar: https://snack.expo.io/@manubi/d02a6f it’s file helpers/db.tsx

The code from the snackbar in the file db.tsx works on iOS but not on android. Do you have any ideas why I can’t insert a student?

Thanks and best
manuel

1 Like

Hi! Could you share the error messages you’re getting on Android? It also looks like you’re not using the ? placeholders in your queries, so you could try fixing that.

Thanks for sharing some code, but a minimal repro would be really helpful!

Hi,
thanks for the help!
I uploaded the whole git repository to this snack. mplus - Snack
the sqlite queries are in /helpers/db.tsx
Thanks a lot!!!
Will post the error messages a little later.

Hi,
me again. Sorry, I couldn’t update the first post.

I tested it again with iOS simulator and everything works fine.

On android emulator I get the following errors:
If I try to add a class, the class is added in the db but I get the following error.

the bind value at index 1 is null
- node_modules/expo-sqlite/build/SQLite.js:36:15 in _deserializeResultSet
* [native code]:null in map

If I try to insert a student the following error appears:

no such column: studentId (code 1 SQLITE_ERROR): , while compiling: INSERT INTO student (studentId, firstName, lastName, classId) VALUES (studentId, firstName, lastName, classId)

If I try to delete a class I get the following error:

Cannot bind argument at index 1 because the index is out of range.  The statement has 0 parameters.
- node_modules/expo-sqlite/build/SQLite.js:36:15 in _deserializeResultSet
* [native code]:null in map

Any ideas?

Thanks for your help!

I have a same problem.

1 Like

Were you able to fix it?

I fixed it. You really need to work with ? in order to get the arguments into the query and that it works on iOS and android. eg.

    db.transaction(tx => {
      tx.executeSql(
        "UPDATE student SET firstName=?, lastName=? WHERE studentId=?;",
        [firstName, lastName, studentId],
        (_, result) => {
          resolve(result);
        },
        (_, err): any => {
          reject(err);
        }
      );

or

      tx.executeSql(
        "INSERT INTO class (classId, className, days) VALUES (?,?,?)",
        [classId, className, days],
        (_, result) => {
          resolve(result);
        },
        (_, err): any => {
          reject(err);
        }
      );

don’t use template-strings as they only work on iOS.
hope it helps!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.