Преглед изворни кода

Fixing db Info refresh bug, closing database after exiting query window
modified: TurboBird.lpi
modified: TurboBird.lpr
modified: dbinfo.pas
modified: main.pas
modified: querywindow.pas
modified: systables.pas

motaz пре 12 година
родитељ
комит
b6130b1ec3
6 измењених фајлова са 211 додато и 155 уклоњено
  1. 72 72
      TurboBird.lpi
  2. 2 2
      TurboBird.lpr
  3. 64 2
      dbinfo.pas
  4. 43 71
      main.pas
  5. 18 3
      querywindow.pas
  6. 12 5
      systables.pas

+ 72 - 72
TurboBird.lpi

@@ -62,8 +62,8 @@
         <UnitName Value="TurboBird"/>
         <EditorIndex Value="0"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="9"/>
-        <CursorPos X="8" Y="16"/>
+        <TopLine Value="10"/>
+        <CursorPos X="33" Y="29"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
       </Unit0>
@@ -76,8 +76,8 @@
         <UnitName Value="main"/>
         <EditorIndex Value="7"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1322"/>
-        <CursorPos X="3" Y="1325"/>
+        <TopLine Value="408"/>
+        <CursorPos X="24" Y="436"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -120,16 +120,15 @@
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="QueryWindow"/>
-        <IsVisibleTab Value="True"/>
         <EditorIndex Value="1"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1398"/>
-        <CursorPos X="3" Y="1425"/>
-        <FoldState Value=" T3rY0j$"/>
+        <TopLine Value="1116"/>
+        <CursorPos X="3" Y="1119"/>
+        <FoldState Value=" T3ra0j("/>
         <UsageCount Value="200"/>
         <Bookmarks Count="2">
-          <Item0 X="3" Y="626" ID="0"/>
-          <Item1 X="3" Y="1430" ID="1"/>
+          <Item0 X="3" Y="628" ID="0"/>
+          <Item1 X="3" Y="1445" ID="1"/>
         </Bookmarks>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -210,7 +209,7 @@
         <UnitName Value="NewTable"/>
         <EditorIndex Value="6"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="113"/>
+        <TopLine Value="183"/>
         <CursorPos X="56" Y="215"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
@@ -473,8 +472,8 @@
         <UnitName Value="SysTables"/>
         <EditorIndex Value="3"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="610"/>
-        <CursorPos X="32" Y="638"/>
+        <TopLine Value="725"/>
+        <CursorPos X="18" Y="749"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -644,7 +643,7 @@
         <UnitName Value="BackupRestore"/>
         <EditorIndex Value="9"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="105"/>
+        <TopLine Value="1"/>
         <CursorPos X="22" Y="55"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
@@ -714,9 +713,9 @@
         <UnitName Value="CreateUser"/>
         <EditorIndex Value="2"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="3"/>
+        <TopLine Value="26"/>
         <CursorPos X="24" Y="12"/>
-        <UsageCount Value="191"/>
+        <UsageCount Value="192"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit68>
@@ -731,7 +730,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="3"/>
         <CursorPos X="88" Y="14"/>
-        <UsageCount Value="190"/>
+        <UsageCount Value="191"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit69>
@@ -744,9 +743,9 @@
         <UnitName Value="PermissionManage"/>
         <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="274"/>
+        <TopLine Value="432"/>
         <CursorPos X="25" Y="289"/>
-        <UsageCount Value="188"/>
+        <UsageCount Value="189"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit70>
@@ -761,7 +760,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="56"/>
         <CursorPos X="20" Y="89"/>
-        <UsageCount Value="173"/>
+        <UsageCount Value="174"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit71>
@@ -789,7 +788,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="51" Y="14"/>
-        <UsageCount Value="144"/>
+        <UsageCount Value="145"/>
       </Unit74>
       <Unit75>
         <Filename Value="/usr/lib/lazarus/0.9.30/lcl/comctrls.pp"/>
@@ -979,11 +978,12 @@
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="dbInfo"/>
+        <IsVisibleTab Value="True"/>
         <EditorIndex Value="8"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="112"/>
+        <TopLine Value="64"/>
+        <CursorPos X="16" Y="66"/>
+        <UsageCount Value="113"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit98>
@@ -1019,9 +1019,9 @@
         <UnitName Value="Comparison"/>
         <EditorIndex Value="4"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="244"/>
+        <TopLine Value="1"/>
         <CursorPos X="15" Y="255"/>
