SQLite tables not being created
Posted: Fri Feb 04, 2011 11:07 pm
Hi, I'm doing a simple app which reads from a Sqlite database. I'd like the program to be able to create the database file on its own if it doesn't exist, like a first-time setup. While the database file gets created with my code, the sql CREATE command for my table fails. Here's my code:
While not included Here, I called UseSQLiteDatabase() in a procedure which executes before this. The value 'r' returned from DatabaseQuery() is equal to 1, but the data file measures 0kb on disk, and attempting to do an INSERT command returns a "table does not exist" error. Can anyone help? Thanks!
Code: Select all
Procedure CreateData()
db_handle = CreateFile(#PB_Any,"data.dat")
db_handle = OpenDatabase(#PB_Any,"data.dat","","",#PB_Database_SQLite)
If db_handle=0
MessageRequester("Fatal Error","Fatal Error. Database cannot be created.")
End
Else
stmt$="CREATE TABLE Alert (id INTEGER PRIMARY KEY AUTOINCREMENT Not NULL , description VARCHAR, alert_time DATETIME)"
r= DatabaseQuery(db_handle,stmt$)
If r=0
MessageRequester("Fatal Error","Unable to Initialize Data Tables.")
End
Else
MessageRequester("Success!","Database succesfully initialized for first run.")
EndIf
FinishDatabaseQuery(db_handle)
EndIf
EndProcedure