PDA

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



cjackson111
Jul 20th, 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
Jul 20th, 2011, 03:36 AM
what kind of client side db are you using?
sqlLite, indexed, couch, other?

cjackson111
Jul 20th, 2011, 01:21 PM
Web SQL

rnd me
Jul 20th, 2011, 06:11 PM
Web SQL

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...

cjackson111
Jul 20th, 2011, 06:41 PM
How about sqlite?

cjackson111
Jul 30th, 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?