Batch insert into client database (WEB SQL) in HTML 5 / Javascript

Is it possible to use batch operation in a client-side database in HTML 5?

+3
source share
2 answers

I assume you are referring to WebSQL ?

WebSQL is currently basically a SQLite shell. SQLite does not support inserting multiple rows into a single statement INSERT. But you can make one request with placeholders and execute it several times in the same transaction to improve performance and ensure integrity.

If this does not answer your question, you should clarify what kind of problem you have.

+5
source

, DCoder () !

-, , , , WebSQL. IndexedDB, W3C.

- WebSQL, , , , API , .

BakedGoods, . , , , :

bakedGoodsd.set({
    data: [{key: "key1", value: "value1"}, {key: "key2", value: "value2"}]
    storageTypes: ["webSQL"],
    complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj){}
});

..., , , , API:

function insertData(transaction)
{
    var dataInsertStatement = "INSERT INTO Main(key, value) VALUES (?, ?)";
    var dataArray = [{key: "key1", value: "value1"}, {key: "key2", value: "value2"}];

    int i = 0;

    function advance()
    {
        if(++i < dataArray.length)
            insertDataItem();
    }

    function insertDataItem()
    {
        transaction.executeSql(
            dataInsertStatement, 
            [dataArray[i].key, dataArray[i].value], 
            advance
        );
    }

    insertDataItem();
}


function conductDataInsertTransac(database)
{
    database.transaction(insertData);
}

window.openDatabase("Baked_Goods", "", "Baked Goods", 1024*1024, conductDataInsertTransac);

BakedGoods - . , WebSQL .

, , .

, , BakedGoods :).

0

All Articles