react-native-sqlite-storage
react-native-sqlite-storage copied to clipboard
Batch insert of Android version 5.0 failing
In sqlite I am batch inserting my rows but it is failing and throwing error.
The error I am getting is : SQLitePlugin.executeSqlBatch: failed android.database.sqlite.SQLiteException: too many terms in compound SELECT (code 1): , while compiling: insert into questions (Qtype,Qname,Raw_json) values (further content) of insert. ...
Please provide a full sample project where error can be replicated.
Same issue here when tried to import json data to local database received from server. It works fine if the no. of records is just few..
Code Snippet... ....... const uri = api_url; fetch(uri) .then(async re => re.json()) .then(async re => { const { res: res1, err: err1 } = this._insertItems('<TABLE NAME>', re) // DO SOMETHING console.log('DONE'); }) .catch((error) => { this.errorCB('Could not import data'); });
async _insertItems(tableName, items) {
if (!this.db) {
await this.open();
}
const sqlStrArr = items.map((item) => {
const columns = Object.keys(item);
let sqlStr = columns.reduce((sqlSegment, columnName, index, arr) => (
${sqlSegment} ${columnName} ${index + 1 === arr.length ? ')' : ','}
), INSERT INTO ${tableName} ();
sqlStr += columns.reduce((sqlSegment, columnName, index, arr) => (
${sqlSegment} '${item[columnName]}' ${index + 1 === arr.length ? ');' : ','}
), ' VALUES (');
return sqlStr;
});
return await this.db.sqlBatch(sqlStrArr)
.then(() => {
this.successInfo('insert Items Batch');
return { res: ['databases execute sqlBatch success'] };
})
.catch((err) => {
this.errorInfo('insertItemsBatch', err);
return { err };
});
}
@varunprashar5 please provide code sample how you load the data. also provide details of your setup, OS, IDE, exact Adnroid version, grunt etc..
Also note that Android 5 is ancient...i would suggest moving to a more modern Android version
Hi @andpor
I am using react-native-sqlite-storage version 3.3.8
Code Snippet...
This is what i tried to insert data,
const test = [[" INSERT INTO USRH(id, firstName, lastName) values",[9002,"MESSENGER","TEST1"]],[" INSERT INTO USRH(id, firstName, lastName) values",[9003,"DRIVER","TEST1"]]]
Now calling, db.sqlBatch()
openDatabase.transaction((db) => {
console.log(db)
db.sqlBatch(test, function () {
console.log('Populated database OK');
}, function (error) {
console.log('SQL batch ERROR: ' + error.message);
})
})
Not returning any response in success and in error. Also check the console log, it was not showing any method sqlBatch.
I can't see types for sqlBatch => https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-native-sqlite-storage/index.d.ts