Create new database file at first run iOS

Hi. Can you take a look at the following code and comment where wrong? This is similar to what I use for desktop apps but getting a nil object when trying to call the db on iOS. Also, what is the process of adding a record to the table? The EEiOS example shows how to update a record not add one.

[code] Dim dbFile As FolderItem
dbFile = SpecialFolder.Documents.Child(“userDB.sqlite”)

If Not SpecialFolder.Documents.Child(“userDB.sqlite”).Exists Then
// Only creates the file if it is not already there
Dim newDB As New SQLiteDatabase
newDB.DatabaseFile = dbFile

'creates tables
if newDB.CreateDatabaseFile then
  Dim sqlUser as Text
  sqlUser = "CREATE TABLE users (userID INTEGER NOT NULL, FirstName TEXT, LastName TEXT, EmailAddress TEXT, NumberOnAllTest INTEGER, NumberQuestions INTEGER, PRIMARY KEY(userID));"

End If
End If[/code]

Ok, i was able to add and connect to the users table, now I am finding that my errors seem to be in the INSERT portion. Could someone take a look at this to see if my syntax is correct? Getting “SQLiteException” error at the SQLExecute line.

dim sqlAddUser as Text sqlAddUser = "INSERT INTO users (userID, NumberOnAllTest, NumberQuestions, D1Corr, D2Corr, D3Corr, D4Corr, D5Corr, D1Taken, D2Taken, D3Taken, D4Taken, D5Taken) VALUES ('1', '1', '25', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');" newDB.SQLExecute(sqlAddUser)

You are creating table users with 6 columns and the insert takes 13.

Yea I actually updated my CREATE TABLE to include these plus a few more, but I only want to preload these. Do I need to add something in each column when doing INSERT?

Is sqlite giving you an errorcode?

Here’s the SQLException
UNIQUE constraint failed: users.userID

You’re using PRIMARY KEY(userID).
The primary key has to be unique INTEGER in your table.
Can you verify this?

Ahhh ok. I removed the userID and its value from the INSERT. Now it worked! Thanks for taking a look at this!