Hi I am a new user and am working with some of the example code. When attempting a simple Database insert using SQL I keep getting a Database Closed error message. I’ve also tried the Insert Database Record example and get the same error. The database is in the same folder as the project and opens and updates perfectly via SQlite Browser. I am following the example code pretty closely so don’t understand why I am getting this error. Any help would be great as I want to move onto coding in greater detail with Xojo, thanks.
Code:
Dim dbFile As FolderItem
Dim db As New SQLiteDatabase
dbFile = GetFolderItem(“C:\…\dbase.sqlite”) //exact path to sqlite file
db.DatabaseFile = dbFile
db.SQLExecute(“BEGIN TRANSACTION”)
db.SQLExecute (“INSERT INTO Things (Number, Last, First) VALUES “+”(‘Dr.Strangelove’,‘Advisor’,1962)”)
If db.Error then
MsgBox("Error: " + db.ErrorMessage)
db.Rollback
Else
db.Commit
End If
Am using the latest download of the IDE: 2014 R3.1 on Windows 8.1 Pro.
db.DatabaseFile = dbFile
if db.connect = false then
msgbox "Never connected to the db!"
Return
end
db.SQLExecute("BEGIN TRANSACTION")
db.SQLExecute ("INSERT INTO Things (Number, Last, First) VALUES "+"('Dr.Strangelove','Advisor',1962)")
BTW, this bit: dbFile = GetFolderItem(“C:\…\dbase.sqlite”) //exact path to sqlite file is not cross platform. You’ll want to look up more info on FolderItems and how to access.
If it’s in the same folder as the executable you can do this:
If video training is your thing you can take a look at our Xojo training videos at http://xojo.bkeeney.com/XojoTraining/. Over 200 videos, 62+ hours, and most of them come with the source that you can use in your own projects.
#Bob, boy don’t I feel like an idiot. Thanks for pointing that out. Getting just bleary eyed looking at the code. I’ll definitely check out your training resources.
#Tim, the example was from the Language Reference Wiki on SQLite and the db.Connect check is in there…
No worries, it happens. Tim and I probably have a combined 30 years using Xojo so the issue jumped out at us.
Xojo is a big framework and it takes a while to figure it out. Doing things step by step for a while is the best way of going about learning it. If you run into issues take a step back and maybe create a small sample app to learn about a subject (which is how a lot of my early training videos came into being).
Ask questions on the forums. This is a (mostly) friendly group that’s willing to help but don’t forget to search for an answer first because a lot of issues have been asked multiple times.