· 8 years ago · Aug 22, 2018, 06:58 AM
1why doesn't my calback function fire?
2function setupDB() {
3hum('setupDB start');
4var shortName = 'myapp';
5var version = '1.0';
6var displayName = 'MyApp';
7var maxSize = 65536;
8db = openDatabase(shortName, version, displayName, maxSize);
9if (!db) { hum('setupDB failure to open db');}
10else db.transaction(
11 function(transaction) {
12 hum('setupDB opened db');
13 transaction.executeSql(
14 'CREATE TABLE IF NOT EXISTS hotlist ' +
15 ' (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' +
16 ' name TEXT NOT NULL, ' +
17 ' addr TEXT NOT NULL, ' +
18 ' city TEXT , ' +
19 ' category TEXT , ' +
20 ' itemid INTEGER , '+ //eg the restaurant id
21 ' lat FLOAT, lon FLOAT, '+
22 ' desc TEXT NOT NULL, '+ //is this a french restaurant, a dance bar, what subcategory of category
23 ' rating FLOAT, '+
24 ' UNIQUE (itemid, category) )',
25 successHandler,errorHandler
26 ); // eg movie rating
27
28 }
29);
30
31function errorHandler( transaction,error) {
32if (error)
33 hum('Oops. Error was '+error.message+' (Code '+error.code+')');
34else
35 hum('Oops. Error but no error object');
36return true;
37
38function successHandler( transaction,results) {
39if (results)
40 hum('Success results=='+results.rows.length );
41else
42 hum('Success no results');
43return true;
44
45function hum(mess,alrt){
46if (debughum == 1){
47 console.log('hum mess=='+mess);
48 if (alrt && alrt=='true') alert(mess);
49}
50
51transaction.executeSql(
52 'CREATE TABLE IF NOT EXISTS hotlist ' +
53 ' (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' +
54 ' name TEXT NOT NULL, ' +
55 ' addr TEXT NOT NULL, ' +
56 ' city TEXT , ' +
57 ' category TEXT , ' +
58 ' itemid INTEGER , '+ //eg the restaurant id
59 ' lat FLOAT, lon FLOAT, '+
60 ' desc TEXT NOT NULL, '+ //is this a french restaurant, a dance bar, what subcategory of category
61 ' rating FLOAT, '+
62 ' UNIQUE (itemid, category) )',
63 [],
64 successHandler,
65 errorHandler
66 ); // eg movie rating