SQLite / Error: "unable to open database file" on Linux host, fine running in the IDE on Mac

Some people complain about not being able to debug in 64 bit… What do you do to debug a program that is running on a distant host and does not behave like in the IDE ?

Here is my problem : the very same method that records data just fine when a Web program runs in the IDE on Mac gets an error “unable to open database file” when the program runs on the Linux host. I simply record a code, SecondsFrom1970, and the current date.

I use code adapted from the SQlite example.

This step goes fine in both cases in the Open event. The Debuglog method places the messages in a property I can read from the web app :

[code] DB = New SQLiteDatabase

Dim f As FolderItem

If DebugBuild then
f = app.ExecutableFile.Parent.Parent.Parent.parent.child(“compteurs.sqlite”) 'SpecialFolder.Documents.Child(“compteurs.sqlite”) 'New FolderItem(“compteurs.sqlite”)
system.DebugLog app.ExecutableFile.ShellPath
Debuglog str(f.exists)+EndOfLine
else
f = app.ExecutableFile.Parent.child(“compteurs.sqlite”) 'SpecialFolder.Documents.Child(“compteurs.sqlite”) 'New FolderItem(“compteurs.sqlite”)
Debuglog str(f.exists)+EndOfLine
end if

db.DatabaseFile = f
If db.CreateDatabaseFile Then
// proceed with database operations…
Debug = Debug + "Database created "+EndOfLine
Else
MsgBox("Database not created. Error: " + db.ErrorMessage)
Debuglog "Database not created. Error: " + db.ErrorMessage+EndOfLine
End If[/code]

The file exists, and database is created.

Where it gets bad is here. When run in the IDE on Mac the record is added just fine. When run on the Linux host I get the “unable to open database file”. I verified the permissions for the sqlite file, it is 666, everybody can read and write :

[code] If db.Connect Then
// App.DB is a connected database
Dim tables As RecordSet
tables = DB.TableSchema

dim lestables as string
If tables <> Nil Then
  While Not tables.EOF
    lestables = lestables + tables.IdxField(1).StringValue
    tables.MoveNext
  Wend
  tables.Close
End If

if instr(lestables, "ftstest") = 0 then
  db.SQLExecute("CREATE VIRTUAL TABLE ftstest USING fts4(content TEXT, totalsec TEXT, zdate TEXT); ")
end if

If not db.Error Then
  DB.Commit
else
  MsgBox(Currentmethodname+" Error: " + db.ErrorMessage)
End If

Dim myDate as Xojo.Core.Date = Xojo.Core.Date.Now
Dim GMTZone As New Xojo.Core.TimeZone("GMT")
Dim dule As New Xojo.Core.Date(myDate.SecondsFrom1970, GMTZone)

Dim Result as boolean
// Add data
'DB.SQLExecute("BEGIN TRANSACTION")
dim d as new date
db.SQLExecute("INSERT INTO ftstest (content, totalsec, zdate) VALUES ('"+Code+"', '"+format(dule.SecondsFrom1970,"###")+"', '"+d.SQLDate+"')")
// We record encrypted UUID, SecondsFrom1970 GMT, and SQLDate
Debuglog "Record dule : "+format(dule.SecondsFrom1970,"###")
If not db.Error Then
  Debuglog "Recorded OK"
  Result = True
else
  Debuglog(Currentmethodname+" Error: " + db.ErrorMessage)
End If

Return Result

end if[/code]

I will appreciate any pointers.

are you sure the data connection is PERSISTENT?
on a desktop computer it would be… its open until YOU close it…
I don’t know about XOJO web, but back in the day when I was writing websites with PHP/MySQL , each page had to check the connection, and refresh it if had gone stale.

[quote=270129:@Dave S]are you sure the data connection is PERSISTENT?
on a desktop computer it would be… its open until YOU close it…
I don’t know about XOJO web, but back in the day when I was writing websites with PHP/MySQL , each page had to check the connection, and refresh it if had gone stale.[/quote]

Oh. That could be it. I will experiment some more. Thank you.

Also, check permissions of the enclosing folder. You’ll probably need the executable but set to be able to write to it.

I checked that too. No joy.

chmod 666 means that all users can read and write but cannot execute
chmod 777 allows all actions for all users

perhaps the remote server needs a bit higher authorization?
set it to 777, if that fixes the problem, then revisit the exact level you really need

In desperation I tried my project under Linux Mint. It appears there is an issue specific to Linux.

I also tried the example projects, and they appear to work just fine.

So I guess I have to start back from the working example.

Sorry for the trouble. Thanks.

I was tired yesterday. Today, after porting the SQLite example to Xojo Web, I saw that indeed, I needed to set the enclosing folder of the database as writable. Now my program works as expected.

Thank you Greg.