Copying a SQLITE table from one database to another database
-
- Posts: 8
- Joined: Wed 06 Nov 2013 13:41
Copying a SQLITE table from one database to another database
I want to copy a SQLITE table from one database to another database using a TLiteQuery. What is the syntax for the SQL? Thanks.
Re: Copying a SQLITE table from one database to another database
Hello,
Below is a sample of copying data from one database to another:
Below is a sample of copying data from one database to another:
Code: Select all
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, LiteAccess;
var
LiteConnection: TLiteConnection;
LiteQuery: TLiteQuery;
begin
LiteConnection := TLiteConnection.Create(nil);
try
LiteConnection.Options.ForceCreateDatabase := True;
LiteConnection.Database := 'd:\src.db3';
LiteConnection.Connect;
LiteConnection.ExecSQL('create table t_test (f_id integer)');
LiteConnection.ExecSQL('insert into t_test values(1),(2),(3),(4),(5)');
LiteConnection.Disconnect;
LiteConnection.Database := 'd:\dst.db3';
LiteConnection.Connect;
LiteConnection.ExecSQL('create table t_test (f_id integer)');
LiteConnection.ExecSQL('attach "d:\src.db3" as source');
LiteConnection.ExecSQL('insert into main.t_test select * from source.t_test');
LiteQuery := TLiteQuery.Create(nil);
try
LiteQuery.Connection := LiteConnection;
LiteQuery.SQL.Text := 'select * from main.t_test';
LiteQuery.Open;
while not LiteQuery.Eof do begin
WriteLn(LiteQuery.FieldByName('f_id').AsString);
LiteQuery.Next;
end;
finally
LiteQuery.Free;
end;
finally
LiteConnection.Free;
readln;
end;
end.
-
- Posts: 8
- Joined: Wed 06 Nov 2013 13:41
Re: Copying a SQLITE table from one database to another database
Thanks for the very quick response. This is just what I needed.
Re: Copying a SQLITE table from one database to another database
You are welcome. Feel free to contact us if you have any further questions.