2

I'm building an HTML based app for querying imported CSV file using AlaSQL. I started with this demo and tried to implement the same behavior by setting the onChange event through JQuery rather than in the tag. I basically follow the same pattern, and naively pass the event forward to the loadFile method. Alternatively, I tried just handling the alasql request right in the callback.

html:

<input id="with-jquery" name="with-jquery" type="file" />

javascript:

$('#with-jquery').on('change', function(event)
  {
    console.log('in jquery callback');
    filename = $('#with-jquery').val();
    console.log("filename: " + filename);
    alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(res){
      console.log('in alasql callback');
        data = res;
        console.log(res);
        document.getElementById("jquery-result").textContent = JSON.stringify(res);
      });
    //loadFile(event);
  });

http://plnkr.co/edit/FOWwVsW7zAUGwv3BDBdN?p=preview

When I try to load the file using the JQuery handler, I get

in jquery callback
test.js:7 filename: C:\fakepath\sample.csv
alasql.min.js:13 Uncaught Error: Wrong usage of FILE() function

Here are some questions:

  1. I can't find documentation for what alasql expects in the [event] slot.
  2. How does the FROM FILE method relate to the more specific FROM CSV and FROM XLSX methods.
  3. The wiki shows using the FROM CSV method by supplying a file name. I can't imagine how that would work without supplying the full path to a local file. But you can't get that from the browser.
  4. The wiki also recommends using the "promise" format. How would I implement that here?
abalter
  • 9,663
  • 17
  • 90
  • 145

0 Answers0