diff --git a/sqlite/Connection.js b/sqlite/Connection.js deleted file mode 100644 index 7787bc1..0000000 --- a/sqlite/Connection.js +++ /dev/null @@ -1,45 +0,0 @@ -// var a = {dbName : "test",dbVersion : "1.0",dbDescription: "testdb",dbSize : 65536}; - -Ext.define('Sqlite.Connection', { - extend: 'Ext.util.Observable', - /** - * @cfg {String} dbName - * Name of database - */ - dbName: undefined, - - /** - * @cfg {String} version - * database version. If different than current, use updatedb event to update database - */ - dbVersion: '1.19', - - /** - * @cfg {String} dbDescription - * Description of the database - */ - dbDescription: '', - - /** - * @cfg {String} dbSize - * Max storage size in bytes - */ - dbSize: 5 * 1024 * 1024, - - /** - * @cfg {String} dbConn - * database connection object - */ - dbConn: undefined, - - constructor: function (config) { - config = config || {}; - - Ext.apply(this, config); - var me = this; - - me.callParent([this]); - me.dbConn = openDatabase(me.dbName, me.dbVersion, me.dbDescription, me.dbSize); - return me; - } -}); \ No newline at end of file diff --git a/sqlite/data/proxy/SqliteStorage.js b/sqlite/data/proxy/SqliteStorage.js index 7f73966..3a60c38 100644 --- a/sqlite/data/proxy/SqliteStorage.js +++ b/sqlite/data/proxy/SqliteStorage.js @@ -25,7 +25,6 @@ Ext.define('Sqlite.data.proxy.SqliteStorage', { me.setTable(); }, - /* INTERFACE FUNCTIONS */ //inherit docs @@ -116,17 +115,17 @@ Ext.define('Sqlite.data.proxy.SqliteStorage', { if (typeof callback == 'function') { callback.call(scope, operation); } - }, - onError = function (tx, err) { - operation.setCompleted(); - operation.setException(err ? err : ''); - if (typeof callback == 'function') { - callback.call(scope, operation); - } - }; + }; - operation.setStarted(); + onError = function (tx, err) { + operation.setCompleted(); + operation.setException(err ? err : ''); + if (typeof callback == 'function') { + callback.call(scope, operation); + } + }; + operation.setStarted(); for (i = 0; i < length; i++) { queries.push(this.getDeleteRecordFunc(records[i], me.getDbConfig().tablename)); } @@ -154,20 +153,42 @@ Ext.define('Sqlite.data.proxy.SqliteStorage', { filters = operation.getFilters(), fieldTypes = {}; - grouper = this.applyGrouper(grouper); - filters = this.applyFilters(filters); - sorters = this.applySorters(sorters); - - // generate sql var sql = "SELECT _ROWID_,*\nFROM " + me.getDbConfig().tablename; - if (filters != null) sql += me.whereClause(filters); - if (grouper != null) sql += me.groupClause(grouper); - if (sorters != null) sql += me.orderClause(sorters); - if (limit != null && start != null) sql += me.limitClause(limit, start); + + if(!operation.config.hasOwnProperty("query")) { + grouper = this.applyGrouper(grouper); + filters = this.applyFilters(filters); + sorters = this.applySorters(sorters); + + // generate sql + if (filters != null) sql += me.whereClause(filters); + if (grouper != null) sql += me.groupClause(grouper); + if (sorters != null) sql += me.orderClause(sorters); + }else{ + sql = operation.config.query; + } + + var regExp = /select(.*\n*)from/gi; + var sql_count = sql.replace(regExp, "SELECT count(*) as total FROM"); + if (!isNaN(limit) && limit != null) sql += me.limitClause(limit, start); var onSuccess, onError; + var countGroups = operation.config.hasOwnProperty("countTotals") ? operation.config.countTotals : true; onSuccess = function (tx, results) { - me.applyDataToModel(tx, results, operation, callback, scope); + me.transactionDB(me.getDb(), [function (tx) { + tx.executeSql(sql_count, [], function(count_tx, count_results){ + var total_count = count_results.rows.length; + if(countGroups){ + total_count = 0; + for (var i=0;i