Database db = Databases.openDatabase("gwittir-windowcontext", "1.0",
"This is the gwittir test db", 512000);
db.run(new TransactionTask() {
public void run(Transaction tx) {
tx.execute("SELECT COUNT(*) FROM Gwittir", null,
new ResultsCallback() {
public void onSuccess(Transaction tx, ResultSet rs) {
Window.alert("Worked!");
tx.execute("SELECT id, note FROM Gwittir", null, new ResultsCallback(){
public void onSuccess(Transaction tx, ResultSet rs) {
for(JavaScriptObjectDecorator d: rs.getRows()){
Window.alert( "Got: "+d.getIntegerProperty("id")+" :: "+d.getStringProperty("note"));
}
}
public void onFailure(Transaction tx, SQLError error) {
Window.alert("Select failed");
}
});
}
public void onFailure(Transaction tx, SQLError error) {
tx.execute("CREATE TABLE Gwittir (id REAL UNIQUE, note TEXT)",
null,
new ResultsCallback() {
public void onSuccess(Transaction tx,
ResultSet rs) {
Window.alert("Database created.");
Object[] parameters = new Object[2];
parameters[0] = 1;
parameters[1] = "This is a test of the emergency broadcast system";
tx.execute("INSERT INTO Gwittir (id, note) VALUES (?, ?)",
parameters,
new ResultsCallback() {
public void onSuccess(
Transaction tx,
ResultSet rs) {
Window.alert(
"Insert Succeeded.");