SQLite and OSX related query...can't get SQLite to create a database on OSX
My program works fine when launched within Lazarus on Windows and OSX. It manages to create a database and commit entries to it. No problem. But after compiling on OSX and creating an Application Bundle, and even after copying the binary to within the .app file to MyApp.app/Contents/MacOS and then copying it to a new DMG image where I have given the DMG full read/write permissions for all users, when I launch the application it tells me it found the SQLite library OK but it can't create the database.
I have even chmod +rwx MyApp.app and it still won't have it.
I have no idea why. But it works fine when launched within Lazarus on OSX. So it must be a permissions thing somewhere but I am out of ideas. Can anyone help?
The code the triggers the database stuff is :
{$ifdef darwin}
SQLDBLibraryLoaderOSX.ConnectionType:='SQLite3';
if FileExists('/usr/lib/libsqlite3.dylib') then
begin
SQLDBLibraryLoaderOSX.LibraryName := '/usr/lib/libsqlite3.dylib';
SQLDBLibraryLoaderOSX.Enabled := true;
SQLDBLibraryLoaderOSX.LoadLibrary;
// Set the filename of the sqlite database
strFileNameRandomiser := FormatDateTime('YYYY-MM-DD_HH-MM-SS', Now); // use a randomised filename suffix to enable multiple instances
SQLite3Connection1.DatabaseName := 'DBOSX_' + strFileNameRandomiser + '.sqlite';
// Create the database
CreateDatabase(SQLite3Connection1.DatabaseName); // this fails on OSX but not within Lazarus
if SQLIte3Connection1.Connected then lblConnectionStatus.Caption:= 'SQLite3 Database connection active';
end
else
begin
ShowMessage('Cannot create SQLite database. Probably SQLite is not installed on your system (should be /usr/lib/libsqlite3.dylib). Exiting');
abort;
end;
// Create a fresh SQLite database for each instance of the program
procedure TfrmSQLiteDBases.CreateDatabase(DBaseName : string);
begin
SQLite3Connection1.Close; // Ensure the connection is closed when we start
//SQLite3Connection1.Password := txtPass.Text;
try
// Make a new database and add the tables
try
SQLite3Connection1.Open;
SQLTransaction1.Active := true;
// Periodically sort the database out to ensure it stays in tip top shape
// during heavy usage
SQLite3Connection1.ExecuteDirect('PRAGMA auto_vacuum = FULL;');
// .... and so on ...