Sql difference between simu,ator and device

Hi everyone,

I am writing an app that uses sql lite. My screen has 8 text fields and a “save” and a “return” (to main menu) buttons. All the fields are to be written to the same table. Nothing happens to the fields except for input and all the work is done by the “save” button. In the “save” coding, I have validation to ensure that the first 2 fields can’t be blank before writing the data to the table.

My problem is that on the simulator, it all works perfectly. However on my iphone 4s, if any of the text fields are blank, the data is not stored. If I fill out all 8 fields then it works fine. On the simulator, if any of the fields are blank, the record is still stored fine.

For the device, do I need to do something like ensure there is a space in each field?

Thanks [import]uid: 83824 topic_id: 34322 reply_id: 334322[/import]

I’m not sure what the problem may be, but you can add the following to log errors:
(assuming you’re using db:exec() for inserting your data)

if (db:exec(sql) ~= 0) then  
 print("Database error ["..db:errmsg().."]\n"..sql);  
end  

On iOS:
This will print log messages to your device’s console. Use Xcode organizer to view the Console output

On Android:
Before running your app on your Android device, start ‘adb logcat -s Corona’ in a terminal window and watch for log messages. [import]uid: 70847 topic_id: 34322 reply_id: 136440[/import]

Thanks ingemar

I am at work but will try that when I get home. I have seen discussion on using Xcode to debug but have never needed to use Xcode before. It will be interesting to see if it gives me any pointers. I was wondering whether the device (4s) wouldn’t allow nulls or whether I have to specifically define something like “allow nulls”.

Thanks again

Adrian [import]uid: 83824 topic_id: 34322 reply_id: 136446[/import]

Unless you have specifically declared a column as “NOT NULL” when you created your table, then nulls should be accepted. [import]uid: 70847 topic_id: 34322 reply_id: 136447[/import]

That’s exactly what I thought but I haven’t specified anything to do with nulls. Not sure why the simulator should behave any differently to the device. [import]uid: 83824 topic_id: 34322 reply_id: 136448[/import]

I’m assuming that the INSERT is failing for some reason, but the log statement above should be able to catch that. [import]uid: 70847 topic_id: 34322 reply_id: 136451[/import]

I’m not sure what the problem may be, but you can add the following to log errors:
(assuming you’re using db:exec() for inserting your data)

if (db:exec(sql) ~= 0) then  
 print("Database error ["..db:errmsg().."]\n"..sql);  
end  

On iOS:
This will print log messages to your device’s console. Use Xcode organizer to view the Console output

On Android:
Before running your app on your Android device, start ‘adb logcat -s Corona’ in a terminal window and watch for log messages. [import]uid: 70847 topic_id: 34322 reply_id: 136440[/import]

Thanks ingemar

I am at work but will try that when I get home. I have seen discussion on using Xcode to debug but have never needed to use Xcode before. It will be interesting to see if it gives me any pointers. I was wondering whether the device (4s) wouldn’t allow nulls or whether I have to specifically define something like “allow nulls”.

Thanks again

Adrian [import]uid: 83824 topic_id: 34322 reply_id: 136446[/import]

Unless you have specifically declared a column as “NOT NULL” when you created your table, then nulls should be accepted. [import]uid: 70847 topic_id: 34322 reply_id: 136447[/import]

That’s exactly what I thought but I haven’t specified anything to do with nulls. Not sure why the simulator should behave any differently to the device. [import]uid: 83824 topic_id: 34322 reply_id: 136448[/import]

I’m assuming that the INSERT is failing for some reason, but the log statement above should be able to catch that. [import]uid: 70847 topic_id: 34322 reply_id: 136451[/import]