View Full Version : Insert CSV file into client-side DB with javascript

07-20-2011, 02:26 AM
I am developing a mobile app. I have a script that will read the contents of a csv into an array. It works great, however I am not sure how to take that array and insert it into a db. The following is the script that reads the csv --

function IO(U, V) {
var X = !window.XMLHttpRequest ? new
ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest;
X.open(V ? "PUT" : "GET", U, false);
X.setRequestHeader("Content-Type", "text/html");
X.send(V ? V : "");
return X.responseText;

var mycells = IO('data.csv').split(/\n/g).map(function(a){return
a.split(/\t/g)} )

I want to insert the array 'mycells' into the db but do not know what
the correct syntax would be.

t.executeSql('INSERT INTO mytable (name, phone, street, city, state)
VALUES (????????????...

Thanks for any helps that is sent my way!

rnd me
07-20-2011, 03:36 AM
what kind of client side db are you using?
sqlLite, indexed, couch, other?

07-20-2011, 01:21 PM

rnd me
07-20-2011, 06:11 PM

haven't heard that in a while...
i can't help you with websql syntax, but you may be able to find tutorials or something. if memory serves correct, the sql part is pretty regular, it's just the initial config that's hairy...

07-20-2011, 06:41 PM
How about sqlite?

07-30-2011, 05:43 PM
I am using sqlite. I am not sure the correct syntax to use to insert the array into the db. Any ideas?