4

I understand that the result set from web sql isn't quite an array, more of an object? I'm cycling through a result set and to speed things up I'd like to remove a row once it's been found. I've tried "delete" and "splice", the former does nothing and the latter throws an error. Here's a piece of what I'm trying to do, notice the delete on line 18:

function selectFromReverse(reverseRay,suggRay){
    var reverseString = reverseRay.toString();
    db.transaction(function (tx) {  
        tx.executeSql('SELECT votecount, comboid FROM counterCombos WHERE comboid IN ('+reverseString+') AND votecount>0', [], function(tx, results){
            processSelectFromReverse(results,suggRay);
        }); 
    }, function(){onError});
}

function processSelectFromReverse(results,suggRay){
    var i = suggRay.length;
    while(i--){
        var j = results.rows.length;
        while(j--){
            console.log('searching');
            var found = 0;
            if(suggRay[i].reverse == results.rows.item(j).comboid){
                delete results.rows.item(j);
                console.log('found');
                found++;
                break;
            }
        }       
        if(found == 0){
            console.log('lost');
        }
    }
}
Kaijin
  • 53
  • 1
  • 1
  • 10

3 Answers3

8

Actually you use DELETE sql command to delete the record from the database. For example:

tx.executeSql('DELETE FROM counterCombos WHERE comboid = ?', [comboid], success, error);

processSelectFromReverse could modified to include tx as input like

processSelectFromReverse(results,suggRay,tx) 
Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
  • I don't want to delete the record from the database. I want to delete it from the result set so that the result set is shorter while looping through it. – Kaijin Oct 02 '12 at 15:02
  • I see. Haven't thought results to be minupulated, better shouldn't . It is a method. So read only. Perhaps you might use Array.prototype.map iteration method for performance rather than looping. – Kyaw Tun Oct 02 '12 at 17:07
0

Web SQL has been dropped from the HTML5 workup for almost 2 years now and isn't supported. Web Storage and Indexed DB have taken its place.

Your syntax for deleting objects: delete object; is correct. It's not used often in JavaScript but I have used it and that is the correct usage.

Using web-storage (more commonly called local storage) you would instansiate a localStorage object which comes with the method removeItem(item key), already built in.

You can see more at the above link on webstorage or go here for a tutorial.

Ryan
  • 5,644
  • 3
  • 38
  • 66
  • I understand that it isn't currently being supported. Indexed DB isn't yet supported on iOS or Android which I am developing for. – Kaijin Oct 01 '12 at 16:24
  • if your developing for mobile why are you not using local storage? its supported by everything. – Ryan Oct 01 '12 at 18:53
  • I've found querying the data I'm storing with web sql performs better than localStorage. I'm storing about 50,000 small rows of data (about 1.5mb if it were JSON data). – Kaijin Oct 01 '12 at 20:44
  • That's great that you get better performance but in a year when they finalize the html5 spec and google/apple drop support for web sql cause its not in the spec what are you going to do? – Ryan Oct 01 '12 at 20:55
  • I'm quite sure by then IndexedDB or some other query-able solution will have been adopted by both. At that time, I shall have to change my application. Right now however, this is what works and works better than localStorage. – Kaijin Oct 02 '12 at 15:05
  • W3c dropped from standard for reasonable motivations (but not because it was'nt useful btw, just because effectively webSql===sqlLite, so no real need for a standard api. the Api remains however.), but browsers and handeld devices are'nt the standard, are real use case who already and for long again will use a perfectly working sqlLite db engine, AND the alternatives that nowadays are localStorage and indexedDB, thought they aren't a _direct_ alternative, being structurally completely different from a local relational db. – netalex Jul 26 '13 at 13:17
  • -continue- So continuing to use and study this tech is necessary, even if you prefer to call it another name (sqlLite? implementer's commercial API name -say, phonegap sql storage API-?) Just my 2 cents. – netalex Jul 26 '13 at 13:18
0

If your concern is IOS or Android, making an application that is wrapped natively would allow you to create a javascript interface. From this interface you can access (for android) sqlite and create a nice, query0able solution. The downside is this would require people downloading your application rather then accessing a site.

http://caniuse.com/indexeddb

indexeddb support is growing rather slowly. With a proper coding style you could probably use local storage (as mentioned in the above comments) with pretty respectable speeds.

arielf
  • 239
  • 2
  • 5