home *** CD-ROM | disk | FTP | other *** search
- unit Dbsql;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, DbForm, Dialogs, StdCtrls, DB, DBTables, DbSQLVew;
-
- type
- TSQLForm = class(TDbForm)
- SQLText: TMemo;
- SQLQuery: TQuery;
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormActivate(Sender: TObject);
- procedure FormDeactivate(Sender: TObject);
- private
- FSQLView: TSQLViewForm;
- public
- constructor Create (AOwner: TComponent; Db: TDatabase);
- procedure ExecuteSQL;
- property Query: TQuery read SQLQuery;
- property View: TSQLViewForm read FSQLView write FSQLView;
- end;
-
- var
- SQLForm: TSQLForm;
-
- implementation
-
- {$R *.DFM}
-
- uses DbMain;
-
- constructor TSQLForm.Create (AOwner: TComponent; Db: TDatabase);
- begin
- inherited Create (AOwner);
- Database := Db;
- Caption := Format ('SQL Editor - Database %s', [Db.DatabaseName]);
- SQLQuery.DatabaseName := Db.DatabaseName;
- Show
- end;
-
- procedure TSQLForm.ExecuteSQL;
- begin
- if Assigned (FSQLView) then View.Free;
-
- SQLQuery.SQL := SQLText.Lines;
-
- try
- DbMainForm.ShowAsHint ('');
- SQLQuery.Open;
- except
- on EDbEngineError do raise { Since is subclass of EDatabase error };
- on EDatabaseError do
- begin
- DbMainForm.ShowAsHint ('Executed successfully');
- Abort { This must be a non-cursor SQL query? };
- end;
- end;
-
- View := TSQLViewForm.Create (Application, Self);
- end;
-
- procedure TSQLForm.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if Assigned (FSQLView) then View.Free;
- DbMainForm.FormCloseActive (Sender, Action)
- end;
-
- procedure TSQLForm.FormActivate(Sender: TObject);
- begin
- DbMainForm.SetActiveForm (nil, nil)
- end;
-
- procedure TSQLForm.FormDeactivate(Sender: TObject);
- begin
- DbMainForm.ShowAsHint ('');
- end;
-
- end.
-