database connecting with nil databasefile

I think there’s a bug here but I guess it depends on if you’re supposed to be able to connect to a db after assigning a nil databasefile.

This reports that it could not connect the the database:

[code]dim db as new SQLiteDatabase
dim f as FolderItem

f = SpecialFolder.UserHome.Child(“this folderitem does not exist”)

db.DatabaseFile = f
if not db.Connect then
MsgBox(“not connected to db”)
else
MsgBox(“connected to db”)
end if[/code]

This reports that the database did connect:

[code]dim db as new SQLiteDatabase
dim f, g as FolderItem

f = SpecialFolder.UserHome.Child(“this folderitem does not exist”)
g = f.Child(“this folderitem does not exist”)

db.DatabaseFile = g
if not db.Connect then
MsgBox(“not connected to db”)
else
MsgBox(“connected to db”)
end if[/code]

In both cases the databasefile folderitem is nil.

And I should add that I’m not sure if connecting with a nil database file is supposed to be an error or the db is considered in-memory.

I’d expect its connecting to an in memory database

So should it connect in-memory in both cases?

if the folder item is nil thats what I would expect since

dim db as new SQLiteDatabase break if not db.Connect then MsgBox("not connected to db") else MsgBox("connected to db") end if

is how you connect to an in memory db and the database file is nil at the break
Not sure how it could distinguish
About the only way to test is to have a valid folder item and check “exists”

So the first example is a bug since it is reporting not connected rather than connecting in memory?

No
The first one has a VALID non-nil folderitem that simply doesn’t exist
The correct course of action would be NOT to connect but to CREATE the database file

The second has a NIL folderitem so it connects to one in memory

Yes, I was thinking that the first was nil when it just didn’t exist. I guess I was hoping for functionality along the lines “you tried to assign a non-existent folderitem to a databasefile so I’m not going to connect.” When in doubt, error check.

My template is +/-:

  db = New SQLiteDatabase
  Dim dbf As FolderItem = SpecialFolder.UserHome.Child("myDB.sqlite") // Not the best place
  db.DatabaseFile = dbf
  if dbf.Exists Then                // Exists, open
    If Not db.Connect Then
      MsgBox "Oops. Open error: "+db.ErrorMessage
      Quit
    End
  Else
    If db.CreateDatabaseFile Then   // New. Create it
      db.SQLExecute(SQLCreateDB)  // Create tables and structures
      If db.Error Then
        MsgBox "Create db struct error: "+db.ErrorMessage
        Quit
      End
    Else
      MsgBox "Create db error: "+db.ErrorMessage
      Quit
    End
  End

File not exists <> nil folderitem.
Impossible path / couldn’t possibly create a file there = nil folderitem.