24. *Note
Firefox 2 has older version of spec:
function getStorage() {
if (typeof localStorage != 'undefined')
return localStorage;
else
return globalStorage[window.location.hostname];
}
29. CREATE TABLE
db.transaction(function(tx) {
tx.executeSql(quot;CREATE TABLE IF NOT EXISTSquot;
+ quot;COUNTRY (id REAL UNIQUE, name TEXT)quot;,
[], function(tx, result) {
// SQL executed; do more work
});
}, function(tx, error) {
alert(error.message);
return;
});
30. SELECT
db.transaction(function(tx) {
tx.executeSql(quot;SELECT id, name FROM COUNTRYquot;,
[],
function(tx, result) {
for (var i = 0; i < result.rows.length; +
+i) {
var row = result.rows.item(i);
alert('id='+row['id');
alert(' name='+row['name']);
}
}, function(tx, err) { alert(err.message); }
);
31. INSERT
db.transaction(function(tx) {
tx.executeSql(
quot;INSERT INTO COUNTRY quot;
+ quot; (id, name) VALUES (?, ?)quot;,
['1', 'United States']);
});
39. Application Cache
• Point to manifest file:
<html manifest=”foo.manifest”>
• foo.manifest must have correct MIME type:
• text/cache-manifest
40. Application Cache
• Example manifest:
CACHE MANIFEST
# v1
# This is a comment.
http://www.foo.com/index.html
http://www.foo.com/header.png
http://www.foo.com/blah/blah
somethingElse.jpg
46. Application Cache
• Update process
• Manifest file fetched
• If changed
• Files refetched in temp cache
• When done, becomes real cache
47. Application Cache
• Update process
• Manifest file fetched
• If changed
• Files refetched in temp cache
• When done, becomes real cache
• Events are fired
63. Database API
var db = google.gears.factory.create('beta.database');
db.open('database-test');
db.execute('CREATE TABLE IF NOT EXISTS Test' +
' (Phrase TEXT, Timestamp INT)');
db.execute('INSERT INTO Test VALUES (?, ?)', ['Monkey!',
new Date().getTime()]);
64. Database API
var rs;
try {
rs = db.execute('SELECT * FROM Test ORDER BY Timestamp DESC');
while (rs.isValidRow()) {
console.log(rs.fieldByName(‘Phrase’) + '@'
+ rs.fieldByName(‘Timestamp’));
rs.next();
}
} finally {
rs.close();
db.close();
}