Recent

Author Topic: Copying an in use SQLite Database File  (Read 27150 times)

mrmikehicks

  • New Member
  • *
  • Posts: 39
Re: Copying an in use SQLite Database File
« Reply #15 on: March 16, 2010, 02:01:34 am »
davesimplewear, don't know why your happy, does this code actually work on your system? I can't get it to read the database file with any of several copy methods (except the dos cmd prompt method)

Had a thought that I want to investigate: The laz fpc sqlite3 dataset component relies on the same sqlite3.dll that is placed in the path. The sqlite3.dll has a funcion call for a command to backup the database. The syntax for the command line version using sqlite3.dll is:

.backup ?DB? FILE      Backup DB (default "main") to FILE

this cmd works like a charm, but I don't know how to get to it to execute the command. I was looking at the dataset.executedirect()  syntax to see if it will let me get to the inner calls of the sqlite3.dll  (which it is already using)
anyway will let all know what happens.
     Mike

davesimplewear

  • Sr. Member
  • ****
  • Posts: 321
    • Davids Freeware
Re: Copying an in use SQLite Database File
« Reply #16 on: March 16, 2010, 03:30:12 am »
mrmikehicks, yes it worked ok for me once I changed to dbsrc:=extractfilepath(application.exename)+'database\sqlite_test.db;
dbres:=extractfilepath(application.exename)+db_backup\sqlite_test.db;
it compiled, ran and saved to the directory. Maybe by trying to save sqlite3.filename as a parameter it didn't work.

Regards
Dave
All things considered insanity seems the best option

mrmikehicks

  • New Member
  • *
  • Posts: 39
Re: Copying an in use SQLite Database File
« Reply #17 on: March 16, 2010, 03:56:52 am »
Davesimplewear, that was the original problem, it will copy correctly unless the file you're trying to copy is the database file that the dataset is using. I don't understand how changing the filename from sqlite3_test.db to sqlite_test.db (which doesn't exist) can work for you.


mrmikehicks

  • New Member
  • *
  • Posts: 39
Re: Copying an in use SQLite Database File
« Reply #18 on: March 16, 2010, 04:12:59 am »
Problem solved, you were right davesimplewear,  I had the wrong directory structure, and in this case I was also trying to copy to a nonexistant directory ('db_backup' didn't exist') so created the directory and it actually worked for me:

procedure TForm1.FileCopy(const FSrc, FDst: string);
var
  sStream,
  dStream: TFileStream;
begin
  sStream := TFileStream.Create(FSrc, fmOpenRead);
  try
    dStream := TFileStream.Create(FDst, fmCreate);
    try
      {Forget about block reads and writes, just copy
       the whole darn thing.}
      dStream.CopyFrom(sStream, 0);
    finally
      dStream.Free;
    end;
  finally
    sStream.Free;
  end;
end;

procedure TForm1.btn_cpy_dbClick(Sender: TObject);
begin
    form1.Sqlite3Dataset1.Active:=false;
    dbsource := extractfilepath(application.exename)+'database\sqlite3_test.db';
    dbdest := extractfilepath(application.exename)+'db_backup\sqlite3_test.db';
    form1.FileCopy(dbsource,dbdest);
end;

thanks to all who listen to all this and responded.
     mike

davesimplewear

  • Sr. Member
  • ****
  • Posts: 321
    • Davids Freeware
Re: Copying an in use SQLite Database File
« Reply #19 on: March 16, 2010, 05:16:22 am »
mrmikehicks, I was only using psuedo code in the reply from memory, just check the converted project and .pas file for what I was doing, good to see it worked for you.

Regards
Dave
All things considered insanity seems the best option

mrmikehicks

  • New Member
  • *
  • Posts: 39
Re: Copying an in use SQLite Database File
« Reply #20 on: March 16, 2010, 05:21:08 am »
Thanks Dave. I'm glad I can put this one to bed finally.
     Mike

 

TinyPortal © 2005-2018