javascript sqlite problem


    Nov 14 2012 | 1:41 am
    I've got a problem with using js and sqlite at the moment. when I run exec() functions in a loop it completely crashes max. I have some js where im iterating through an array and writing values into a db, i know my sql statement isnt wrong as it works when its not in a loop, but when i put it inside the loops braces it crashes max. I can see from the database that it writes the first value before it crashes, im just not sure what the problem could be. Has anyone else experienced this?

    • Nov 14 2012 | 1:50 am
      for example this works and will put in the last array but if you put the insert_entry call inside the brace above it max crashes //get the information of an entry formatted for the inspector patch function get_entry(fields, table, datafield, data){ var call = []; //do the sqlite query if (datafield == null) { exec("SELECT "+fields+" FROM "+table, AsctNLdbR); } else{ exec("SELECT "+fields+" FROM "+table+" WHERE "+selector+" = '"+data+"'"); } //make the numrecord and numfields so we can use them to iterate through var numrecords = AsctNLdbR.numrecords(); var numfields = AsctNLdbR.numfields(); //iterate through our results
      for(var a = 0; a call = []; for(var j=0; j //get the value for this index var value = AsctNLdbR.value(j, a); //push the values into an array call.push(value); } post("'outputinloop', ['outlet','call','type','f_ref'], [2, "+call[0]+' '+call[1]+' '+call[2]+',lp,'+'get_entry n'); } insert_entry('output',['outlet','call','type','f_ref'],[2, call[0]+' '+call[1]+' '+call[2],'lp','get_entry']); post('GET_ENTRY FINAL output is:'+call+'n'); }
    • Nov 14 2012 | 2:03 am
      I just worked out a fix for this but i'd be interested to know if anyone could shed some light on why this works and what kind of performance/memory implications it has.
      you need to make a special version of exec for fast writing stuff where you dont care about the results it generates. For some reason if you make a new sqlite results item (with the same name) before doing the exec it no longer crashes
      eg: function exec2(arg) { // post('args are'+arg+'n'); // execute the SQL statement in arg, returning results in the 'result' object var Atemp = new SQLResult; AsctNLdb.exec(arg, Atemp); }