Sub CreateTable(SQL As SQL, TableName As String, FieldsAndTypes As Map, PrimaryKey As String, Auto As Boolean)
Dim sb As StringBuilder
sb.Initialize
sb.Append("(")
For i = 0 To FieldsAndTypes.Size - 1
Dim field, ftype As String
field = FieldsAndTypes.GetKeyAt(i)
ftype = FieldsAndTypes.GetValueAt(i)
If i > 0 Then sb.Append(", ")
sb.Append("[").Append(field).Append("] ").Append(ftype)
'If field = PrimaryKey Then sb.Append(" PRIMARY KEY") 'Original line changed below
If field = PrimaryKey Then
sb.Append(" PRIMARY KEY")
If Auto = True Then sb.Append(" AUTOINCREMENT")
End If
Next
sb.Append(")")
Dim query As String
query = "CREATE TABLE IF NOT EXISTS [" & TableName & "] " & sb.ToString
Log("CreateTable: " & query)
SQL.ExecNonQuery(query)
End Sub
Source: Billy047 @ http://www.basic4ppc.com/android/forum/threads/dbutils-android-databases-are-now-simple.8475/page-2
Originally Posted on September 27, 2013
Last Updated on December 30, 2015
Last Updated on December 30, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.