vendredi 24 avril 2015

Sqlite issue regarding table creation using Qml [duplicate]

This question already has an answer here:

I'm trying to create a table using Sqlite in QML, here is my code:

 function getDatabase() {
             return LocalStorage.openDatabaseSync("HomeScreen1", "1.0", "StorageDatabase", 100000);
        }


        function initialize() {
            var db = getDatabase();
            db.transaction(
                function(tx) {                                                                        
                    tx.executeSql("CREATE TABLE IF NOT EXISTS table (redp TEXT, redvalue TEXT)");
              });
        }



        function setRedValue() {
           var db = getDatabase()
           db.transaction(function(tx) {            
                           var rs = tx.executeSql("INSERT OR REPLACE INTO table VALUES (?,?);", ['myName2',mytextInput2.text]);

                }
          );
        }



        function getRedValue() {
           var db = enterYourName.getDatabase();
           var res="";
           db.transaction(function(tx) {
               var rs = tx.executeSql('SELECT redvalue FROM table WHERE redp=?;', ['myName2']);

             if (rs.rows.length > 0) {
                  res = rs.rows.item(0).value;
             } else {
                 res = "Unknown";
             }
          })

          return res;
        }


        Component.onCompleted: initialize()

Although everything in the code seems logical (at least to me :) but still i have an error appearing when i run my application: Error: near "table": syntax error Unable to execute statement i have checked the code several times to find the mistake that i'm making & after playing with the code many times the problem still persists, How this issue can be resolved?

Aucun commentaire:

Enregistrer un commentaire