Creating a new file for a SQLite database

dbSQL.DatabaseFile = getFolderItem("").child( "NFMarketPlaceDB.sqlite" )
  
  if dbSQL.databaseFile.exists then
    if not dbSQL.connect() then
      MsgBox("Database Connection Error")
      gDBError = "Y"
      return
    end
  else   // dbSQL was not found
    iMsgResult = MsgBox("Database Not Found, Create New Database File?",4)
    if iMsgResult = 6 then
       CreateNewDBFile
    else
       gDBError = "Y"
    end
    return
  end

dbSQL is defined as GLOBAL SQLiteDatabase

When this code executes I get a nil exception before I have a change to test if the file exist.
How do I do this now?

thanks,

You need to initialize it first:

dbSQL = new SQLiteDatabase

the init is done as a global property - in the same module as the above method but since it’s global I just made it a separate property since virtually everything in the app uses the database…

In the method where you instantiate the dbSQL property, make sure you don’t have a DIM line.

dim dbSQL as SqliteDatabase    // creates a local variable of the same name as the property
dbSQL = new SqliteDatabase   // loads the local variable and leaves the global property nil

You have defined the variable, but it will be nil until you create a new instance of the SQLiteDatabase:

[code]
if (dbSQL is nil) Then
dbSQL = new SQLiteDatabase
end if

dbSQL.DatabaseFile = getFolderItem("").child( “NFMarketPlaceDB.sqlite” )

if dbSQL.databaseFile.exists then
if not dbSQL.connect() then
MsgBox(“Database Connection Error”)
gDBError = “Y”
return
end
else // dbSQL was not found
iMsgResult = MsgBox(“Database Not Found, Create New Database File?”,4)
if iMsgResult = 6 then
CreateNewDBFile
else
gDBError = “Y”
end
return
end[/code]