home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk15 / dbtools.pak / DBSQL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-08-24  |  1.8 KB  |  81 lines

  1. unit Dbsql;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, DbForm, Dialogs, StdCtrls, DB, DBTables, DbSQLVew;
  8.  
  9. type
  10.   TSQLForm = class(TDbForm)
  11.     SQLText: TMemo;
  12.     SQLQuery: TQuery;
  13.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  14.     procedure FormActivate(Sender: TObject);
  15.     procedure FormDeactivate(Sender: TObject);
  16.   private
  17.     FSQLView: TSQLViewForm;
  18.   public
  19.     constructor Create (AOwner: TComponent; Db: TDatabase);
  20.     procedure ExecuteSQL;
  21.     property Query: TQuery read SQLQuery;
  22.     property View: TSQLViewForm read FSQLView write FSQLView;
  23.   end;
  24.  
  25. var
  26.   SQLForm: TSQLForm;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. uses DbMain;
  33.  
  34. constructor TSQLForm.Create (AOwner: TComponent; Db: TDatabase);
  35. begin
  36.   inherited Create (AOwner);
  37.   Database := Db;
  38.   Caption := Format ('SQL Editor - Database %s', [Db.DatabaseName]);
  39.   SQLQuery.DatabaseName := Db.DatabaseName;
  40.   Show
  41. end;
  42.  
  43. procedure TSQLForm.ExecuteSQL;
  44. begin
  45.   if Assigned (FSQLView) then View.Free;
  46.  
  47.   SQLQuery.SQL := SQLText.Lines;
  48.  
  49.   try
  50.      DbMainForm.ShowAsHint ('');
  51.      SQLQuery.Open;
  52.   except
  53.      on EDbEngineError do raise { Since is subclass of EDatabase error };
  54.      on EDatabaseError do
  55.      begin
  56.        DbMainForm.ShowAsHint ('Executed successfully');
  57.        Abort { This must be a non-cursor SQL query? };
  58.      end;
  59.   end;
  60.  
  61.   View := TSQLViewForm.Create (Application, Self);
  62. end;
  63.  
  64. procedure TSQLForm.FormClose(Sender: TObject; var Action: TCloseAction);
  65. begin
  66.   if Assigned (FSQLView) then View.Free;
  67.   DbMainForm.FormCloseActive (Sender, Action)
  68. end;
  69.  
  70. procedure TSQLForm.FormActivate(Sender: TObject);
  71. begin
  72.   DbMainForm.SetActiveForm (nil, nil)
  73. end;
  74.  
  75. procedure TSQLForm.FormDeactivate(Sender: TObject);
  76. begin
  77.   DbMainForm.ShowAsHint ('');
  78. end;
  79.  
  80. end.
  81.