I am creating a script in Xojo to create my database with code. I already created the database within the DB Browser for SQLITe program, but I think it would be a good idea to have the option to be able to Create it from within the app as well (especially because I almost lost my created DB…).
I have lots of columns in the database and tried to do a simple copy/paste from the DB Browser program into the Xojo code, but that doesn’t seem to work without removing all the quotes that the DB Browser program places around the column names. No problem though. What is a little bit a problem is that I seem to have to place all the columns code on a single line of code in Xojo which makes it very difficult to get track with so many columns. Is there a way to keep if more organised as in the screenshot?
You need to learn how to do statement continuation on the next line. You have to tell it explicitly (using the underscore) that you are doing this. And in your case you’ll have to tell it to concatenate all the bits of string, too.
And this is an example I wrote and shared this summer:
Var db As New SQLiteDatabase
// Set the Database file to the db Reference
db.DatabaseFile = DB_FI // DB_FI is a File Reference
If db.Connect Then
// Add a TABLE And Rows
Var sql_Cmd As String
sql_Cmd = "CREATE TABLE IF NOT EXISTS Employee(« +_
"Name_First TEXT, " +_
"Name_Last TEXT, " +_
"Job_Titre TEXT, " +_
"Job_Salary Text, " +_
"Employe_ID TEXT, " +_
"Employe_Photo TEXT, " +_
"Employe_Entry_Date DATE, " +_
"ID INTEGER NOT NULL, PRIMARY KEY(ID));"
db.SQLExecute(sql_Cmd)
If db.Error Then
MsgBox("Database error: " + db.ErrorMessage)
Else
MsgBox("The TABLE Employee have been added to the Data Base file.")
End If
Else
MsgBox("Unable to open the Data Base File. Error: " + db.ErrorMessage)
End If
When you create a constant in Xojo, it can be as many lines as you like. Type what you will into the Default Value area. If you want multiple lines, click on the ellipsis button (…) and a window will a large text sheet will appear and you can write as many lines as you like here.