Permalink
Browse files

keep connection

  • Loading branch information...
1 parent f5e7197 commit cd7ff0860f9320348e0cc21d4f697e90d0a8a4d7 @stijnsanders committed Nov 5, 2011
Showing with 29 additions and 10 deletions.
  1. +2 −0 SQLiteAdmin/SQLiteAdminMain.dfm
  2. +27 −10 SQLiteAdmin/SQLiteAdminMain.pas
@@ -90,6 +90,7 @@ object formSQLiteAdminMain: TformSQLiteAdminMain
Anchors = [akLeft, akTop, akRight]
TabOrder = 0
Text = 'test.db'
+ OnChange = txtDbPathChange
end
object btnDbBrowse: TButton
Left = 376
@@ -118,6 +119,7 @@ object formSQLiteAdminMain: TformSQLiteAdminMain
Height = 22
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
+ DropDownCount = 25
ItemHeight = 14
TabOrder = 6
OnChange = ComboBox1Change
@@ -4,7 +4,7 @@ interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ComCtrls, ActnList, StdActns, ExtCtrls;
+ Dialogs, StdCtrls, ComCtrls, ActnList, StdActns, ExtCtrls, SQLiteData;
type
TformSQLiteAdminMain = class(TForm)
@@ -34,10 +34,12 @@ TformSQLiteAdminMain = class(TForm)
procedure actCopyRowExecute(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure actNextRSExecute(Sender: TObject);
+ procedure txtDbPathChange(Sender: TObject);
private
- { Private declarations }
- public
- { Public declarations }
+ Fdb: TSQLiteConnection;
+ protected
+ procedure DoCreate; override;
+ procedure DoDestroy; override;
end;
var
@@ -46,13 +48,24 @@ TformSQLiteAdminMain = class(TForm)
implementation
uses
- SQLiteData, Clipbrd;
+ Clipbrd;
{$R *.dfm}
+procedure TformSQLiteAdminMain.DoCreate;
+begin
+ inherited;
+ Fdb:=nil;
+end;
+
+procedure TformSQLiteAdminMain.DoDestroy;
+begin
+ inherited;
+ FreeAndNil(Fdb);
+end;
+
procedure TformSQLiteAdminMain.actRunExecute(Sender: TObject);
var
- db:TSQLiteConnection;
st:TSQLiteStatement;
b:boolean;
i,j,ref1,ref2:integer;
@@ -63,7 +76,7 @@ procedure TformSQLiteAdminMain.actRunExecute(Sender: TObject);
Panel1.Visible:=false;
for i:=0 to ComboBox1.Items.Count-1 do ComboBox1.Items.Objects[i].Free;
ComboBox1.Items.Clear;
- db:=TSQLiteConnection.Create(txtDbPath.Text);
+ if Fdb=nil then Fdb:=TSQLiteConnection.Create(txtDbPath.Text);
Screen.Cursor:=crHourGlass;
try
if txtCommand.SelLength=0 then
@@ -82,7 +95,7 @@ procedure TformSQLiteAdminMain.actRunExecute(Sender: TObject);
while s<>'' do
begin
i:=1;
- st:=TSQLiteStatement.Create(db,UTF8Encode(s),i);
+ st:=TSQLiteStatement.Create(Fdb,UTF8Encode(s),i);
try
ref1:=ref2;
inc(ref2,i);
@@ -150,13 +163,12 @@ procedure TformSQLiteAdminMain.actRunExecute(Sender: TObject);
except
txtCommand.SelLength:=0;
txtCommand.SelStart:=ref1;
- txtCommand.SelLength:=ref2-ref1;
+ txtCommand.SelLength:=ref2-ref1-1;
txtCommand.SetFocus;
raise;
end;
finally
Screen.Cursor:=crDefault;
- db.Free;
if ComboBox1.Items.Count<>0 then
begin
ComboBox1.ItemIndex:=0;
@@ -201,4 +213,9 @@ procedure TformSQLiteAdminMain.actNextRSExecute(Sender: TObject);
(ComboBox1.Items.Objects[ComboBox1.ItemIndex] as TListView).BringToFront;
end;
+procedure TformSQLiteAdminMain.txtDbPathChange(Sender: TObject);
+begin
+ FreeAndNil(Fdb);
+end;
+
end.

0 comments on commit cd7ff08

Please sign in to comment.