Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native SQLite bulk insert

Hi is there any way to do a bulk insert in the SQLite in React-native?

I am using the following library

https://github.com/andpor/react-native-sqlite-storage

I have tried the following code but it just inserts all the values to the first column in the table.

export function saveWelfareInfo(authenticationToken, welfareArr) {
  var sqlQuery = 'authenticationToken, enabled, title, tabname, tabimage, tabcontents, last_update_date, id, ethnicity_id, course, campus, app_profile_id'

  let db = OpenSqliteDatabase()
  db.transaction((tx) => {
    tx.executeSql('insert into welfare_list(' + sqlQuery + ') values(?,?,?,?,?,?,?,?,?,?,?,?)', welfareArr)
  tx.executeSql('SELECT * FROM welfare_list', [], (tx, results) => {
        console.log("Query completed");
        var len = results.rows.length;
        for (let i = 0; i < len; i++) {
          let row = results.rows.item(i);
          console.log('welfare_list Record: ', row);
        }
      });
  })

Any help would be greatly appreciated. thanks in advance

like image 791
dogwasstar Avatar asked Oct 28 '22 22:10

dogwasstar


1 Answers

Don't worry solved the issue. used the following page as example.

https://github.com/reconka/Cordova-sqlite-storage-bulkinsert/blob/9e72c4ca44dd56df38233dbda42fcc6de80363d4/android/assets/www/js/index.js

like image 86
dogwasstar Avatar answered Jan 02 '23 21:01

dogwasstar