Saving Data

8 views
Skip to first unread message

Jeff McFadden

unread,
Oct 20, 2008, 1:42:38 AM10/20/08
to phonegap
I'm looking into saving data for my app... has anyone thought about
the best way to implement this? I don't want to reinvent the wheel if
possible, and I have limited Obj-C experience so I'm likely to do it
rather messily if I head out on my own.

-- Jeff

Dirk Holtwick

unread,
Oct 20, 2008, 1:48:35 AM10/20/08
to phon...@googlegroups.com
To keep it really simple I wrote a little Javascript helper that stores
data serialized as JSON into the local SQLite database. It uses
prototype to convert data to JSON. This one is for loading:

database.transaction(function(tx) {
tx.executeSql("SELECT data FROM data", [], function(tx, result) {
var data = result.rows.item(0).data
config = (new String(data)).evalJSON()
initWithConfig()
}, function(tx, error) {
tx.executeSql("CREATE TABLE data (data TEXT)", [],
function(tx, result) {
var data = (new Hash(config)).toJSON()
tx.executeSql("INSERT INTO data (data) VALUES (?)",
[data]);
initWithConfig()
});
});
});

And this is for storing:

database.transaction(function(tx) {
var data = (new Hash(config)).toJSON();
tx.executeSql("UPDATE data SET data=? WHERE 1", [data]);
});

Hope this helps.

Dirk

Jeff McFadden schrieb:

Jeff McFadden

unread,
Oct 20, 2008, 2:28:45 AM10/20/08
to phonegap
I just ran into this after I posted my question.

You get this functionality with every UIWebView?

-- Jeff

Dirk Holtwick

unread,
Oct 20, 2008, 2:31:14 AM10/20/08
to phon...@googlegroups.com
Yes I think so. I tested it with this code:

http://code.google.com/p/big5/source/browse/#svn/trunk

Chris Blown

unread,
Oct 20, 2008, 7:27:21 AM10/20/08
to phon...@googlegroups.com
Try
    if (window.openDatabase) {
document.write("open database present");
} else
document.write("open database not available");
}


Jeff McFadden

unread,
Oct 20, 2008, 8:02:10 PM10/20/08
to phonegap
Managed to get enough code working to verify that this does in fact
work. Hopefully I'll have a self-contained object that can manage
storing data to a sort of game_save location for serializing save game
type data.

How awesome that you get a storage DB for free with a UIWebView!

Why would ANYONE want to waste their time with Obj-C for most apps??

-- Jeff
Reply all
Reply to author
Forward
0 new messages