开发者

Problem with SQL database in PhoneGap application running on iPhone

I have mobile app written in HTML5 using PhoneGap. Some parts of the app make use of SQL database, like this:

db = window.openDatabase("my_app_database", "1.0", "Description of my database about 50 chars long", 1000000); 

$.get('db/app_data.dat',function(result){
  var data = $.parseJSON(result);
  if (!data) {
    alert('Data error');
    return false;
  }
  db.transaction(function(tx){
    tx.executeSql('DROP TABLE IF EXISTS table_a');
    tx.executeSql('DROP TABLE IF EXISTS table_b');
    tx.executeSql('CREATE TABLE table_a (id INTEGER,name,html)');
    tx.executeSql('CREATE TABLE table_b (id_a INTEGER, id_b INTEGER)');
  });
  db.transaction(function(tx){
    $.each(data.item, function(i, v){
      tx.executeSql('INSERT INTO table_a(id, name,html) VALUES (?,?,?)',[v.id, v.name, v.html]);
    });
  });
});

On Android this works perfectly fine with no problem. But on iPhone(4.0, 4.2) it doesn't work at all. Do you have any ideas why this standard use of SQL database on PhoneGa开发者_如何学JAVAp would cause any kind of trouble on iPhone ? Are there some limits to be aware of ? E.g. database name limit, database size limit or query limits ?

EDIT: Don't know if it is relevant, but I am using PhoneGap v. 0.9.5.1 in this app right now.


Ok, I've finally figured out this problem. There seems to be some kind of SQL-query-length limit, which is not documented. At least I haven't found it anywhere. My INSERT query was 190 characters long (for the simplicity of asking question here I have shortened the query in the given example) and when I kept trying and testing, I also tried to make column names shorter. I don't know the exact number of this limit, but query with the length of 130 characters worked fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