SQL >> Database >  >> RDS >> SQLite

Variabele inserts oplossen in de Cordova SQLite-plugin

Het ontbrekende stuk is een id-kolom:

var db = window.sqlitePlugin.openDatabase({name: "MYDB"});
db.transaction(function (tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS Locationlog ' +
        '(id INTEGER PRIMARY KEY AUTOINCREMENT, 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]);
});

Door waarden als tweede argument aan executeSql mee te geven, voorkom je quotingproblemen en SQL-injectie.

  1. SQLite resultaten als INSERT-statements laten tonen

  2. SQLite resultaten in kolommen met headers tonen

  3. Invoegen met UNION: literale waarden selecteren in MySQL

  4. Insert-query met een inner join