Android Question Why do I get No such table?

GEoffT

Member
Licensed User
Longtime User
Probably a stupid question, but I am just starting with Basic4Android. I don't understand why I get a "no such table" from the second Query. Surely the first one would have created it.


Sub btnArchersD_Click
'Label1.Text = "Archers diary"
Dim cursor1 As Cursor
SQL1.BeginTransaction
Try
SQL1.ExecNonQuery("CREATE TABLE IF NOT EXISTS archers(archerID Integer Primary Key, FName Text, LName Text, BowType Text)")
Catch
Log(LastException.Message)
End Try
SQL1.EndTransaction
' check if any entries in table
SQL1.BeginTransaction
Try
cursor1 = SQL1.ExecQuery("SELECT * FROM archers")
Catch
Log(LastException.Message)
End Try
SQL1.EndTransaction
 

barx

Well-Known Member
Licensed User
Longtime User
How are you initializing SQL1?

Are you trying to use the DB whilst it is in 'Assets'?
 
Upvote 0

GEoffT

Member
Licensed User
Longtime User
This is my initialization statement. I thought that this meant it was not in assets

SQL1.Initialize(File.DirRootExternal,"adcd.db",True)
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Tried adding
B4X:
sql1.TransactionSuccessful
just before the endTransaction line?
In general, I would avoid these try...catch blocks.
Finally, in executing queries such as 'select' there's no need of begin-end transaction.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
This is my initialization statement. I thought that this meant it was not in assets

SQL1.Initialize(File.DirRootExternal,"adcd.db",True)

Correct your not supposed to work with DB in assets, do you copy from assets to DirRootExternal first?
 
Upvote 0

GEoffT

Member
Licensed User
Longtime User
Took the begin and end transaction and try-catch from around the first select and now it appears to work!
 
Upvote 0
Top