Sqlite.Database.Connect always returns true, even if no file attached.

I have discovered, that “Database.Connect ( ) As Boolean”

always returns true after a new data base has been created.

I was using dbConnect to see if a DB was connected (See code below.)

dbConnect returns true even if the file selected is an RTF!

Is this a bug? If not how do I get around this feature to ensure that I have a legit Data Base connected?

Under what circumstances does dbConnect() return False?

dim dd as new SQLiteDatabase
Dim f as FolderItem
Dim rs as RecordSet
Dim s as string

stx1.Text=Str(dd.Connect)

f=GetOpenFolderItem("")
if f=nil then
stx2.Text=“Cancelled”
stx3.Text=Str(dd.Connect)
Return // if cancel pressed, no file opened. and we allow further handler processing. We also leave the opened file open.
end if

REM if we drop through, than have a FolderItem.
stx2.Text=f.DisplayName

dd.databaseFile=f

stx3.Text=Str(dd.Connect)

If the database file value is nil then an in memory database is created on the connect (SQLite). Check that your folder item “exists” before connecting.

I doubt that very much, a test shows that Connect returns false when the file is an RTF file:

[code] Dim fi As FolderItem = GetOpenFolderItem("") // Select an RTF-file

If fi Is Nil Then
// User cancelled dialog
Break
End

If Not fi.Exists Or fi.Directory Then
// File doesn’t exist or is a folder
Break
End

Dim db As New SQLiteDatabase()
db.DatabaseFile = fi

If Not db.Connect() Then
// Could not connect, be it because the file is not an SQLite database or for other reasons
Break
End

// We’re good
Break

[/code]

Can’t speak for Mac, but on Windows it wouldn’t really matter what the file extension is. I can take a database file and make the extension .docx and it will still connect. It will confuse Word if I double click it, but that’s not the point I’m making. If you can connect to the file then it’s a non-encrypted SQLite file regardless of the extension.

SQLite cares about the contents of the file, not the extension.

You can take an SQLite database and change the extension to RTF and it will work
but you can’t take an RTF file and change it to DB and expect it to work

for the SQLite.Org webpage

[quote]
SQLite does not impose any naming requirements on database files. SQLite will happily work with a database file that has any filename extension or with no extension at all[/quote]

Connect returns false if you have a valid, existing file that does not contain an actual database. Otherwise, it will create a database.