[solved] SQLite DB on OSX cannot be created lazarus / 16-Databases ---------------------------------------------------------------------- Gizmo · 2018-01-08 10:09 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 : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  {$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 programprocedure 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 ... ---------------------------------------------------------------------- molly · 2018-01-08 10:27 The only thing that i'm able to deduct from docs is that here it is written how to obtain the path to the application bundle. Assuming that you should create your database there, you would have to make sure that it is the directory where sqlite tries to create the database. Not providing a path at all could end up in nowhere's land (e.g. a directory where your application does not have read/write access) edit: In case the application bundle is not the path to store things then use GetUserDir or GetAppConfigDir (depending on the needs of your program/use). Another thread with information on bundles and directories (with links) on MacOS. ---------------------------------------------------------------------- Gizmo · 2018-01-08 11:10 Molly...you saved me again!! I did think it would be a path related issue but hadn't considered than a .app file is not really the place where a new SQLite db can be written into! So yes, I have used : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SafePlaceForDB := GetUserDir;SQLite3Connection1.DatabaseName := SafePlaceForDB + 'DBOSX_' + strFileNameRandomiser + '.sqlite';  and now it just gets thrown in /Users/Username/. The program launches OK, created the DB, and then deletes it when the program closes. Superb. Might look at the other way and do it more cleanly soon but for now, that fixes my issue. Life saver Molly. Thanks