-        <UsageCount Value="99"/>
+        <UsageCount Value="100"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit102>
@@ -1057,7 +1057,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="45"/>
+        <UsageCount Value="46"/>
       </Unit106>
       <Unit107>
         <Filename Value="../../../lazarus/lcl/interfaces/win32/win32object.inc"/>
@@ -1093,123 +1093,123 @@
     <JumpHistory Count="30" HistoryIndex="29">
       <Position1>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="1434" Column="32" TopLine="1417"/>
+        <Caret Line="1404" Column="21" TopLine="1310"/>
       </Position1>
       <Position2>
-        <Filename Value="tablemanage.pas"/>
-        <Caret Line="310" Column="39" TopLine="304"/>
+        <Filename Value="querywindow.pas"/>
+        <Caret Line="1401" Column="3" TopLine="1398"/>
       </Position2>
       <Position3>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="823" Column="7" TopLine="646"/>
+        <Caret Line="242" Column="32" TopLine="232"/>
       </Position3>
       <Position4>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="1437" Column="18" TopLine="1423"/>
+        <Caret Line="679" Column="74" TopLine="664"/>
       </Position4>
       <Position5>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="234" Column="3" TopLine="231"/>
+        <Caret Line="1429" Column="3" TopLine="1427"/>
       </Position5>
       <Position6>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="196" Column="3" TopLine="194"/>
+        <Caret Line="803" Column="11" TopLine="649"/>
       </Position6>
       <Position7>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="19" Column="7" TopLine="23"/>
+        <Caret Line="1418" Column="25" TopLine="1373"/>
       </Position7>
       <Position8>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="666" Column="13" TopLine="668"/>
+        <Caret Line="761" Column="45" TopLine="742"/>
       </Position8>
       <Position9>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="686" Column="14" TopLine="668"/>
+        <Caret Line="237" Column="10" TopLine="232"/>
       </Position9>
       <Position10>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="646" Column="1" TopLine="617"/>
+        <Caret Line="615" Column="54" TopLine="600"/>
       </Position10>
       <Position11>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="626" Column="3" TopLine="617"/>
+        <Caret Line="1435" Column="17" TopLine="1424"/>
       </Position11>
       <Position12>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="1426" Column="3" TopLine="1397"/>
+        <Caret Line="687" Column="76" TopLine="661"/>
       </Position12>
       <Position13>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="626" Column="3" TopLine="619"/>
+        <Caret Line="1447" Column="37" TopLine="1427"/>
       </Position13>
       <Position14>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="953" Column="3" TopLine="966"/>
+        <Caret Line="633" Column="30" TopLine="615"/>
       </Position14>
       <Position15>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="639" Column="62" TopLine="622"/>
+        <Caret Line="418" Column="3" TopLine="416"/>
       </Position15>
       <Position16>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="1404" Column="21" TopLine="1310"/>
+        <Caret Line="346" Column="50" TopLine="72"/>
       </Position16>
       <Position17>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="1401" Column="3" TopLine="1398"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="1" Column="1" TopLine="41"/>
       </Position17>
       <Position18>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="242" Column="32" TopLine="232"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="64" Column="21" TopLine="41"/>
       </Position18>
       <Position19>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="679" Column="74" TopLine="664"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="421" Column="3" TopLine="408"/>
       </Position19>
       <Position20>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="1429" Column="3" TopLine="1427"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="689" Column="3" TopLine="684"/>
       </Position20>
       <Position21>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="803" Column="11" TopLine="649"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="104" Column="25" TopLine="99"/>
       </Position21>
       <Position22>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="1418" Column="25" TopLine="1373"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="64" Column="21" TopLine="41"/>
       </Position22>
       <Position23>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="761" Column="45" TopLine="742"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="486" Column="70" TopLine="469"/>
       </Position23>
       <Position24>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="237" Column="10" TopLine="232"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="426" Column="65" TopLine="409"/>
       </Position24>
       <Position25>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="615" Column="54" TopLine="600"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="736" Column="25" TopLine="705"/>
       </Position25>
       <Position26>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="1435" Column="17" TopLine="1424"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="64" Column="21" TopLine="41"/>
       </Position26>
       <Position27>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="687" Column="76" TopLine="661"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="43" Column="8" TopLine="33"/>
       </Position27>
       <Position28>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="1447" Column="37" TopLine="1427"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="81" Column="1" TopLine="73"/>
       </Position28>
       <Position29>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="633" Column="30" TopLine="615"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="56" Column="21" TopLine="24"/>
       </Position29>
       <Position30>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="418" Column="3" TopLine="416"/>
