dogwasstar
dogwasstar

Reputation: 881

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

Upvotes: 7

Views: 9019

Answers (1)

Related Questions