Robert Gilland 5 Posted September 14, 2023 I am having real trouble trying to create an SQLLite Database at runtime in Android. Does anyone know how to do this? Share this post Link to post
sjordi 39 Posted September 14, 2023 Do you have permissions to write the DB? Did you try to write a test file like "test.txt"? If it doesn't work, you don't have write permissions. Otherwise please provide the error message (if any) you get when creating the DB 1 Share this post Link to post
Robert Gilland 5 Posted September 14, 2023 Victory: I created an empty file fist by this method and then all good: lsDBPath := DBPath; if( not FileExists(lsDBPAth))then begin lhandle := System.SysUtils.FileCreate(lsDBPath); System.SysUtils.FileClose(lhandle); end; cnctnDB.Params.Values['Database'] := lsDBPath; cnctnDB.Params.Values['SQLiteAdvanced'] := 'page_size=4096'; cnctnDB.Params.Values['OpenMode'] := 'ReadWrite'; Share this post Link to post
Patrick PREMARTIN 69 Posted September 15, 2023 Hi @Robert Gilland Can you give us the code you used previously ? It's very strange you need to create a file before using it as a SQLite database. I've never needed to do that. Perhaps you need some permission about external storage or use a not authorized folder ? Share this post Link to post
Robert Gilland 5 Posted September 19, 2023 Previous code was procedure Tdtmdl.CheckDatabaseExists; var EmptyDB: string; begin if not FileExists(DBPath) then begin EmptyDB := DocumentsFolderPath + 'empty.sqlite'; TFile.Copy(EmptyDB, DBPath); end; end; procedure Tdtmdl.ConfigureDatabaseAndTable; var SQL: string; SL: TStringList; begin // if fActiveApp = TActiveApp.aaNone then exit; cnctnDB.Params.Values['Database'] := DBPath; CheckDatabaseExists; try cnctnDB.Connected := true; except on e:Exception do begin end; end; Share this post Link to post
Hans J. Ellingsgaard 21 Posted September 21, 2023 On 9/20/2023 at 12:33 AM, Robert Gilland said: DocumentsFolderPath + 'empty.sqlite Is there a path delimiter after the DocumentFolderPath? Share this post Link to post