storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API
Other
2.15k stars 716 forks source link

Android: One table works, but the other table doesn't #884

Open willnix86 opened 5 years ago

willnix86 commented 5 years ago

I'm creating and using two tables that both work perfectly on iOS, but only one of them works on Android.

This one works perfectly:

const createEntriesTable = () => {
  const query = `
    CREATE TABLE IF NOT EXISTS entries ( 
    id TEXT PRIMARY KEY,  
    entry TEXT NOT NULL,  
    category TEXT NOT NULL,  
    source TEXT NOT NULL)
  `;
  db.executeSql(
    query,
    err => {
      console.log('Create entries Error: ' + err.message);
    },
    () => {
      console.log('Entries table OK');
      fetchEntries();
    }
  );
};

This one doesn't work

const createSettingsTable = () => {
  const user = window.device.uuid;
  const query = `
    CREATE TABLE IF NOT EXISTS settings ( 
    user TEXT PRIMARY KEY,  
    theme TEXT,  
    language TEXT,  
    voice TEXT)
  `;

  db.transaction(tx => {
    tx.executeSql(
      query,
      err => {
        console.log('Create settings Error: ' + err.message);
      },
      () => {
        console.log('Settings table OK');
      }
    );
    tx.executeSql(
      `SELECT * FROM settings WHERE user = '${user}'`,
      [],
      res => {
        console.log('User found OK');
        if (res.rows.length < 1) {
          initUser(user);
        } else {
          fetchSettings();
        }
      },
      err => console.log(err.message)
    );
  });
};

I see the console logs that tell me the tables were created "ok", but when I try to update something in the settings table, I get the 'no such table settings' error.

Any thoughts?

brodycj commented 5 years ago

I see multiple issues with your code:

brodycj commented 5 years ago

P.S. Commercial support is also available from: http://xpbrew.consulting