react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

Batch insert of Android version 5.0 failing

Open varunprashar5 opened this issue 7 years ago • 6 comments

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. ...

varunprashar5 avatar Feb 28 '18 06:02 varunprashar5

Please provide a full sample project where error can be replicated.

andpor avatar Mar 08 '18 10:03 andpor

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 }; }); }

kapsona avatar Apr 18 '18 11:04 kapsona

@varunprashar5 please provide code sample how you load the data. also provide details of your setup, OS, IDE, exact Adnroid version, grunt etc..

andpor avatar May 18 '18 18:05 andpor

Also note that Android 5 is ancient...i would suggest moving to a more modern Android version

andpor avatar May 19 '18 10:05 andpor

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.

sagargheewala avatar Nov 16 '18 10:11 sagargheewala

I can't see types for sqlBatch => https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-native-sqlite-storage/index.d.ts

jdnichollsc avatar May 22 '20 14:05 jdnichollsc