6

Problem with query insertion in sqlite? (Values ​​are not inserted)

 2 years ago
source link: https://www.codesd.com/item/problem-with-query-insertion-in-sqlite-values-are-not-inserted.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Problem with query insertion in sqlite? (Values ​​are not inserted)

advertisements

I am new to Sqlite, I am unable to insert values in DB, by the following code both database and tables are created but the values are no inserted, What is wrong with my code? Any suggestions!!! I am able to see the alert values are stored but not able to see in table data.

     $("#btnDefaultSave").click(function(){
              var Latlongs = "Test1";
              var Location = "Test2";
              var Category = "Test3";
              var Address = "Test4";
              var db = window.sqlitePlugin.openDatabase({name: "TestDB"});
              db.transaction(function (tx) {
   tx.executeSql('CREATE TABLE IF NOT EXISTS Locationlog (id INTEGER PRIMARY KEY, Coordinates TEXT, Location TEXT, Category TEXT, Address TEXT)');
          });
     db.transaction(function (tx){
tx.executeSql('INSERT INTO Locationlog (Coordinates, Location, Category, Address) VALUES ('+Latlongs+', '+Location+', '+Category+', '+Address+')');
                                                                        alert("values are stored");
                                                                        });

                                                        });


I have changed the format of insert query as follows,

     db.transaction(function (tx){

  tx.executeSql('INSERT INTO Locationlog (Coordinates, Location, Category, Address) VALUES (?,?,?,?)',[Latlongs,Location,Category,Address]);
   alert("values are stored");
       });


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK