📄 frmsqlbatch.pas
字号:
unit frmsqlbatch;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,db,adodb, StdCtrls, ExtCtrls, Grids, ValEdit;
type
Tsqlbatchfrm = class(TForm)
Panel1: TPanel;
CheckBox1: TCheckBox;
Button1: TButton;
Button2: TButton;
Panel2: TPanel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Memo2: TMemo;
Splitter1: TSplitter;
ValueListEditor1: TValueListEditor;
Splitter2: TSplitter;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
sqlbatchfrm: Tsqlbatchfrm;
dbconn:TADOConnection;
implementation
uses unit1;
{$R *.dfm}
procedure Tsqlbatchfrm.FormCreate(Sender: TObject);
begin
dbconn:=unit1.form1.ADOConnection1;
end;
procedure Tsqlbatchfrm.Button1Click(Sender: TObject);
var sqls,tmps:Tstrings;
function decodeparams(ss:Tstrings;ps:integer;qstr:string):boolean;
var tstr:string;
i,j,k,l:integer;
tmpdset:Tadodataset;
begin
if (ps<0) or (ps>=ValueListEditor1.RowCount) then exit;
tstr:= ValueListEditor1.Values[ValueListEditor1.Keys[ps]];
if (trim(tstr)='') or (pos(ValueListEditor1.Keys[ps],qstr)<1) then
begin
ss.Add(qstr);
exit;
end;
if pos('..',tstr)>0 then
begin
tmps.Text:=stringreplace(tstr,'..',#$D#$A,[rfreplaceall]);
if trystrtoint(tmps.Strings[0],k) and trystrtoint(tmps.Strings[1],l) then
begin
for i:=k to l do
decodeparams(ss,ps+1,stringreplace(qstr,ValueListEditor1.Keys[ps],inttostr(i),[rfreplaceall]));
end;
end
else if pos(',',tstr)>0 then
begin
tmps.Text:=stringreplace(tstr,',',#$D#$A,[rfreplaceall]);
for i:=0 to tmps.Count-1 do
decodeparams(ss,ps+1,stringreplace(qstr,ValueListEditor1.Keys[ps],tmps.Strings[i],[rfreplaceall]));
end
else if pos('SELECT',uppercase(tstr))>0 then
begin
tmpdset:=Tadodataset.Create(self);
tmpdset.Connection:=dbconn;
tmpdset.CommandText:= tstr;
try
tmpdset.Active:=true;
if not tmpdset.Eof then
begin
tmpdset.First;
for i:=0 to tmpdset.RecordCount-1 do
begin
decodeparams(ss,ps+1,stringreplace(qstr,ValueListEditor1.Keys[ps],tmpdset.Fields[0].AsString,[rfreplaceall]));
end;
end;
except
end;
tmpdset.Active:=false;
tmpdset.Free;
end;
end;
begin
sqls:=tstringlist.Create;
tmps:=tstringlist.Create;
decodeparams(sqls,1,memo1.Lines.text);
memo2.Lines.Text:=sqls.Text;
sqls.free;
tmps.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -