]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * @private\r | |
3 | */\r | |
4 | Ext.define('Ext.device.storage.HTML5.Database', {\r | |
5 | requires: ["Ext.device.storage.HTML5.SQLStatement"],\r | |
6 | db: null,\r | |
7 | \r | |
8 | constructor: function(config) {\r | |
9 | this.db = window.openDatabase(config.name, config.version, config.displayName, config.size);\r | |
10 | },\r | |
11 | \r | |
12 | getVersion: function() {\r | |
13 | if (this.db) {\r | |
14 | return this.db.version;\r | |
15 | }\r | |
16 | // <debug>\r | |
17 | Ext.Logger.warn('Database has not been opened before calling function #getVersion');\r | |
18 | // </debug>\r | |
19 | \r | |
20 | return null;\r | |
21 | },\r | |
22 | \r | |
23 | /**\r | |
24 | * @param {String/String[]/Object/Object[]/SQLStatement/SQLStatement[]} sql SQL Command to run with optional arguments and callbacks\r | |
25 | * @param {Function} success callback for successful transaction\r | |
26 | * @param {Function} failure callback for failed transaction\r | |
27 | */\r | |
28 | transaction: function(sql, success, failure) {\r | |
29 | if (!this.db) {\r | |
30 | // <debug>\r | |
31 | Ext.Logger.warn('Database has not been opened before calling function #transaction');\r | |
32 | // </debug>\r | |
33 | return;\r | |
34 | }\r | |
35 | \r | |
36 | if (!Ext.isArray(sql)) {\r | |
37 | sql = [sql];\r | |
38 | }\r | |
39 | \r | |
40 | \r | |
41 | var txFn = function(tx) {\r | |
42 | Ext.each(sql, function(sqlStatement) {\r | |
43 | if (Ext.isString(sqlStatement)) {\r | |
44 | tx.executeSql(sqlStatement);\r | |
45 | }else if(Ext.isObject(sqlStatement)) {\r | |
46 | tx.executeSql(sqlStatement.sql, sqlStatement.arguments, sqlStatement.success, sqlStatement.failure);\r | |
47 | }\r | |
48 | });\r | |
49 | };\r | |
50 | this.db.transaction(txFn, failure, success);\r | |
51 | }\r | |
52 | });\r |