0

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.

4
  • How do you want insert the data? Commented Jul 7, 2017 at 2:04
  • I want to insert the array. the array have 3 elements and my table have 3 columns. Commented Jul 8, 2017 at 3:03
  • You have an array with 3 element and want to insert each element to a column right? Commented Jul 8, 2017 at 4:00
  • yes, you are right. Commented Jul 8, 2017 at 9:41

1 Answer 1

1

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+')', {}); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.