0
votes

I am trying to insert an array into my sqlite database. But all the data is getting inserted into the first column. Please help. I already checked these :

https://github.com/litehelpers/Cordova-sqlite-storage/issues/392

sqlite3 insert into dynamic table

But not able to solve my problem.

my code is

 let insertarr:Array;

for(var i=0;i<this.fullData.length;i++)

{
insertarr = [];
for(var j=0;j<this.fullData[i].length;j++)
{

        insertarr.push(this.fullData[i][j].val);

      }
     alert(insertarr);
      db.executeSql('insert into mytable (col1, col2, col3) values(?,?,?)', [insertarr]);  
  }

When I run the above code col1 is getting populated with the full array. col2 and col3 are populated with null.

1
How do you want insert the data? - Duannx
I want to insert the array. the array have 3 elements and my table have 3 columns. - Arijit
You have an array with 3 element and want to insert each element to a column right? - Duannx
yes, you are right. - Arijit

1 Answers

1
votes

Solved this issue. Posting if it helps someone in future.

I changed the arguments of db.executeSql like below:

 db.executeSql('insert into mytable (col1, col2, col3) values('+insertarr+')', {});