SQLite
Posted
#1
(In Topic #1236)
Administrator

Code
If Not MGlobal.hDB.Tables.Exist("test") Then
dbTable = MGlobal.hDB.Tables.Add("test")
dbTable.Fields.Add("id", DB.Integer)
dbTable.Fields.Add("name", DB.String, 50)
dbTable.Fields.Add("url", DB.String, 255)
dbTable.Fields.Add("show", DB.Integer)
dbTable.PrimaryKey = ["id"]
dbTable.Update()
End If
Posted
Expert

You can read about it here on the SQLite site.
As a side note, you can create tables by storing the creation script as a file, reading it in and executing it as a SQL command.
This is an example that I've used to create a 'Category' table.
I find this better than using the code creation method as you can edit an existing file and tweak for new fields and name and it takes far less time to create large table sets.
If you have an existing database with a lot of tables, you can create a backup of all your tables with this subroutine:
Code (gambas)
- TmpTable = $Con.Tables[InName]
- TmpLine &= "CREATE TABLE '" & InName & "' (" & Gb.NewLine
- LastLine = TmpTable.Fields.Count - 1
- KeyStr = ""
- TmpLine &= "'" & TmpField.Name & "' "
- TmpLine &= "TEXT"
- TmpLine &= "," & Gb.NewLine
- TmpLine &= ");" & Gb.NewLine
- LastLine -= 1
- ReturnStr &= TmpLine
- TmpLine = ""
- Return ReturnStr
…and create them all with this one.
Code (gambas)
- $InCon.Close
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Administrator

I'll file your information away somewhere for later use (or forgetting!
Posted
Expert

I do a lot of work with SQLite but nothing so complex or large that would require multiple indexes to speed up search functions.
Instead, I found that a bit of effort on good validation in the input form is a better solution and you can give you users a better constructed error message to fix the issue.
Cheers - Quin.
I code therefore I am
I code therefore I am
1 guest and 0 members have just viewed this.


