Android Question intercepting SQLite runtime native error

peacemaker

Expert
Licensed User
Longtime User
HI, All

1) If SQLite table format is has to be changed, but an app is already widely used - how to update the db structure preserving the current tables' data?

2) Is it possible to catch SQL runtime error like
B4X:
Dim sms_sent As Int = Starter.SQL.ExecQuerySing
android.database.sqlite.SQLiteException: no such column: sms_sent (code 1): , while compiling: SELECT sms_sent FROM orders WHERE id = '1'
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
    (no such column: sms_sent (code 1): , while compiling: SELECT sms_sent FROM orders WHERE id = '1')
#################################################################
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1008)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:573)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1711)
    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1650)

?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What about question 2 ?
Check the table structure (field existing or not) before you send the query.
Usually it is a coding mistake. Like here as you did not alter the table to add the new column.

You may consider using versioning in your Database
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Thanks, but question was about another code.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Thanks, but question was about another code.

Try... Catch... like any other exception

Why don't you follow Manfreds suggestion:

a) if you change a table you need to update your app
b) in you app check if the table has the new columns
c) if not, just alter the table

That's it. Not need to catch exceptions
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I just wonder that such SQL error is without the line number in the log.
 
Upvote 0
Top