Android Code Snippet Tip: SQLite Column Does not exist even if you know it exists!!!

Ola

When you run your app and developing it during debug and release mode. You will find out that you encounter this error.

NB: If during development you make changes to your schema on your files inside "Files" tab.

Now if your code has this kinda of statement.

B4X:
'copy the default DB to working folder
    If File.Exists(xui.DefaultFolder, DbaseLocal) = False Then
        File.Copy(File.DirAssets, DbaseLocal, xui.DefaultFolder, DbaseLocal)
    End If

This means that the database should only be copied if it does not exist. If it exists and you made new changes, you have a bomb!

Solution: Completely de-install your app from your device, this will remove the database also. Installing over and over and coding will not update your db, unless of course you directly run File.Copy each time you debug your app.

#FromARustyB4AHead.
 

klaus

Expert
Licensed User
Longtime User
To overcome this problem I add a line to delete the database.
I uncomment it when needed.

B4X:
'    File.Delete(SQLDataBasePath, SQLDateBaseName) ' only for testing, removes the database
        
    'check if the database already exists
    If File.Exists(SQLDataBasePath, SQLDateBaseName) = False Then
        'copy the default DB
        File.Copy(File.DirAssets, SQLDateBaseName, SQLDataBasePath, SQLDateBaseName)
    End If
 

mangojack

Expert
Licensed User
Longtime User
To overcome this problem I add a line to delete the database.
I uncomment it when needed.

I adopt the same method ...
 

KMatle

Expert
Licensed User
Longtime User
I create the db, the tables and insert the data at the first startup by code. When I test an app I can drop everthing, add/drop a column or change the data very quick (otherwise you need to use a tool to create/change the db and copy ecerything again).
 
Top