About creating database with code

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?


S = "..." + _
"..." + _

The easiest thing to do is put the SQL into a class or module constant.



I copied/pasted the sql as is from the DB Browser Into a constant and that constant in the sql command:

works like a charm! Thanks so much.

1 Like

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.

1 Like

Thanks Tim, for this issue it is resolved now using constants, but it’s indeed good to know how to do this.

André, can you explain what you mean when you talk about “Constant” ?

I placed all the sql code in a Constant.
Screenshot 2022-10-04 at 08.44.24

Yes, that is what you says and it seems to be correct, but I do not get it.

You were talking about using multiple lines… And I… do not understand how you’re doing that in App.Constants…



    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)

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, " +_
  If db.Error Then
    MsgBox("Database error: " + db.ErrorMessage)
    MsgBox("The TABLE ““Employee”” have been added to the Data Base file.")
  End If
  MsgBox("Unable to open the Data Base File. Error: " + db.ErrorMessage)
End If

This was a long search (on my hard disks) !

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.

After you have types the lines you want in the large text sheet, the first few lines will be visible in the Default Value box.


I checked, but I do not add a constant.

NB: I wrote the above code especially to show how to use many lines…

A long time ago I used FoxPro for development. FoxPro had Text…EndText commands.

Anything between the Text and EndText could be multiple lines (like in a Xojo constant). Very convenient for writing SQL.

Other languages use backticks, three quotes, or three single quotes. But I’d settle for same-screen view/edit of constants.