+        <Filename Value="dbinfo.pas"/>
+        <Caret Line="129" Column="1" TopLine="99"/>
       </Position30>
     </JumpHistory>
   </ProjectOptions>

+ 2 - 2
TurboBird.lpr

@@ -2,7 +2,7 @@
 {  TurboBird: FireBird database administration and management tool          }
 {  Developed by: Motaz Abdel Azeem http://code.sd/                          }
 {  Start development :  5.Dec.2009                                          }
-{  Last updated      : 29.Dec.2012                                          }
+{  Last updated      :  2.Jan.2013                                          }
 {  License           : GPL for GUI, LGPL for Units                          }
 {***************************************************************************}
 
@@ -26,7 +26,7 @@ uses
 
 const
   Version = '0.9.7';
-  VersionDate = '2010 - Dec 2012';
+  VersionDate = '2010 - Jan 2013';
 {$IFDEF Unix}
 {$DEFINE extdecl:=cdecl}
     fbclib = 'libfbclient.' + sharedsuffix;

+ 64 - 2
dbinfo.pas

@@ -38,7 +38,9 @@ type
     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
   private
     { private declarations }
+    fdbIndex: Integer;
   public
+    procedure Init(dbIndex: Integer);
     { public declarations }
   end; 
 
@@ -51,7 +53,7 @@ implementation
 
 { TfmDBInfo }
 
-uses Main;
+uses Main, SysTables;
 
 procedure TfmDBInfo.bbCloseClick(Sender: TObject);
 begin
@@ -61,7 +63,7 @@ end;
 
 procedure TfmDBInfo.bbRefreshClick(Sender: TObject);
 begin
-  fmMain.lmDBIndoClick(nil);
+  Init(fdbIndex);
 end;
 
 procedure TfmDBInfo.FormClose(Sender: TObject; var CloseAction: TCloseAction);
@@ -69,6 +71,66 @@ begin
   CloseAction:= caFree;
 end;
 
+procedure TfmDBInfo.Init(dbIndex: Integer);
+var
+  dbName, CreationDate, ACharSet: string;
+  MajorVer, MinorVer, Pages, PageSize: Integer;
+  ProcessList: TStringList;
+  dbSize: Double;
+  AType: string;
+  ServerTime: string;
+  ErrorMsg: string;
+begin
+  fdbIndex:= dbIndex;
+  ProcessList:= TStringList.Create;
+
+  // Read database info
+  if dmSysTables.GetDatabaseInfo(dbIndex, dbName, ACharSet, CreationDate, ServerTime,
+    MajorVer, MinorVer, Pages, PageSize, ProcessList, ErrorMsg) then
+  begin
+    edName.Text:= dbName;
+    edODSVer.Text:= IntToStr(MajorVer) + '.' + IntToStr(MinorVer);
+    edCharset.Text:= ACharSet;
+    edCreationDate.Text:= CreationDate;
+    edPageSize.Text:= IntToStr(PageSize);
+    edConnections.Text:= IntToStr(ProcessList.Count);
+    dbSize:= Pages * PageSize;
+
+    // Display database size in readable format
+    if dbSize > 1000000000 then
+    begin
+      dbSize:= ((dbSize / 1024) / 1024) / 1024;
+      AType:= 'Giga bytes';
+    end
+    else
+    if dbSize > 1000000 then
+    begin
+      dbSize:= ((dbSize / 1024) / 1024);
+      AType:= 'Mega bytes';
+    end
+    else
+    if dbSize > 1000 then
+    begin
+      dbSize:= (dbSize / 1024);
+      AType:= 'Kilo bytes';
+    end
+    else
+    begin
+      AType:= 'Bytes';
+    end;
+
+    edDBSize.Text:= Format('%3.1n %s', [dbSize, AType]);
+    fmDBInfo.edServerTime.Text:= ServerTime;
+    meClients.Lines.Text:= ProcessList.Text;
+    meClients.Lines.Insert(0, '');
+    ProcessList.Free;
+    Show;
+  end
+  else
+    ShowMessage('Unable to get database information' + #10 + ErrorMsg);
+end;
+
+
 
 end.
 

+ 43 - 71
main.pas

@@ -408,81 +408,35 @@ end;
 
 procedure TfmMain.lmDBIndoClick(Sender: TObject);
 var
-  dbName, CreationDate, ACharSet: string;
-  MajorVer, MinorVer, Pages, PageSize: Integer;
-  ProcessList: TStringList;
-  dbSize: Double;
-  AType: string;
   ATab: TTabSheet;
   Title: string;
   dbIndex: Integer;
-  ServerTime: string;
 begin
-  ProcessList:= TStringList.Create;
-  dbIndex:= tvMain.Selected.OverlayIndex;
   Title:= 'Database information for: ' + tvMain.Selected.Text;
-  if dmSysTables.GetDatabaseInfo(dbIndex, dbName, ACharSet, CreationDate, ServerTime,
-    MajorVer, MinorVer, Pages, PageSize, ProcessList) then
-  with fmDBInfo do
-  begin
-    fmDBInfo:= FindCustomForm(Title, TfmDBInfo) as TfmDBInfo;
-
-    if fmDBInfo = nil then
-    begin
-      fmDBInfo:= TfmDBInfo.Create(Application);
-      ATab:= TTabSheet.Create(nil);
-      ATab.Parent:= PageControl1;
-      fmDBInfo.Parent:= ATab;
-      fmDBInfo.Left:= 0;
-      fmDBInfo.Top:= 0;
-      fmDBInfo.BorderStyle:= bsNone;
-      fmDBInfo.Align:= alClient;
-      Caption:= Title;
-    end
-    else
-      ATab:= fmDBInfo.Parent as TTabSheet;
+  dbIndex:= tvMain.Selected.OverlayIndex;
 
-    PageControl1.ActivePage:= ATab;
-    ATab.Tag:= dbIndex;
-    ATab.Caption:= Title;
-    edName.Text:= dbName;
-    edODSVer.Text:= IntToStr(MajorVer) + '.' + IntToStr(MinorVer);
-    edCharset.Text:= ACharSet;
-    edCreationDate.Text:= CreationDate;
-    edPageSize.Text:= IntToStr(PageSize);
-    edConnections.Text:= IntToStr(ProcessList.Count);
-    dbSize:= Pages * PageSize;
-    if dbSize > 1000000000 then
-    begin
-      dbSize:= ((dbSize / 1024) / 1024) / 1024;
-      AType:= 'Giga bytes';
-    end
-    else
-    if dbSize > 1000000 then
-    begin
-      dbSize:= ((dbSize / 1024) / 1024);
-      AType:= 'Mega bytes';
-    end
-    else
-    if dbSize > 1000 then
-    begin
-      dbSize:= (dbSize / 1024);
-      AType:= 'Kilo bytes';
-    end
-    else
-    begin
-      AType:= 'Bytes';
-    end;
+  fmDBInfo:= FindCustomForm(Title, TfmDBInfo) as TfmDBInfo;
 
-    edDBSize.Text:= Format('%3.1n %s', [dbSize, AType]);
-    fmDBInfo.edServerTime.Text:= ServerTime;
-    meClients.Lines.Text:= ProcessList.Text;
-    meClients.Lines.Insert(0, '');
-    ProcessList.Free;
-    Show;
+  if fmDBInfo = nil then
+  begin
+    fmDBInfo:= TfmDBInfo.Create(Application);
+    ATab:= TTabSheet.Create(nil);
+    ATab.Parent:= PageControl1;
+    fmDBInfo.Parent:= ATab;
+    fmDBInfo.Left:= 0;
+    fmDBInfo.Top:= 0;
+    fmDBInfo.BorderStyle:= bsNone;
+    fmDBInfo.Align:= alClient;
+    Caption:= Title;
   end
   else
-    ShowMessage('Unable to get database information');
+    ATab:= fmDBInfo.Parent as TTabSheet;
+
+  PageControl1.ActivePage:= ATab;
+  ATab.Tag:= dbIndex;
+  ATab.Caption:= Title;
+
+  fmDBInfo.Init(dbIndex);
 end;
 
 procedure TfmMain.lmDisconnectClick(Sender: TObject);
@@ -1266,6 +1220,8 @@ begin
   fmNewGen.Init(DatabaseIndex);
 end;
 
+(*  Get server name from database string  *)
+
 function TfmMain.GetServerName(DBName: string): string;
 begin
   if Pos(':', DBName) > 2 then
@@ -1274,6 +1230,9 @@ begin
     Result:= 'localhost';
 end;
 
+
+(* Search and get server node in tree view *)
+
 function TfmMain.GetServerNameNode(ServerName: string): TTreeNode;
 var
   i: Integer;
@@ -1368,6 +1327,9 @@ begin
   end;
 end;
 
+
+(* Insert SQL query into database history file *)
+
 function TfmMain.AddToSQLHistory(DatabaseTitle: string; SQLType, SQLStatement: string): Boolean;
 begin
   try
@@ -1412,6 +1374,9 @@ begin
   end;
 end;
 
+
+(* Open SQL history file for current database *)
+
 function TfmMain.OpenSQLHistory(DatabaseTitle: string): Boolean;
 var
   AFileName: string;
@@ -1464,6 +1429,9 @@ begin
   end;
 end;
 
+
+(* Get input parameters from stored procedure body *)
+
 function TfmMain.RetreiveInputParamFromSP(Body: string): string;
 var
   i: Integer;
@@ -1522,9 +1490,6 @@ begin
   dbIndex:= SelNode.Parent.OverlayIndex;
   Rec:= RegisteredDatabases[dbIndex];
 
-{  fmNewTable.Init(dbIndex);
-  fmNewTable.ShowModal;}
-
   Title:= SelNode.Parent.Text + ': New Table';
 
   Form:= FindCustomForm(Title, TfmNewTable) as TfmNewTable;
@@ -2486,6 +2451,7 @@ begin
     SQLQuery1.Open;
     FirstOutput:= False;
 
+    // Get procedure parameters
       while not SQLQuery1.EOF do
       begin
         ParamName:= Trim(SQLQuery1.FieldByName('RDB$Parameter_Name').AsString);
@@ -2518,7 +2484,7 @@ begin
 
     SQLQuery1.Close;
 
-    // Procedure body
+    // Get Procedure body
     SQLQuery1.SQL.Text:= 'SELECT * FROM rdb$procedures where rdb$Procedure_name =  ''' + AProcName + '''';
     SQLQuery1.Open;
     SPOwner:= Trim(SQLQuery1.FieldByName('rdb$Owner_Name').AsString);
@@ -2631,6 +2597,8 @@ begin
   AQuery.Open;
   Result:= AQuery.FieldCount > 0;
   FieldsList.Clear;
+
+  // Get index field names
   if Result then
   while not AQuery.EOF do
   begin
@@ -2715,7 +2683,11 @@ var
 begin
   Rec:= RegisteredDatabases[DatabaseIndex];
   ACaption:= Rec.RegRec.Title + ': ' + ATitle;
+
+  // Search for already opened query window for the same title
   Result:= TfmQueryWindow(FindQueryWindow(ACaption));
+
+  // No opened query window
   if Result = nil then
   begin
     Result:= TfmQueryWindow.Create(Application);
@@ -2728,7 +2700,7 @@ begin
     Result.Align:= alClient;
     Result.Font.Name:= 'Arial';
   end
-  else
+  else // Already opened query window found
     ATab:= Result.Parent as TTabSheet;
 
   Result.Init(DatabaseIndex);

+ 18 - 3
querywindow.pas

@@ -343,6 +343,7 @@ procedure TfmQueryWindow.tbNewClick(Sender: TObject);
 var
   i: Integer;
 begin
+  // Get a free number to be assigned to the new Query window
   for i:= 1 to 1000 do
   begin
     if fmMain.FindQueryWindow(RegRec.Title + ': Query Window # ' + IntToStr(i)) = nil then
@@ -457,6 +458,7 @@ begin
     Self.ibConnection.Role:= RegRec.Role;
   end;
 
+  // Get current database tables to be hilighted in SQL query editor
   SynSQLSyn1.TableNames.CommaText:= fmMain.GetTableNames(dbIndex);
 end;
 
@@ -1000,7 +1002,7 @@ begin
      end;
   end;
 
-
+  // Get SQL type
   IsDDL:= False;
   if SecondRealStart < QueryList.Count then
   begin
@@ -1115,6 +1117,8 @@ procedure TfmQueryWindow.FormClose(Sender: TObject;
   var CloseAction: TCloseAction);
 begin
   RemoveControls;
+
+  // Check if the transaction is active commit it
   if SqlTrans.Active then
   begin
     SqlTrans.CommitRetaining;
@@ -1122,7 +1126,7 @@ begin
       OnCommit(self);
     OnCommit:= nil;
   end;
-  //IBConnection.Close;
+  IBConnection.Close;
   CloseAction:= caFree;
 end;
 
@@ -1204,6 +1208,8 @@ begin
     Grid.DataSource.DataSet.First;
     List:= TStringList.Create;
     Line:= '';
+
+    // Copy fields header
     with Grid.DataSource.DataSet do
     for i:= 0 to FieldCount - 1 do
     begin
@@ -1212,6 +1218,8 @@ begin
         Line:= Line + ',';
     end;
     List.Add(Line);
+
+    // Copy table data
     with Grid.DataSource.DataSet do
     while not Eof do
     begin
@@ -1383,13 +1391,15 @@ begin
     Break;
   end;
 
+  // Search for status bar inside current query result TabSheet
   if TabSheet <> nil then
   for i:= 0 to High(ResultControls) do
   if ResultControls[i] <> nil then
     if  (ParentResultControls[i] <> nil) and ((ParentResultControls[i] as TTabSheet) = TabSheet)
       and (ResultControls[i] is TStatusBar) then
       begin
-      (ResultControls[i] as TStatusBar).SimpleText:= IntToStr(DataSet.RecordCount) +
+        // Display current record and number of total records in status bar
+        (ResultControls[i] as TStatusBar).SimpleText:= IntToStr(DataSet.RecordCount) +
         ' records fetched. At record # ' + IntToStr(DataSet.RecNo);
       break;
   end;
@@ -1399,10 +1409,13 @@ end;
 procedure TfmQueryWindow.CallExecuteQuery(aQueryType: Integer);
 begin
   fList:= TStringList.Create;
+
+  // Get query text from memo
   fQuery:= Trim(GetQuery);
   fList.Text:= fQuery;
   fStartLine:= 0;
 
+  // Disable buttons to prevent query interrupt
   tbRun.Enabled:= False;
   tbCommit.Enabled:= False;
   tbCommitRetaining.Enabled:= False;
@@ -1412,11 +1425,13 @@ begin
   fModifyCount:= 0;
   RemoveControls;
 
+  // Get initial query type, it could be changed later in the next parts
   if aQueryType = 0 then // Auto
     fQueryType:= GetQueryType(fQuery)
   else
     fQueryType:= aQueryType;
 
+  // Call execute query for each parts until finished
   fCnt:= 0;
   fFinished:= False;
   repeat

+ 12 - 5
systables.pas

@@ -53,9 +53,9 @@ type
     function GetFieldInfo(dbIndex: Integer; TableName, FieldName: string; var FieldType: string;
       var FieldSize: Integer; var NotNull: Boolean; var DefaultValue, Description : string): Boolean;
 
-    function GetDatabaseInfo(dbIndex: Integer; var DatabaseName, CharSet,
-      CreationDate, ServerTime: string; var ODSVerMajor, ODSVerMinor, Pages,
-  PageSize: Integer; var ProcessList: TStringList): Boolean;
+    function GetDatabaseInfo(dbIndex: Integer; var DatabaseName, CharSet, CreationDate, ServerTime: string;
+      var ODSVerMajor, ODSVerMinor, Pages, PageSize: Integer;
+      var ProcessList: TStringList; var ErrorMsg: string): Boolean;
 
     function GetIndices(dbIndex: Integer; ATableName: string; PrimaryIndexName: string;
       var List: TStringList): Boolean;
@@ -100,6 +100,8 @@ procedure TdmSysTables.Init(dbIndex: Integer);
 begin
   with fmMain.RegisteredDatabases[dbIndex] do
   begin
+    if IBConnection.Connected then
+      IBConnection.Close;
     sqQuery.Close;
     IBConnection.DatabaseName:= RegRec.DatabaseName;
     IBConnection.UserName:= RegRec.UserName;
@@ -683,8 +685,10 @@ begin
   sqQuery.Close;
 end;
 
-function TdmSysTables.GetDatabaseInfo(dbIndex: Integer; var DatabaseName, CharSet, CreationDate, ServerTime: string;
-  var ODSVerMajor, ODSVerMinor, Pages, PageSize: Integer; var ProcessList: TStringList): Boolean;
+function TdmSysTables.GetDatabaseInfo(dbIndex: Integer; var DatabaseName,
+  CharSet, CreationDate, ServerTime: string; var ODSVerMajor, ODSVerMinor,
+  Pages, PageSize: Integer; var ProcessList: TStringList; var ErrorMsg: string
+  ): Boolean;
 begin
   try
     Init(dbIndex);
@@ -728,8 +732,11 @@ begin
 
   except
   on e: exception do
+  begin
+    ErrorMsg:= e.Message;
     Result:= False;
   end;
+  end;
 end;
 
 function TdmSysTables.GetIndices(dbIndex: Integer; ATableName: string; PrimaryIndexName: string;