I had created two functions for insert in sqlite,
In Android 5 or greater both working fine.
And in Android 4 or down, Single Insert works fine,
But, on Bulk Insert it through an error
could not prepare statement (1 near ",": syntax error)
Single Insert
function insert(TABLENAME, COLNAME, VALNAME, callBack) { var query = "INSERT INTO " + TABLENAME + "(" + COLNAME + ") VALUES (" + VALNAME + ") "; $ionicPlatform.ready(function () { $cordovaSQLite.execute(db, query).then(function (res) { console.log("INSERT " + TABLENAME + " -> " + res); if (callBack) callBack(); }, function (err) { console.error(err); }); }); }
Bulk Insert
function bulkInsert(TABLENAME, COLNAME, VALNAMES, DATA, callBack) { var query = "INSERT INTO " + TABLENAME + "(" + COLNAME + ") VALUES "; var data = DATA; var rowArgs = []; query += VALNAMES.join(", "); $cordovaSQLite.execute(db, query, data).then(function (res) { console.log("inserted"); if (callBack) callBack(); }, function (err) { console.log(err); }); }
Can anyone help me out, how do i fix this issue??
PS: Bulk insert parameter will be like this,
bulkInsert('users', 'id,name', ['(?,?)','(?,?)'], [[1,'abc'],[2,'xyz']], function(){});
I am asking about Cordova-SQLite not Android SQLite