toufik 2 Posted December 9, 2022 hello every one ; using delphi 10.4.2 i need some help im trying to backup a sqllite database like this : var msg,CommonPath: string; SourceFile: string; BackupFile: string; begin FireTaskList.connected := False; SourceFile := TPath.combine(TPath.GetDocumentsPath,'tasks.s3db');// TPath.GetDocumentsPath +PathDelim+ 'tasks.s3db'; BackupFile := TPath.Combine( TPath.GetSharedPicturesPath, 'MyBackup.s3db'); if not FileExists(SourceFile) then Exit; msg := 'Create a file in the following location ' + sLineBreak+ ExtractFilePath(BackupFile); TDialogService.MessageDialog( msg, TMsgDlgType.mtConfirmation, mbYesNo, TMsgDlgBtn.mbYes, 0, procedure(const AResult: TModalResult) begin if AResult=mrYes then begin try FDSQLiteBackup1.Database := SourceFile; FDSQLiteBackup1.DestDatabase := BackupFile; FDSQLiteBackup1.Backup; ShowMessage( ExtractFileName(BackupFile)+' ...'+'saved' ); except on E: Exception do begin msg := E.ClassName + sLineBreak + E.Message; ShowMessage( msg ); mmo1.text := BackupFile; end; end; end; end ); end; and im keep getting an error message i did set the read and write permissions and i connected the database like this try FireTaskList.Connected := False; FireTaskList.Params.Clear; FireTaskList.LoginPrompt := False; FireTaskList.Params.Values['OpenMode'] :='=ReadWrite'; FireTaskList.Params.DriverID := 'SQLite'; FireTaskList.Params.Values['Database'] := TPath.combine(TPath.GetDocumentsPath,'tasks.s3db'); except on E: EDatabaseError do ShowMessag('cant connect' + E.Message); Share this post Link to post
sjordi 39 Posted December 9, 2022 Do you actually create the "BackupFile"? With its structure (built-in tables)? I think that the file should exist first before being able to open it. Also make sure that you create the file somewhere where you have the right to write (sandboxing), either it the app space or in the public space. Share this post Link to post
programmerdelphi2k 237 Posted December 9, 2022 Quote System.IOUtils.TPath.GetSharedDocumentsPath: NOTE: If the system running your application does not support the requested folder, or if the requested folder does not exist in the system, this function returns an empty string instead FDSQLiteBackup1.Database := 'c:\db.sdb'; FDSQLiteBackup1.DestDatabase := 'c:\db.backup'; FDSQLiteBackup1.DestMode := smCreate; // <--- FDSQLiteBackup1.Backup; Share this post Link to post
toufik 2 Posted December 9, 2022 27 minutes ago, sjordi said: Do you actually create the "BackupFile"? With its structure (built-in tables)? I think that the file should exist first before being able to open it. Also make sure that you create the file somewhere where you have the right to write (sandboxing), either it the app space or in the public space. maybe i wasn't very clear,,,, i want the user to be able to back up the db in any folder i chose too for example : GetSharedPicturesPath . with all its structure and data and restore if he wants too to answer the second question, i create the db on create ,, and filled the table and its structure, the last part i will try it and get back to you soon as possible,,, thanks for taking the time to reply . Share this post Link to post
toufik 2 Posted December 9, 2022 16 minutes ago, programmerdelphi2k said: FDSQLiteBackup1.Database := 'c:\db.sdb'; FDSQLiteBackup1.DestDatabase := 'c:\db.backup'; FDSQLiteBackup1.DestMode := smCreate; // <--- FDSQLiteBackup1.Backup; the error i'm having on android not windows ,windows every thing fine i just can use filecopy to do that ,,thanks for reply Share this post Link to post
programmerdelphi2k 237 Posted December 9, 2022 after Android 11, you can not use all folders, only public or from your app install! Share this post Link to post