My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.totsp.gwittir.example.client;

import com.google.gwt.user.client.Window;

import com.totsp.gwittir.client.jsni.JavaScriptObjectDecorator;
import com.totsp.gwittir.client.util.html5db.Database;
import com.totsp.gwittir.client.util.html5db.Databases;
import com.totsp.gwittir.client.util.html5db.ResultSet;
import com.totsp.gwittir.client.util.html5db.ResultsCallback;
import com.totsp.gwittir.client.util.html5db.SQLError;
import com.totsp.gwittir.client.util.html5db.Transaction;
import com.totsp.gwittir.client.util.html5db.TransactionTask;


/**
*
* @author kebernet
*/
public class DBTest {
public static void doInsert() {
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.");
}

public void onFailure(
Transaction tx,
SQLError error) {
Window.alert(
"Insert failed.");
}
});
}

public void onFailure(Transaction tx,
SQLError error) {
Window.alert(
"Error creating database.");
}
});
}
});
}
});
}
}

Change log

r345 by kebernet on Aug 8, 2009   Diff
Undoing catastrophic error.
Go to: 
Project members, sign in to write a code review

Older revisions

r344 by kebernet on Aug 8, 2009   Diff
Format
r290 by kebernet on Apr 9, 2009   Diff
Works on everything except Opera.
r260 by kebernet on Mar 28, 2009   Diff
Checking in a bunch of stuff from this
week.
All revisions of this file

File info

Size: 4316 bytes, 89 lines
Powered by Google Project Hosting