February 6th, 2013 § § permalink
Hi all,
It’s been long time since my last post, I got a bit busy with work and other stuff :D. I’m going to write a new solution for iOS database limit, I solve it last year but don’t have time to post it.
To make it short, This is the plugin that I use to solve all the limitation problem, and gaining the speed. I use SQLitePlugin by davibe, many thanks to him.
just in-case you can’t find the js file from the plugin:
file name ‘pgsqlite_plugin.js’
2 | var callbacks, cbref, counter, getOptions, root, Cordova = cordova; |
10 | cbref = function(hash) { |
12 | f = "cb" + (counter += 1); |
17 | getOptions = function(opts, success, error) { |
21 | if (typeof success === "function") { |
25 | if (typeof error === "function") { |
29 | if (has_cbs) opts.callback = cbref(cb); |
33 | root.PGSQLitePlugin = (function() { |
35 | PGSQLitePlugin.prototype.openDBs = {}; |
37 | function PGSQLitePlugin(dbPath, openSuccess, openError) { |
39 | this.openSuccess = openSuccess; |
40 | this.openError = openError; |
42 | throw new Error("Cannot create a PGSQLitePlugin instance without a dbPath"); |
44 | this.openSuccess || (this.openSuccess = function() { |
45 | console.log("DB opened: " + dbPath); |
47 | this.openError || (this.openError = function(e) { |
48 | console.log(e.message); |
50 | this.open(this.openSuccess, this.openError); |
53 | PGSQLitePlugin.handleCallback = function(ref, type, obj) { |
55 | if ((_ref = callbacks[ref]) != null) { |
56 | if (typeof _ref[type] === "function") _ref[type](obj); |
58 | callbacks[ref] = null; |
59 | delete callbacks[ref]; |
62 | PGSQLitePlugin.prototype.executeSql = function(sql, success, error) { |
64 | if (!sql) throw new Error("Cannot executeSql without a query"); |
66 | query: [].concat(sql || []), |
69 | Cordova.exec("PGSQLitePlugin.backgroundExecuteSql", opts); |
72 | PGSQLitePlugin.prototype.transaction = function(fn, success, error) { |
74 | t = new root.PGSQLitePluginTransaction(this.dbPath); |
76 | return t.complete(success, error); |
79 | PGSQLitePlugin.prototype.open = function(success, error) { |
81 | if (!(this.dbPath in this.openDBs)) { |
82 | this.openDBs[this.dbPath] = true; |
86 | Cordova.exec("PGSQLitePlugin.open", opts); |
90 | PGSQLitePlugin.prototype.close = function(success, error) { |
92 | if (this.dbPath in this.openDBs) { |
93 | delete this.openDBs[this.dbPath]; |
97 | Cordova.exec("PGSQLitePlugin.close", opts); |
101 | return PGSQLitePlugin; |
105 | root.PGSQLitePluginTransaction = (function() { |
107 | function PGSQLitePluginTransaction(dbPath) { |
108 | this.dbPath = dbPath; |
112 | PGSQLitePluginTransaction.prototype.executeSql = function(sql, success, error) { |
113 | this.executes.push(getOptions({ |
114 | query: [].concat(sql || []), |
119 | PGSQLitePluginTransaction.prototype.complete = function(success, error) { |
120 | var begin_opts, commit_opts, executes, opts; |
121 | if (this.__completed) throw new Error("Transaction already run"); |
122 | this.__completed = true; |
123 | begin_opts = getOptions({ |
127 | commit_opts = getOptions({ |
131 | executes = [begin_opts].concat(this.executes).concat([commit_opts]); |
135 | Cordova.exec("PGSQLitePlugin.backgroundExecuteSqlBatch", opts); |
139 | return PGSQLitePluginTransaction; |
You need to add libsqlite3.dylib to your project, go to ‘Build Phases’ > ‘Link Binary with Libraries’ > Add and type in the library name.
And then I wrote, I mean modified my SQLite Class for HTML 5 Database to connect to database, so I won’t get alot of changes on my code to use it, and this is the code:
7 | check : function(tbl,callback){ |
8 | if(!this._db) return false; |
10 | var _sql = '', _sqlField='', _field=[]; |
12 | for(var i=0;i<tbl.length;i++){ |
13 | _sql = "CREATE TABLE IF NOT EXISTS "+tbl[i].table+" ("; |
14 | _field = tbl[i].properties; |
17 | for (var j=0;j<_field.length;j++){ |
18 | _sqlField += ',`'+_field[j].name+'` '+_field[j].type; |
21 | _sql += _sqlField.substr(1)+");"; |
23 | this.query(_sql,callback,null,null); |
32 | return this._response; |
37 | callback_error: function(tx,_er){ |
39 | if(typeof(tx) == 'object'){ |
41 | err += q+' = "'+tx[q]+'"; '; |
46 | if(typeof(_er) == 'object'){ |
48 | err += q+' = "'+_er[q]+'"; '; |
50 | }else if(typeof(_er) == 'undefined'){ |
54 | //if(callback) callback(); |
57 | query: function(sql,callback,params,er){ |
58 | if(!this._db) return false; |
60 | function _genErrorCallback(sql){ |
61 | return function(tx,__er){ |
62 | __er = jQuery.extend(__er,{sql:sql}); |
64 | else self.callback_error(tx,__er); |
70 | _query.splice(0,0,sql); |
72 | this._db.transaction(function(tx){ |
73 | tx.executeSql(_query,function(res){ |
74 | //echo('finish execute sql ' + _query , 300); |
76 | },self.callback_error); |
77 | },function(){return false;}, _genErrorCallback(_query)); |
79 | update:function(tbl,sets,clauses,callback){ |
80 | var __sql = 'UPDATE '+tbl, _field = null, __set = '', __clause = '',__values=[]; |
82 | for(var i=0;i<sets.length;i++){0 |
84 | for(var j=0;j<_field.length;j++){ |
85 | __set += ',`'+_field[j].name+'`=?'; |
86 | __values.push(_field[j].value); |
90 | for(var i=0;i<clauses.length;i++){ |
91 | __clause += ',`'+clauses[i].name+'`=?'; |
92 | __values.push(clauses[i].value); |
94 | __sql += ((__set!='')?' SET '+__set.substr(1):'')+((__clause!='')?' WHERE '+__clause.substr(1):'')+';'; |
95 | this.query(__sql,callback,__values); |
98 | remove:function(tbl, clauses, callback){ |
99 | var __sql = 'DELETE FROM '+tbl, __clause = ''; |
101 | if(typeof(clauses) != 'undefined'){ |
102 | for(var i=0;i<clauses.length;i++) |
103 | __clause += ',`'+clauses[i].name+'`="'+escape(clauses[i].value)+'"'; |
104 | echo('doing clauses'); |
105 | if(clauses.length > 0) |
106 | __sql += ' WHERE ' + ((__clause!='')?__clause.substr(1):'FALSE'); |
109 | this.query(__sql,callback); |
112 | multiInsert: function(tbl,rows,callback,er){ |
113 | if(!this._db) return false; |
115 | var __sql = '', _field = null, __field = '', __qs = [], __values = []; |
117 | this._db.transaction(function(tx){ |
118 | for(var i=0;i<rows.length;i++){ |
124 | for(var j=0;j<_field.length;j++){ |
125 | __field += ',`'+_field[j].name+'`'; |
127 | __values.push(_field[j].value ? _field[j].value : ''); |
130 | var _sql = 'INSERT INTO '+tbl+' ('+__field.substr(1)+') VALUES('+__qs.join(',')+');'; |
134 | _query.splice(0,0,_sql); |
135 | tx.executeSql(_query,function(){return false;},self.callback_error); |
138 | if(callback) callback(); |
140 | }, self.callback_error); |
144 | insert:function(tbl,rows,callback){ |
145 | var __sql = '', _field = null, __field = '', __qs = [], __values = [], __debug = ''; |
147 | for(var i=0;i<rows.length;i++){ |
152 | __debug += _field[0].name+' = '+_field[0].value+';'; |
153 | for(var j=0;j<_field.length;j++){ |
154 | __field += ',`'+_field[j].name+'`'; |
156 | __values.push(_field[j].value ? _field[j].value : ''); |
158 | __sql += 'INSERT INTO '+tbl+' ('+__field.substr(1)+') VALUES('+__qs.join(',')+');'; |
160 | this.query(__sql,callback,__values); |
163 | insertReplace:function(tbl,rows,debug){ |
164 | var __sql = '', _field = null, __field = '', __qs = [], __values = [], __debug = ''; |
166 | for(var i=0;i<rows.length;i++){ |
171 | __debug += _field[0].name+' = '+_field[0].value+';'; |
172 | for(var j=0;j<_field.length;j++){ |
173 | __field += ',`'+_field[j].name+'`'; |
175 | __values.push(_field[j].value ? _field[j].value : ''); |
177 | __sql += 'INSERT OR REPLACE INTO '+tbl+' ('+__field.substr(1)+') VALUES('+__qs.join(',')+');'; |
179 | this.query(__sql,null,__values); |
182 | dropTable:function(tbl,callback){ |
184 | if(tbl==null) return false; |
185 | __sql = 'DROP TABLE IF EXISTS '+tbl; |
186 | this.query(__sql,callback); |
190 | return jQuery.extend(ret,confs); |
How To Use It
Database Constructor:
» Read the rest of this entry «
August 20th, 2011 § § permalink
hi every one, I was trying to uninstall xcode 4, and I managed to uninstall it, but, when i want to re-install, i can’t get it from AppStore, it still marked as installed.
I was trying to remove all of the folder and no luck. After some time (15 minutes) go around to my folders, I found out “Install XCode” still in my /Application folder, that’s the reason why appStore keep it as Installed.
If you want to re-install the XCode, you just need to double click on “Install XCode” again and it will start the Installation step again.
This is a my small tips to uninstall XCode:
#from Terminal
$ sudo /Developer/Library/uninstall-devtools --mode=all
# or
$ sudo /Xcode4/Library/uninstall-devtools --mode=all
Depend on where is your Xcode get installed, sometime it’s not installed in /Developer but /Xcode4 because you have previous version Xcode 3.x
If you want the fresh Installation file of XCode, you will need to delete “Install Xcode” in /Application folder, and go to appStore again to download it.
thanks is all, talk to you guys soon, if you have some questions, just POKE me.
cheers,
helman.
June 15th, 2011 § § permalink
Hi all,
It’s been a while since the last post of iOS Databases Limit. Now, I’m doing an experiment about the geolocation on iPhone using Navigator – Geolocation on Google Maps.
This is just for your information about HTML5 navigator – GeoLocation. GeoLocation API is part of HTML5 library that can be used to define your device location.
methods:
1 | getCurrentPosition(callback[, error[, opts]]) |
4 | watchPositioin(callback[, error[, opts]]) |
10 | /* callback -> triggered when success of getting position */ |
19 | altitudeAccuracy: (double), |
23 | timestamp: (timestamp) |
26 | /* callback -> triggered when error occur while getting position */ |
31 | POSITION_UNAVAILABLE: 2; |
39 | enableHighAccuracy: (boolean), |
41 | long maximumAge: (long); |
» Read the rest of this entry «
April 6th, 2011 § § permalink
Hi all,
As we know, iOS only allow us to have 5MB Database if we use web-base application. I also faced the same problem when i’m doing application that need more than 5MB Database size on iPad / iPhone using PhoneGap as a wrapper.
After some experiment on iPad and iPhone, i found some thing that very interesting:
1. We cannot define / open database with more than 5MB size allocation.
2. We able to define / open more than one databases that each one has 5MB or less size allocation
3. Every databases being recorded in Databases.db under ‘~/Library/WebKit/Databases’
4. Databases file is stored in ‘~/Library/WebKit/Databases/file__0’ path.
5. ‘~/Library/WebKit/Databases/file__0’ folder has limit definition (5MB) in Databases.db under origin table.
What i did:
1. Run my application using iPhone / iPad simulation (run it once)
2. Get the Databases.db file under simulation folder
3. Open Databases.db using SQLite client, in here i’m using “SQLite Database Browser 1.3”

» Read the rest of this entry «