0

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?

Tommi Un
  • 173
  • 1
  • 9

2 Answers2

0

Try this...

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

See SQLite returned an error code of 14

Community
  • 1
  • 1
jiten
  • 5,128
  • 4
  • 44
  • 73
  • Thx, tried. But doesn't work. Still error 14. And i think "1" is not needed, because id is PRIMARY KEY and therefore uses autoincrement. – Tommi Un May 31 '12 at 13:58
  • alright, after more research and trying, your answer was really useful. My first attempt of trying to use your line didn't work, because i confused names i used in this post and in my program (i changed some names for my post above..). Also SQLite's PRIMARY KEY doesn't implicate autoincrement (thx research), so this assumption was wrong. Thank you! – Tommi Un May 31 '12 at 15:07
0

If you see the error:

I/Database(  362): sqlite returned: error code = 14, msg = cannot open file at source line 25467

you can safely ignore it. That is most probably the instantiation of the WebView component. It will throw that error as it tries to open webview.db, which is completely not necessary.

Instead of "id int NOT NULL PRIMARY KEY" try "id unique" and specify the id on the insert just to make sure your insert is working. Then continue to add more conditions to the id column.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • i couldn't ignore it, because the db.transaction called the error-callback function. But i found the mistake (see below). But thanks for help, i appreciate it! – Tommi Un May 31 '12 at 15:12