4

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 PhoneGap 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.

1
  • Hmm..I'm not keen on HTML5, but I can give it a try. Do you add flags to you database what allow you do modifications like the one it is in android SQLiteDatabase.OPEN_READWRITE? I mean do you have priviledges to write, did you make sure you can connect to the database? Commented Jul 23, 2011 at 20:18

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

It would be very worthwhile to put the error message you were getting on the iPhone somewhere on this page. That way when someone searches for it someday, they will find your discovery!
There was no error whatsoever. Everything appeared as OK to the moment, when I needed to pull the data from the table, that was unfortunately empty.
Android seems to accept SQL queries over 1000 chars, acording to the code I've just tested. If iPhone doesn't...that is annoying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.