Created
January 15, 2014 18:32
-
-
Save leocosta/8441680 to your computer and use it in GitHub Desktop.
Deferred WebSQL execute query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
// size the database to 3mb. | |
var dbSize = 3 * 1024 * 1024, | |
myDb = window.openDatabase('myDb', '1.0', 'My Database', dbSize); | |
function runQuery() { | |
return $.Deferred(function (d) { | |
myDb.transaction(function (tx) { | |
tx.executeSql("select ? as Name", ['Juca'], | |
successWrapper(d), failureWrapper(d)); | |
}); | |
}); | |
}; | |
function successWrapper(d) { | |
return (function (tx, data) { | |
d.resolve(data) | |
}) | |
}; | |
function failureWrapper(d) { | |
return (function (tx, error) { | |
d.reject(error) | |
}) | |
}; | |
$.when(runQuery()).done(function (dta) { | |
alert('Hello ' + dta.rows.item(0).Name + '!'); | |
}).fail(function (err) { | |
alert('An error has occured.'); | |
console.log(err); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment