Topic: Backup record disappear from tablegrid

I have create a simple code that backup and restore the database in a directory (Files).
The sqlite.db thakes a new from with the day and the hour of backup.
like this    sqlite08-07-2016 22-34-31.db
When I restore the selected file all the records from the tablegrid in the restore form disappears.
I can not find the reason.
Any help ?
In the attached file is my software.
Thank you in advance

Post's attachments

Attachment icon Backup.zip 662.02 kb, 490 downloads since 2016-07-08 

Re: Backup record disappear from tablegrid

Hello,


Your application seams to work.


I saved 5 times the database, loaded the last backup, and found 4 available in the Tablegrid (1 less than the last backup which is logical).


My best guess is that either you did not save enough database to have records in theprevious backup, OR you restored the first backup which contains no records :-)


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

3 (edited by v_pozidis 2016-07-09 08:10:59)

Re: Backup record disappear from tablegrid

Hi,  the backup works fine but   when you select a record from the tablegrid and press the restore button the next time you are gonna use the restore form you will see that the tablegrid is empty. I can not understand the reason. Please test it . Thank you for your help.

4 (edited by prahousefamily 2016-07-09 14:11:15)

Re: Backup record disappear from tablegrid

Hi,v_pozidis
I have little project  Backup and Save log to DB For Is Example in  Learn Script My Student
I hope that it would be useful for you ... Thank You Again.

https://i.imgsafe.org/10291af020.png
https://i.imgsafe.org/10292559fc.png
https://i.imgsafe.org/10292eead1.png

var
AppPath: string;
Lines: TStrings;
Line: string;


//restore
procedure Form1_TableGrid1_OnCellDoubleClick (Sender: string; ACol, ARow: Integer);
var
bf : string ;
begin
    CreateDir(AppPath+'DatabaseUserRestore');
    bf := SQLExecute('Select backup_filename From backuplog Where id ='+
    inttostr(Form1.TableGrid1.dbItemID));
    begin
        DecompressFiles(
        AppPath+'DatabaseUserBackup\'+bf,  //From File
        AppPath+'DatabaseUserRestore\');    //To Folder
        ShowMessage('OK Restore File is "'+ 'sqlite.db'+'" From File "'+bf+'"'+
        ' At DatabaseUserRestore') ;
    end;
end;


//reset log
procedure Form1_Button2_OnClick (Sender: string; var Cancel: boolean);
var
backup_file_list : string ;
i,c: integer;
sl: TStringList;
begin
    SQLExecute('Delete From backuplog' );
    backup_file_list := AppPath+'DatabaseUserBackup\'+'backup_file_list.ini';
    Lines := TStringList.Create;
    Lines.Add(
    ReplaceStr(
    GetFilesList(AppPath+'DatabaseUserBackup','*.Zlib')
    ,AppPath+'DatabaseUserBackup\','')
    );
    Lines.SaveToFile(backup_file_list);
    Lines.Free;
    sl := TStringList.Create;
    sl.LoadFromFile(AppPath+'DatabaseUserBackup\'+'backup_file_list.ini') ;
    c := sl.Count - 1;
    for i := 0 to c do
    begin
        SQLExecute(
        'insert into backuplog(backup_filename,backup_datetime) values'+
        '("'+sl[i]+'",'+
        'substr("'+sl[i]+'",10,11)||'+
        'substr("'+sl[i]+'",21,2)||":"||'+
        'substr("'+sl[i]+'",24,2)||":"||'+
        'substr("'+sl[i]+'",27,2)||"."||'+
        'substr("'+sl[i]+'",30,3)'+')');
    end;
    Form1.TableGrid1.dbUpdate ;
    Form1.TableGrid1.BestFitColumns() ;
end;


//backup
procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
stamp_date_time_file : string  ;
begin
    CreateDir(AppPath+'DatabaseUserBackup') ;
    stamp_date_time_file := FormatDateTime('yyyy-mm-dd hh-mm-ss-zzz', now)+'.Zlib' ;
    CopyFile(AppPath+'sqlite.db', AppPath+'DatabaseUserBackup/' + 'sqlite.db');
    CompressFile(AppPath+'DatabaseUserBackup\sqlite.db', AppPath+'DatabaseUserBackup\sqlite.db'+stamp_date_time_file);
    DeleteFile(AppPath+'DatabaseUserBackup\sqlite.db');
    SQLExecute(
    'insert into backuplog(backup_filename,backup_datetime) values'+
    '("sqlite.db'+stamp_date_time_file+'","'+FormatDateTime('yyyy-mm-dd hh:mm:ss.zzz', now)+'")'
    ) ;
    Form1.TableGrid1.dbUpdate ;
    Form1.TableGrid1.BestFitColumns() ;
    ShowMessage('OK Backup Clear! File is "'+ 'sqlite.db'+' '+stamp_date_time_file+'"') ;
end;
begin
    AppPath := ExtractFilePath(Application.ExeName);
    end.
Post's attachments

Attachment icon BackUpLog.zip 6.35 kb, 462 downloads since 2016-07-09 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: Backup record disappear from tablegrid

Thank you for your help.
I will study your script to learn more Pascal.
Regards