Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert CSV file into client-side DB with javascript

    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!

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,302
    Thanks
    10
    Thanked 586 Times in 567 Posts
    what kind of client side db are you using?
    sqlLite, indexed, couch, other?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Web SQL
    Last edited by cjackson111; 07-20-2011 at 01:12 PM.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,302
    Thanks
    10
    Thanked 586 Times in 567 Posts
    Quote Originally Posted by cjackson111 View Post
    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...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How about sqlite?

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am using sqlite. I am not sure the correct syntax to use to insert the array into the db. Any ideas?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •