jeudi 5 mai 2016

Connecting sqlite in framework7 using javascript?

I can not read the database that is at the root folder of my application I'm creating with framework7. Would you have to define the url example: (http: localhost \ mydb), which is the database? I noticed that the javascript creates a database on the way down for Chrome.

    //F:\Users\i5\AppData\Local\Google\Chrome\User Data\Default\databases\http_localhost_0
var db = openDatabase('mydb', '1.0', '', 2 * 1024 * 1024);
console.log(db);

db.transaction(function(transaction){
    transaction.executeSql("SELECT COUNT(*) FROM table", null, null, null);
});

// os parametros são, respectivamente: a consulta, as variáveis a serem "bindadas", callback de sucesso e callback de erro, ou seja:

db.transaction(function(transaction){
    transaction.executeSql(
        // a consulta
        "SELECT COUNT(*) FROM table",
        // variáveis para bind, como é um SELECT, passamos um array vazio
        [[]],
        // callback de sucesso, uma função anônima que recebe um objeto SQLTransaction e um SQLResultSet
        function(transaction, result){
            console.log('all right!');
            console.log(result);
        },
        // callback de erro, função anônima que recebe um objeto SQLTransaction e um SQLError
        function(transaction, error){
            console.log('deu pau!');
            console.log(error);
        }
    );
}); 

Aucun commentaire:

Enregistrer un commentaire