views:

75

answers:

1

Hi (this is my first post on StackOverflow :),

every time i increase my database version and push the upgraded app to the users, something weird happens.. For some it works perfectly fine, and some report crashes (including through the Market's reporting system) caused by the lack of table columns i just added in onUpgrade.

If you want to see the method: http://code.google.com/p/tag-todo-list/source/browse/trunk/Donut/src/com/android/todo/data/ToDoDB.java#136

I can't spot any exceptions that appear in onUpgrade. What i'm currently doing to bypass these problems is intercepting the exceptions where the new fields are invoked for the first time and then calling onUpgrade 'manually', which is kind of dirty.

Also, the app sometimes generates a 'no such table' SQLiteException when accessing the main table (again, only for some users) which is incredibly strange... Does someone know why these things happen? Or can you spot something wrong in my code?

Thanks, Teo

A: 

I haven't read through your code in depth, but are you seeding the records with values when you add a column? I can see that you are putting a default value in there, but when you first add a new column into an existing table, what is going into the column fields for the existing records in your tables?

I had similar issued with this on version upgrades, but by also executing a db.exec("UPDATE... function call I could seed the default value into all the existing records. This fixed a lot of those "X column does not exist" errors and such.

Adriaan
Any progress with this?
Adriaan
Teo
Well I was getting those exceptions when I was including them in the Cursor. You are only going to notice them when you are doing operations with the data, either reading or writing from the database. What system are you using to develop your apps with? I am surprised you would not be getting exceptions popping up when you are testing if you are not doing that, particularly if you have data that is `not null`. Also, it is always nice to give back to the community but giving credit. Hit the tick mark.
Adriaan
I'm using the standard emulator, no errors on it, on my phone and on most user phones... The only problem is these things still happen for quite a few users and i can't spot the cause. The 'no such table' exception is particularly annoying since i can't get around it :/
Teo
Could it be earlier (or later?) versions of the SDK that are giving you issues? Does your app require a particular version and/or have you tried running your app on an earlier version of Android?
Adriaan
The build target is Android 1.6 and android:minSdkVersion="4". Theoretically it should run on anything >= 1.6 (I use it on 2.2 on my own phone, and it works flawlessly). And even weirder, i have 2 tables, one is missing for some, and the other is missing for others, it's like their creation somehow fails without an exception in onCreate, but where they're first accessed through SQL.
Teo