mercredi 4 novembre 2015

Sqlite INSERT statement NOT WORKING

I'm trying the following code to insert data in an SqlLite Database. What I checked:

  • The db is created (I can see it in the browser);
  • The table codeData is present too (I already created it earlier, with columns code char(10), desc char(50) and price char(10));
  • The CSV file is read ok;
  • I used a Stringbuilder function to emulate the Java one (works ok!);
  • I issued and "alert" to check the syntax of the INSERT command ( 'INSERT INTO codeData (code, desc, price) values("123456","Cardboard 123", "US$ 9,99")' );
  • The code run without error messages.

But no data is entered in the table!

Anyone can help me? I think the error is obvious, but after 24 hours trying, I cannot see anymore... Thanks!

    tableName ="codeData";
    columns = "code, desc, price";
    str1 = " 'INSERT INTO " + tableName + " (" + columns + ") VALUES (";
    str2 = ")'";

    function Codes_Import() {

    createDatabase_codes();
    var db =  openDatabase("db_codes", "1.0", "Code Information" , 1500000); 
    file = ReadFile("PRICELIST.csv"); // open csv
    var lines = file.responseText.split('\n');
    for(var line = 0; line < lines.length; line++)
    {
      var line = (lines[line]); 
      var sb = new StringBuilder(str1);
      var str = line.split(";");
        sb.append('"' + str[0] + '","');
        sb.append(str[1] + '", "');
        sb.append(str[2] + '"');
        sb.append(str2);
        alert (sb);  //<-- just to check if the INSERT statement is correct.
          db.transaction(function(tx) {
             tx.executeSql(sb);
          });    
       }
    }

Aucun commentaire:

Enregistrer un commentaire