unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
DB, ADODB, ExtCtrls, DBCtrls, Grids, DBGrids, ComCtrls;
type
Tfrm =
class(TForm)
DataSource: TDataSource;
ADOQuery: TADOQuery;
pnTop: TPanel;
StatusBar: TStatusBar;
DBGrid: TDBGrid;
DBNavigator: TDBNavigator;
Splitter: TSplitter;
ADOConnection: TADOConnection;
btnSQL: TButton;
btnEnde: TButton;
pnInfo: TPanel;
SQLEingabe: TMemo;
Splitter1: TSplitter;
Tabellen: TMemo;
procedure btnEndeClick(Sender: TObject);
procedure btnSQLClick(Sender: TObject);
procedure TabellenDblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
frm: Tfrm;
implementation
{$R *.dfm}
procedure Tfrm.btnEndeClick(Sender: TObject);
begin
ADOQuery.Close;
ADOConnection.Close;
Close;
end;
procedure Tfrm.btnSQLClick(Sender: TObject);
var
slTables : TStringList;
slFields : TStringList;
i : Integer;
k : Integer;
begin
if not ADOConnection.Connected
then begin
if ADOConnection.ConnectionString = '
'
then begin
ADOConnection.ConnectionString := PromptDataSource(
handle,'
');
end;
if ADOConnection.ConnectionString <> '
'
then begin
ADOConnection.Open;
Tabellen.Lines.Clear;
slTables := TStringList.Create;
slFields := TStringList.Create;
ADOConnection.GetTableNames(slTables,false);
for i := 0
to slTables.Count - 1
do begin
Tabellen.Lines.Add(slTables[i]);
ADOConnection.GetFieldNames(slTables[i],slFields);
for k := 0
to slFields.Count - 1
do begin
Tabellen.Lines.Add(Format('
%s',[slFields[k]]));
end;
end;
slTables.Free;
slFields.Free;
end;
end;
if ADOConnection.Connected
then begin
ADOQuery.Close;
ADOQuery.SQL.Clear;
if SQLEingabe.SelLength <> 0
then begin
ADOQuery.SQL.Add(Trim(SQLEingabe.SelText));
end else begin
ADOQuery.SQL.Add(Trim(SQLEingabe.Text));
end;
if Trim(ADOQuery.SQL.Text) <> '
'
then begin
ADOQuery.Open;
end;
end;
end;
procedure Tfrm.TabellenDblClick(Sender: TObject);
begin
if Tabellen.SelText <> '
'
then begin
SQLEingabe.SelText := Tabellen.SelText;
end;
end;
procedure Tfrm.FormCreate(Sender: TObject);
begin
if FileExists(ChangeFileExt(Application.ExeName,'
.sql'))
then begin
SQLEingabe.Lines.LoadFromFile(ChangeFileExt(Application.ExeName,'
.sql'));
end;
end;
procedure Tfrm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
SQLEingabe.Lines.SaveToFile(ChangeFileExt(Application.ExeName,'
.sql'));
end;
end.