Search code examples
androidsqlitecordovainsert-into

Android Phonegap App Database error


My problem is the following: I'm creating a sqlite Database using Javascript in my Phonegap-App and am getting the following information from eclipse (LogCat): sqlite returned: error code 14, msg= cannot open file at source 25467

This is how i initialize the db (works fine):

function initDB() {
  try { 

    if (!window.openDatabase) { 

      alert('doesn't work!'); 

    } else { 

      var shortName = 'name'; 

      var version = '1.0'; 

      var displayName = 'displayname'; 

      var maxSize = 65536; // in bytes 

      var db = window.openDatabase(shortName, version, displayName, maxSize); 

      db.transaction(populateDB, errorCB, successCB);
     }

  } catch(e) { 

    // Error handling code goes here. 

    if (e == INVALID_STATE_ERR) { 

      // Version number mismatch. 

      alert("Invalid database version."); 

    } else { 

      alert("Unknown error "+e+"."); 

    } 

    return; 

  } 

}

so the variable db is initialized with my database. Then i try to populate the db, with this code:

function populateDB(tx) {
  //dropping the table if exists for testing
  tx.executeSql('DROP TABLE IF EXISTS CLIENT');

  //creating a table
  tx.executeSql('CREATE TABLE IF NOT EXISTS CLIENT (id int NOT NULL PRIMARY KEY, name text, adress text, notes text)');  

  //inserting an entry for testing -- SQLITE ERROR 14 HERE!
  tx.executeSql('INSERT INTO CLIENT (name, adress, notes) VALUES ("client1","adress1","note1")');
}

the line where i try to INSERT INTO CLIENT doesn't work, so the transaction calls the callback function errorCB, which says "Error processing SQL: 1" and LogCat says sqlite returned error 14.. Can't seem to fix it, i'm giving my app all permissions.. and creating the table CLIENT doesn't give me any errors, so i think the app has permissions to write into the db file? what is the problem?


Solution

  • Try this...

     tx.executeSql('INSERT INTO CLIENT (id,name, adress, notes) VALUES ("1","client1","adress1","note1")');
    

    See SQLite returned an error code of 14