My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes  
Changes to /trunk/source/main.pas
r4108 vs. r4109 Compare: vs.  Format:
Revision r4109
Go to: 
/trunk/source/main.pas   r4108 /trunk/source/main.pas   r4109
1 unit Main; 1 unit Main;
2 2
3 3
4 // ------------------------------------- 4 // -------------------------------------
5 // Main-window 5 // Main-window
6 // ------------------------------------- 6 // -------------------------------------
7 7
8 {$I compilers.inc} 8 {$I compilers.inc}
9 9
10 interface 10 interface
11 11
12 uses 12 uses
13 Windows, SysUtils, Classes, GraphicEx, Graphics, GraphUtil, Forms, Controls, Menus, StdCtrls, Dialogs, Buttons, 13 Windows, SysUtils, Classes, GraphicEx, Graphics, GraphUtil, Forms, Controls, Menus, StdCtrls, Dialogs, Buttons,
14 Messages, ExtCtrls, ComCtrls, StdActns, ActnList, ImgList, ToolWin, Clipbrd, SynMemo, 14 Messages, ExtCtrls, ComCtrls, StdActns, ActnList, ImgList, ToolWin, Clipbrd, SynMemo,
15 SynEdit, SynEditTypes, SynEditKeyCmds, VirtualTrees, DateUtils, SyncObjs, 15 SynEdit, SynEditTypes, SynEditKeyCmds, VirtualTrees, DateUtils, SyncObjs,
16 ShlObj, SynEditMiscClasses, SynEditSearch, SynEditRegexSearch, SynCompletionProposal, SynEditHighlighter, 16 ShlObj, SynEditMiscClasses, SynEditSearch, SynEditRegexSearch, SynCompletionProposal, SynEditHighlighter,
17 SynHighlighterSQL, Tabs, SynUnicode, SynRegExpr, ExtActns, IOUtils, Types, Themes, ComObj, 17 SynHighlighterSQL, Tabs, SynUnicode, SynRegExpr, ExtActns, IOUtils, Types, Themes, ComObj,
18 CommCtrl, Contnrs, Generics.Collections, Generics.Defaults, SynEditExport, SynExportHTML, Math, ExtDlgs, Registry, AppEvnts, 18 CommCtrl, Contnrs, Generics.Collections, Generics.Defaults, SynEditExport, SynExportHTML, Math, ExtDlgs, Registry, AppEvnts,
19 routine_editor, trigger_editor, event_editor, options, EditVar, helpers, createdatabase, table_editor, 19 routine_editor, trigger_editor, event_editor, options, EditVar, helpers, createdatabase, table_editor,
20 TableTools, View, Usermanager, SelectDBObject, connections, sqlhelp, dbconnection, 20 TableTools, View, Usermanager, SelectDBObject, connections, sqlhelp, dbconnection,
21 insertfiles, searchreplace, loaddata, copytable, VTHeaderPopup, Cromis.DirectoryWatch, SyncDB; 21 insertfiles, searchreplace, loaddata, copytable, VTHeaderPopup, Cromis.DirectoryWatch, SyncDB;
22 22
23 23
24 type 24 type
25 TQueryTab = class; 25 TQueryTab = class;
26 TResultTab = class(TObject) 26 TResultTab = class(TObject)
27 Results: TDBQuery; 27 Results: TDBQuery;
28 Grid: TVirtualStringTree; 28 Grid: TVirtualStringTree;
29 FilterText: String; 29 FilterText: String;
30 public 30 public
31 constructor Create(AOwner: TQueryTab); 31 constructor Create(AOwner: TQueryTab);
32 destructor Destroy; override; 32 destructor Destroy; override;
33 end; 33 end;
34 TResultTabs = TObjectList<TResultTab>; 34 TResultTabs = TObjectList<TResultTab>;
35 TQueryTab = class(TComponent) 35 TQueryTab = class(TComponent)
36 private 36 private
37 FMemoFilename: String; 37 FMemoFilename: String;
38 procedure SetMemoFilename(Value: String); 38 procedure SetMemoFilename(Value: String);
39 public 39 public
40 Number: Integer; 40 Number: Integer;
41 ExecutionThread: TQueryThread; 41 ExecutionThread: TQueryThread;
42 CloseButton: TSpeedButton; 42 CloseButton: TSpeedButton;
43 pnlMemo: TPanel; 43 pnlMemo: TPanel;
44 pnlHelpers: TPanel; 44 pnlHelpers: TPanel;
45 treeHelpers: TVirtualStringTree; 45 treeHelpers: TVirtualStringTree;
46 Memo: TSynMemo; 46 Memo: TSynMemo;
47 MemoFileRenamed: Boolean; 47 MemoFileRenamed: Boolean;
48 MemoLineBreaks: TLineBreaks; 48 MemoLineBreaks: TLineBreaks;
49 DirectoryWatch: TDirectoryWatch; 49 DirectoryWatch: TDirectoryWatch;
50 MemofileModifiedTimer: TTimer; 50 MemofileModifiedTimer: TTimer;
51 LastSaveTime: Cardinal; 51 LastSaveTime: Cardinal;
52 spltHelpers: TSplitter; 52 spltHelpers: TSplitter;
53 spltQuery: TSplitter; 53 spltQuery: TSplitter;
54 tabsetQuery: TTabSet; 54 tabsetQuery: TTabSet;
55 TabSheet: TTabSheet; 55 TabSheet: TTabSheet;
56 ResultTabs: TResultTabs; 56 ResultTabs: TResultTabs;
57 DoProfile: Boolean; 57 DoProfile: Boolean;
58 QueryRunning: Boolean; 58 QueryRunning: Boolean;
59 QueryProfile: TDBQuery; 59 QueryProfile: TDBQuery;
60 ProfileTime, MaxProfileTime: Extended; 60 ProfileTime, MaxProfileTime: Extended;
61 LeftOffsetInMemo: Integer; 61 LeftOffsetInMemo: Integer;
62 HistoryDays: TStringList; 62 HistoryDays: TStringList;
63 function GetActiveResultTab: TResultTab; 63 function GetActiveResultTab: TResultTab;
64 procedure DirectoryWatchNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string); 64 procedure DirectoryWatchNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string);
65 procedure MemofileModifiedTimerNotify(Sender: TObject); 65 procedure MemofileModifiedTimerNotify(Sender: TObject);
66 function LoadContents(Filename: String; ReplaceContent: Boolean; Encoding: TEncoding): Boolean; 66 function LoadContents(Filename: String; ReplaceContent: Boolean; Encoding: TEncoding): Boolean;
67 procedure SaveContents(Filename: String; OnlySelection: Boolean); 67 procedure SaveContents(Filename: String; OnlySelection: Boolean);
68 property ActiveResultTab: TResultTab read GetActiveResultTab; 68 property ActiveResultTab: TResultTab read GetActiveResultTab;
69 property MemoFilename: String read FMemoFilename write SetMemoFilename; 69 property MemoFilename: String read FMemoFilename write SetMemoFilename;
70 constructor Create(AOwner: TComponent); override; 70 constructor Create(AOwner: TComponent); override;
71 destructor Destroy; override; 71 destructor Destroy; override;
72 end; 72 end;
73 73
74 TQueryHistoryItem = class(TObject) 74 TQueryHistoryItem = class(TObject)
75 Time: TDateTime; 75 Time: TDateTime;
76 Database: String; 76 Database: String;
77 SQL: String; 77 SQL: String;
78 Duration: Cardinal; 78 Duration: Cardinal;
79 RegValue: Integer; 79 RegValue: Integer;
80 end; 80 end;
81 TQueryHistory = class(TObjectList<TQueryHistoryItem>) 81 TQueryHistory = class(TObjectList<TQueryHistoryItem>)
82 private 82 private
83 FMaxDuration: Cardinal; 83 FMaxDuration: Cardinal;
84 public 84 public
85 property MaxDuration: Cardinal read FMaxDuration; 85 property MaxDuration: Cardinal read FMaxDuration;
86 function ReadItem(RegValue: String): TQueryHistoryItem; 86 function ReadItem(RegValue: String): TQueryHistoryItem;
87 end; 87 end;
88 TQueryHistoryItemComparer = class(TComparer<TQueryHistoryItem>) 88 TQueryHistoryItemComparer = class(TComparer<TQueryHistoryItem>)
89 function Compare(const Left, Right: TQueryHistoryItem): Integer; override; 89 function Compare(const Left, Right: TQueryHistoryItem): Integer; override;
90 end; 90 end;
91 91
92 ITaskbarList = interface(IUnknown) 92 ITaskbarList = interface(IUnknown)
93 [SID_ITaskbarList] 93 [SID_ITaskbarList]
94 function HrInit: HRESULT; stdcall; 94 function HrInit: HRESULT; stdcall;
95 function AddTab(hwnd: HWND): HRESULT; stdcall; 95 function AddTab(hwnd: HWND): HRESULT; stdcall;
96 function DeleteTab(hwnd: HWND): HRESULT; stdcall; 96 function DeleteTab(hwnd: HWND): HRESULT; stdcall;
97 function ActivateTab(hwnd: HWND): HRESULT; stdcall; 97 function ActivateTab(hwnd: HWND): HRESULT; stdcall;
98 function SetActiveAlt(hwnd: HWND): HRESULT; stdcall; 98 function SetActiveAlt(hwnd: HWND): HRESULT; stdcall;
99 end; 99 end;
100 ITaskbarList2 = interface(ITaskbarList) 100 ITaskbarList2 = interface(ITaskbarList)
101 [SID_ITaskbarList2] 101 [SID_ITaskbarList2]
102 function MarkFullscreenWindow(hwnd: HWND; fFullscreen: BOOL): HRESULT; stdcall; 102 function MarkFullscreenWindow(hwnd: HWND; fFullscreen: BOOL): HRESULT; stdcall;
103 end; 103 end;
104 ITaskbarList3 = interface(ITaskbarList2) 104 ITaskbarList3 = interface(ITaskbarList2)
105 [SID_ITaskbarList3] 105 [SID_ITaskbarList3]
106 function SetProgressValue(hwnd: HWND; ullCompleted: ULONGLONG; ullTotal: ULONGLONG): HRESULT; stdcall; 106 function SetProgressValue(hwnd: HWND; ullCompleted: ULONGLONG; ullTotal: ULONGLONG): HRESULT; stdcall;
107 function SetProgressState(hwnd: HWND; tbpFlags: Integer): HRESULT; stdcall; 107 function SetProgressState(hwnd: HWND; tbpFlags: Integer): HRESULT; stdcall;
108 function RegisterTab(hwndTab: HWND; hwndMDI: HWND): HRESULT; stdcall; 108 function RegisterTab(hwndTab: HWND; hwndMDI: HWND): HRESULT; stdcall;
109 function UnregisterTab(hwndTab: HWND): HRESULT; stdcall; 109 function UnregisterTab(hwndTab: HWND): HRESULT; stdcall;
110 function SetTabOrder(hwndTab: HWND; hwndInsertBefore: HWND): HRESULT; stdcall; 110 function SetTabOrder(hwndTab: HWND; hwndInsertBefore: HWND): HRESULT; stdcall;
111 function SetTabActive(hwndTab: HWND; hwndMDI: HWND; tbatFlags: Integer): HRESULT; stdcall; 111 function SetTabActive(hwndTab: HWND; hwndMDI: HWND; tbatFlags: Integer): HRESULT; stdcall;
112 function ThumbBarAddButtons(hwnd: HWND; cButtons: UINT; pButton: PThumbButton): HRESULT; stdcall; 112 function ThumbBarAddButtons(hwnd: HWND; cButtons: UINT; pButton: PThumbButton): HRESULT; stdcall;
113 function ThumbBarUpdateButtons(hwnd: HWND; cButtons: UINT; pButton: PThumbButton): HRESULT; stdcall; 113 function ThumbBarUpdateButtons(hwnd: HWND; cButtons: UINT; pButton: PThumbButton): HRESULT; stdcall;
114 function ThumbBarSetImageList(hwnd: HWND; himl: HIMAGELIST): HRESULT; stdcall; 114 function ThumbBarSetImageList(hwnd: HWND; himl: HIMAGELIST): HRESULT; stdcall;
115 function SetOverlayIcon(hwnd: HWND; hIcon: HICON; pszDescription: LPCWSTR): HRESULT; stdcall; 115 function SetOverlayIcon(hwnd: HWND; hIcon: HICON; pszDescription: LPCWSTR): HRESULT; stdcall;
116 function SetThumbnailTooltip(hwnd: HWND; pszTip: LPCWSTR): HRESULT; stdcall; 116 function SetThumbnailTooltip(hwnd: HWND; pszTip: LPCWSTR): HRESULT; stdcall;
117 function SetThumbnailClip(hwnd: HWND; var prcClip: TRect): HRESULT; stdcall; 117 function SetThumbnailClip(hwnd: HWND; var prcClip: TRect): HRESULT; stdcall;
118 end; 118 end;
119 119
120 TMainForm = class(TForm) 120 TMainForm = class(TForm)
121 MainMenu1: TMainMenu; 121 MainMenu1: TMainMenu;
122 File1: TMenuItem; 122 File1: TMenuItem;
123 FileNewItem: TMenuItem; 123 FileNewItem: TMenuItem;
124 Help1: TMenuItem; 124 Help1: TMenuItem;
125 N1: TMenuItem; 125 N1: TMenuItem;
126 FileExitItem: TMenuItem; 126 FileExitItem: TMenuItem;
127 menuAbout: TMenuItem; 127 menuAbout: TMenuItem;
128 Edit1: TMenuItem; 128 Edit1: TMenuItem;
129 CopyItem: TMenuItem; 129 CopyItem: TMenuItem;
130 PasteItem: TMenuItem; 130 PasteItem: TMenuItem;
131 StatusBar: TStatusBar; 131 StatusBar: TStatusBar;
132 ActionList1: TActionList; 132 ActionList1: TActionList;
133 actCopy: TAction; 133 actCopy: TAction;
134 actPaste: TAction; 134 actPaste: TAction;
135 actNewWindow: TAction; 135 actNewWindow: TAction;
136 actExitApplication: TAction; 136 actExitApplication: TAction;
137 Extra1: TMenuItem; 137 Extra1: TMenuItem;
138 FlushUserPrivileges1: TMenuItem; 138 FlushUserPrivileges1: TMenuItem;
139 N5: TMenuItem; 139 N5: TMenuItem;
140 Flush1: TMenuItem; 140 Flush1: TMenuItem;
141 MenuFlushLogs: TMenuItem; 141 MenuFlushLogs: TMenuItem;
142 MenuFlushHosts: TMenuItem; 142 MenuFlushHosts: TMenuItem;
143 MenuFlushTables: TMenuItem; 143 MenuFlushTables: TMenuItem;
144 MenuFlushTableswithreadlock: TMenuItem; 144 MenuFlushTableswithreadlock: TMenuItem;
145 MenuFlushStatus: TMenuItem; 145 MenuFlushStatus: TMenuItem;
146 N6: TMenuItem; 146 N6: TMenuItem;
147 MenuUserManager: TMenuItem; 147 MenuUserManager: TMenuItem;
148 MenuPreferences: TMenuItem; 148 MenuPreferences: TMenuItem;
149 N7a: TMenuItem; 149 N7a: TMenuItem;
150 menuReadme: TMenuItem; 150 menuReadme: TMenuItem;
151 actUserManager: TAction; 151 actUserManager: TAction;
152 actAboutBox: TAction; 152 actAboutBox: TAction;
153 actMaintenance: TAction; 153 actMaintenance: TAction;
154 menuMaintenance: TMenuItem; 154 menuMaintenance: TMenuItem;
155 actPrintList: TAction; 155 actPrintList: TAction;
156 actCopyTable: TAction; 156 actCopyTable: TAction;
157 ControlBar1: TControlBar; 157 ControlBar1: TControlBar;
158 ToolBarStandard: TToolBar; 158 ToolBarStandard: TToolBar;
159 ToolButton9: TToolButton; 159 ToolButton9: TToolButton;
160 tlbSep1: TToolButton; 160 tlbSep1: TToolButton;
161 ToolButton5: TToolButton; 161 ToolButton5: TToolButton;
162 ToolButton6: TToolButton; 162 ToolButton6: TToolButton;
163 ToolButton12: TToolButton; 163 ToolButton12: TToolButton;
164 tlbSep2: TToolButton; 164 tlbSep2: TToolButton;
165 ButtonRefresh: TToolButton; 165 ButtonRefresh: TToolButton;
166 ButtonImportTextfile: TToolButton; 166 ButtonImportTextfile: TToolButton;
167 ButtonExport: TToolButton; 167 ButtonExport: TToolButton;
168 ButtonUserManager: TToolButton; 168 ButtonUserManager: TToolButton;
169 ToolBarData: TToolBar; 169 ToolBarData: TToolBar;
170 actUndo: TEditUndo; 170 actUndo: TEditUndo;
171 ToolButton14: TToolButton; 171 ToolButton14: TToolButton;
172 actExecuteQuery: TAction; 172 actExecuteQuery: TAction;
173 actExecuteSelection: TAction; 173 actExecuteSelection: TAction;
174 SaveDialog2: TSaveDialog; 174 SaveDialog2: TSaveDialog;
175 ExportSettings1: TMenuItem; 175 ExportSettings1: TMenuItem;
176 Importsettings1: TMenuItem; 176 Importsettings1: TMenuItem;
177 OpenDialog2: TOpenDialog; 177 OpenDialog2: TOpenDialog;
178 menuSupportForum: TMenuItem; 178 menuSupportForum: TMenuItem;
179 actExportData: TAction; 179 actExportData: TAction;
180 actExecuteCurrentQuery: TAction; 180 actExecuteCurrentQuery: TAction;
181 actDataPreview: TAction; 181 actDataPreview: TAction;
182 actInsertFiles: TAction; 182 actInsertFiles: TAction;
183 actExportTables: TAction; 183 actExportTables: TAction;
184 actDropObjects: TAction; 184 actDropObjects: TAction;
185 actLoadSQL: TAction; 185 actLoadSQL: TAction;
186 menuConnections: TPopupMenu; 186 menuConnections: TPopupMenu;
187 menuFeaturetracker: TMenuItem; 187 menuFeaturetracker: TMenuItem;
188 menuDownload: TMenuItem; 188 menuDownload: TMenuItem;
189 btnSQLHelp: TToolButton; 189 btnSQLHelp: TToolButton;
190 menuSQLHelp1: TMenuItem; 190 menuSQLHelp1: TMenuItem;
191 N8a: TMenuItem; 191 N8a: TMenuItem;
192 tlbSep6: TToolButton; 192 tlbSep6: TToolButton;
193 menuUpdateCheck: TMenuItem; 193 menuUpdateCheck: TMenuItem;
194 ImageListMain: TImageList; 194 ImageListMain: TImageList;
195 actCreateView: TAction; 195 actCreateView: TAction;
196 ToolButton3: TToolButton; 196 ToolButton3: TToolButton;
197 actDataFirst: TAction; 197 actDataFirst: TAction;
198 actDataLast: TAction; 198 actDataLast: TAction;
199 actDataInsert: TAction; 199 actDataInsert: TAction;
200 actDataDelete: TAction; 200 actDataDelete: TAction;
201 actDataPostChanges: TAction; 201 actDataPostChanges: TAction;
202 ToolButton4: TToolButton; 202 ToolButton4: TToolButton;
203 ToolButton7: TToolButton; 203 ToolButton7: TToolButton;
204 ToolButton8: TToolButton; 204 ToolButton8: TToolButton;
205 ToolButton10: TToolButton; 205 ToolButton10: TToolButton;
206 actCreateTable: TAction; 206 actCreateTable: TAction;
207 actEmptyTables: TAction; 207 actEmptyTables: TAction;
208 actCreateDatabase: TAction; 208 actCreateDatabase: TAction;
209 actSQLhelp: TAction; 209 actSQLhelp: TAction;
210 actRefresh: TAction; 210 actRefresh: TAction;
211 actImportCSV: TAction; 211 actImportCSV: TAction;
212 actCut: TAction; 212 actCut: TAction;
213 Cut1: TMenuItem; 213 Cut1: TMenuItem;
214 actExportSettings: TAction; 214 actExportSettings: TAction;
215 actImportSettings: TAction; 215 actImportSettings: TAction;
216 actSelectTreeBackground: TAction; 216 actSelectTreeBackground: TAction;
217 actPreferences: TAction; 217 actPreferences: TAction;
218 actFlushHosts: TAction; 218 actFlushHosts: TAction;
219 actFlushLogs: TAction; 219 actFlushLogs: TAction;
220 actFlushPrivileges: TAction; 220 actFlushPrivileges: TAction;
221 actFlushTables: TAction; 221 actFlushTables: TAction;
222 actFlushTableswithreadlock: TAction; 222 actFlushTableswithreadlock: TAction;
223 actFlushStatus: TAction; 223 actFlushStatus: TAction;
224 actUpdateCheck: TAction; 224 actUpdateCheck: TAction;
225 actWebDownloadpage: TAction; 225 actWebDownloadpage: TAction;
226 actWebForum: TAction; 226 actWebForum: TAction;
227 actWebChangelog: TAction; 227 actWebChangelog: TAction;
228 actReadme: TAction; 228 actReadme: TAction;
229 actSaveSQL: TAction; 229 actSaveSQL: TAction;
230 actSaveSQLAs: TAction; 230 actSaveSQLAs: TAction;
231 actSaveSQLselection: TAction; 231 actSaveSQLselection: TAction;
232 actSaveSQLSnippet: TAction; 232 actSaveSQLSnippet: TAction;
233 actSaveSQLSelectionSnippet: TAction; 233 actSaveSQLSelectionSnippet: TAction;
234 actClearQueryEditor: TAction; 234 actClearQueryEditor: TAction;
235 actClearFilterEditor: TAction; 235 actClearFilterEditor: TAction;
236 actApplyFilter: TAction; 236 actApplyFilter: TAction;
237 actQueryStopOnErrors: TAction; 237 actQueryStopOnErrors: TAction;
238 actQueryWordWrap: TAction; 238 actQueryWordWrap: TAction;
239 actQueryFind: TAction; 239 actQueryFind: TAction;
240 actQueryReplace: TAction; 240 actQueryReplace: TAction;
241 ToolBarQuery: TToolBar; 241 ToolBarQuery: TToolBar;
242 btnExecuteQuery: TToolButton; 242 btnExecuteQuery: TToolButton;
243 btnLoadSQL: TToolButton; 243 btnLoadSQL: TToolButton;
244 btnSaveSQL: TToolButton; 244 btnSaveSQL: TToolButton;
245 btnSaveSQLSnippet: TToolButton; 245 btnSaveSQLSnippet: TToolButton;
246 btnQueryFind: TToolButton; 246 btnQueryFind: TToolButton;
247 btnQueryReplace: TToolButton; 247 btnQueryReplace: TToolButton;
248 btnStopOnErrors: TToolButton; 248 btnStopOnErrors: TToolButton;
249 btnQueryWordwrap: TToolButton; 249 btnQueryWordwrap: TToolButton;
250 PopupQueryLoad: TPopupMenu; 250 PopupQueryLoad: TPopupMenu;
251 actSetDelimiter: TAction; 251 actSetDelimiter: TAction;
252 btnSetDelimiter: TToolButton; 252 btnSetDelimiter: TToolButton;
253 actDataCancelChanges: TAction; 253 actDataCancelChanges: TAction;
254 ToolButton1: TToolButton; 254 ToolButton1: TToolButton;
255 actRemoveFilter: TAction; 255 actRemoveFilter: TAction;
256 panelTop: TPanel; 256 panelTop: TPanel;
257 pnlLeft: TPanel; 257 pnlLeft: TPanel;
258 DBtree: TVirtualStringTree; 258 DBtree: TVirtualStringTree;
259 comboDBFilter: TComboBox; 259 comboDBFilter: TComboBox;
260 spltDBtree: TSplitter; 260 spltDBtree: TSplitter;
261 PageControlMain: TPageControl; 261 PageControlMain: TPageControl;
262 tabData: TTabSheet; 262 tabData: TTabSheet;
263 tabDatabase: TTabSheet; 263 tabDatabase: TTabSheet;
264 splitterTopBottom: TSplitter; 264 splitterTopBottom: TSplitter;
265 tabQuery: TTabSheet; 265 tabQuery: TTabSheet;
266 popupDB: TPopupMenu; 266 popupDB: TPopupMenu;
267 menuRefreshDB: TMenuItem; 267 menuRefreshDB: TMenuItem;
268 tabHost: TTabSheet; 268 tabHost: TTabSheet;
269 PageControlHost: TPageControl; 269 PageControlHost: TPageControl;
270 tabVariables: TTabSheet; 270 tabVariables: TTabSheet;
271 tabProcessList: TTabSheet; 271 tabProcessList: TTabSheet;
272 ListVariables: TVirtualStringTree; 272 ListVariables: TVirtualStringTree;
273 ListProcesses: TVirtualStringTree; 273 ListProcesses: TVirtualStringTree;
274 popupHost: TPopupMenu; 274 popupHost: TPopupMenu;
275 Kill1: TMenuItem; 275 Kill1: TMenuItem;
276 ListTables: TVirtualStringTree; 276 ListTables: TVirtualStringTree;
277 Refresh1: TMenuItem; 277 Refresh1: TMenuItem;
278 pnlDataTop: TPanel; 278 pnlDataTop: TPanel;
279 pnlQueryMemo: TPanel; 279 pnlQueryMemo: TPanel;
280 SynSQLSyn1: TSynSQLSyn; 280 SynSQLSyn1: TSynSQLSyn;
281 SynMemoQuery: TSynMemo; 281 SynMemoQuery: TSynMemo;
282 spltQuery: TSplitter; 282 spltQuery: TSplitter;
283 OpenDialog1: TOpenDialog; 283 OpenDialog1: TOpenDialog;
284 TimerHostUptime: TTimer; 284 TimerHostUptime: TTimer;
285 N5a: TMenuItem; 285 N5a: TMenuItem;
286 popupDataGrid: TPopupMenu; 286 popupDataGrid: TPopupMenu;
287 Refresh3: TMenuItem; 287 Refresh3: TMenuItem;
288 N9a: TMenuItem; 288 N9a: TMenuItem;
289 TimerConnected: TTimer; 289 TimerConnected: TTimer;
290 popupSqlLog: TPopupMenu; 290 popupSqlLog: TPopupMenu;
291 Clear2: TMenuItem; 291 Clear2: TMenuItem;
292 Copy1: TMenuItem; 292 Copy1: TMenuItem;
293 N15: TMenuItem; 293 N15: TMenuItem;
294 N17: TMenuItem; 294 N17: TMenuItem;
295 Copy3: TMenuItem; 295 Copy3: TMenuItem;
296 Paste2: TMenuItem; 296 Paste2: TMenuItem;
297 N4a: TMenuItem; 297 N4a: TMenuItem;
298 DataGrid: TVirtualStringTree; 298 DataGrid: TVirtualStringTree;
299 QueryGrid: TVirtualStringTree; 299 QueryGrid: TVirtualStringTree;
300 Delete1: TMenuItem; 300 Delete1: TMenuItem;
301 N6a: TMenuItem; 301 N6a: TMenuItem;
302 QF1: TMenuItem; 302 QF1: TMenuItem;
303 QF2: TMenuItem; 303 QF2: TMenuItem;
304 menuQuickFilter: TMenuItem; 304 menuQuickFilter: TMenuItem;
305 QF3: TMenuItem; 305 QF3: TMenuItem;
306 QF4: TMenuItem; 306 QF4: TMenuItem;
307 N7: TMenuItem; 307 N7: TMenuItem;
308 DropFilter1: TMenuItem; 308 DropFilter1: TMenuItem;
309 PrintList2: TMenuItem; 309 PrintList2: TMenuItem;
310 N1a: TMenuItem; 310 N1a: TMenuItem;
311 SynMemoFilter: TSynMemo; 311 SynMemoFilter: TSynMemo;
312 TimerRefresh: TTimer; 312 TimerRefresh: TTimer;
313 Saveastextfile1: TMenuItem; 313 Saveastextfile1: TMenuItem;
314 QF7: TMenuItem; 314 QF7: TMenuItem;
315 QF5: TMenuItem; 315 QF5: TMenuItem;
316 QF6: TMenuItem; 316 QF6: TMenuItem;
317 QF8: TMenuItem; 317 QF8: TMenuItem;
318 QF10: TMenuItem; 318 QF10: TMenuItem;
319 QF11: TMenuItem; 319 QF11: TMenuItem;
320 QF9: TMenuItem; 320 QF9: TMenuItem;
321 QF12: TMenuItem; 321 QF12: TMenuItem;
322 Exportdata2: TMenuItem; 322 Exportdata2: TMenuItem;
323 N11a: TMenuItem; 323 N11a: TMenuItem;
324 DataInsertValue: TMenuItem; 324 DataInsertValue: TMenuItem;
325 DataDateTime: TMenuItem; 325 DataDateTime: TMenuItem;
326 DataTime: TMenuItem; 326 DataTime: TMenuItem;
327 DataDate: TMenuItem; 327 DataDate: TMenuItem;
328 DataYear: TMenuItem; 328 DataYear: TMenuItem;
329 DataGUID: TMenuItem; 329 DataGUID: TMenuItem;
330 ViewasHTML1: TMenuItem; 330 ViewasHTML1: TMenuItem;
331 InsertfilesintoBLOBfields3: TMenuItem; 331 InsertfilesintoBLOBfields3: TMenuItem;
332 setNULL1: TMenuItem; 332 setNULL1: TMenuItem;
333 menuExporttables: TMenuItem; 333 menuExporttables: TMenuItem;
334 popupListHeader: TVTHeaderPopupMenu; 334 popupListHeader: TVTHeaderPopupMenu;
335 SynCompletionProposal: TSynCompletionProposal; 335 SynCompletionProposal: TSynCompletionProposal;
336 ParameterCompletionProposal: TSynCompletionProposal; 336 ParameterCompletionProposal: TSynCompletionProposal;
337 SaveDialogSQLFile: TSaveDialog; 337 SaveDialogSQLFile: TSaveDialog;
338 SynEditSearch1: TSynEditSearch; 338 SynEditSearch1: TSynEditSearch;
339 SynEditRegexSearch1: TSynEditRegexSearch; 339 SynEditRegexSearch1: TSynEditRegexSearch;
340 tabCommandStats: TTabSheet; 340 tabCommandStats: TTabSheet;
341 ListCommandStats: TVirtualStringTree; 341 ListCommandStats: TVirtualStringTree;
342 QF13: TMenuItem; 342 QF13: TMenuItem;
343 QF14: TMenuItem; 343 QF14: TMenuItem;
344 QF15: TMenuItem; 344 QF15: TMenuItem;
345 QF16: TMenuItem; 345 QF16: TMenuItem;
346 QF17: TMenuItem; 346 QF17: TMenuItem;
347 QF18: TMenuItem; 347 QF18: TMenuItem;
348 QF19: TMenuItem; 348 QF19: TMenuItem;
349 N21: TMenuItem; 349 N21: TMenuItem;
350 popupQuery: TPopupMenu; 350 popupQuery: TPopupMenu;
351 MenuRun: TMenuItem; 351 MenuRun: TMenuItem;
352 MenuRunSelection: TMenuItem; 352 MenuRunSelection: TMenuItem;
353 MenuRunLine: TMenuItem; 353 MenuRunLine: TMenuItem;
354 MenuItem1: TMenuItem; 354 MenuItem1: TMenuItem;
355 menucopy: TMenuItem; 355 menucopy: TMenuItem;
356 menupaste: TMenuItem; 356 menupaste: TMenuItem;
357 menuload: TMenuItem; 357 menuload: TMenuItem;
358 menusave: TMenuItem; 358 menusave: TMenuItem;
359 menuSaveSQL: TMenuItem; 359 menuSaveSQL: TMenuItem;
360 menuclear: TMenuItem; 360 menuclear: TMenuItem;
361 MenuFind: TMenuItem; 361 MenuFind: TMenuItem;
362 MenuReplace: TMenuItem; 362 MenuReplace: TMenuItem;
363 MenuItem2: TMenuItem; 363 MenuItem2: TMenuItem;
364 lblDataTop: TLabel; 364 lblDataTop: TLabel;
365 spltQueryHelpers: TSplitter; 365 spltQueryHelpers: TSplitter;
366 N22: TMenuItem; 366 N22: TMenuItem;
367 N23: TMenuItem; 367 N23: TMenuItem;
368 menuSaveSelectionToFile: TMenuItem; 368 menuSaveSelectionToFile: TMenuItem;
369 menuSaveAsSnippet: TMenuItem; 369 menuSaveAsSnippet: TMenuItem;
370 menuSaveSelectionAsSnippet: TMenuItem; 370 menuSaveSelectionAsSnippet: TMenuItem;
371 popupQueryHelpers: TPopupMenu; 371 popupQueryHelpers: TPopupMenu;
372 menuDeleteSnippet: TMenuItem; 372 menuDeleteSnippet: TMenuItem;
373 menuHelp: TMenuItem; 373 menuHelp: TMenuItem;
374 menuLoadSnippet: TMenuItem; 374 menuLoadSnippet: TMenuItem;
375 menuInsertSnippetAtCursor: TMenuItem; 375 menuInsertSnippetAtCursor: TMenuItem;
376 menuExplore: TMenuItem; 376 menuExplore: TMenuItem;
377 menuSQLhelp2: TMenuItem; 377 menuSQLhelp2: TMenuItem;
378 menuSQLhelpData: TMenuItem; 378 menuSQLhelpData: TMenuItem;
379 menuLogToFile: TMenuItem; 379 menuLogToFile: TMenuItem;
380 menuOpenLogFolder: TMenuItem; 380 menuOpenLogFolder: TMenuItem;
381 tabStatus: TTabSheet; 381 tabStatus: TTabSheet;
382 ListStatus: TVirtualStringTree; 382 ListStatus: TVirtualStringTree;
383 Splitter3: TSplitter; 383 Splitter3: TSplitter;
384 pnlProcessViewBox: TPanel; 384 pnlProcessViewBox: TPanel;
385 pnlProcessView: TPanel; 385 pnlProcessView: TPanel;
386 SynMemoProcessView: TSynMemo; 386 SynMemoProcessView: TSynMemo;
387 pnlFilterVT: TPanel; 387 pnlFilterVT: TPanel;
388 editFilterVT: TButtonedEdit; 388 editFilterVT: TButtonedEdit;
389 lblFilterVT: TLabel; 389 lblFilterVT: TLabel;
390 lblFilterVTInfo: TLabel; 390 lblFilterVTInfo: TLabel;
391 menuEditVariable: TMenuItem; 391 menuEditVariable: TMenuItem;
392 menuTreeExpandAll: TMenuItem; 392 menuTreeExpandAll: TMenuItem;
393 menuTreeCollapseAll: TMenuItem; 393 menuTreeCollapseAll: TMenuItem;
394 tlbDataButtons: TToolBar; 394 tlbDataButtons: TToolBar;
395 tbtnDataSorting: TToolButton; 395 tbtnDataSorting: TToolButton;
396 tbtnDataColumns: TToolButton; 396 tbtnDataColumns: TToolButton;
397 tbtnDataFilter: TToolButton; 397 tbtnDataFilter: TToolButton;
398 pnlFilter: TPanel; 398 pnlFilter: TPanel;
399 btnFilterApply: TButton; 399 btnFilterApply: TButton;
400 lblTableFilter: TLabel; 400 lblTableFilter: TLabel;
401 editFilterSearch: TEdit; 401 editFilterSearch: TEdit;
402 btnFilterClear: TButton; 402 btnFilterClear: TButton;
403 popupFilter: TPopupMenu; 403 popupFilter: TPopupMenu;
404 menuFilterCopy: TMenuItem; 404 menuFilterCopy: TMenuItem;
405 menuFilterPaste: TMenuItem; 405 menuFilterPaste: TMenuItem;
406 N8: TMenuItem; 406 N8: TMenuItem;
407 menuFilterApply: TMenuItem; 407 menuFilterApply: TMenuItem;
408 menuFilterClear: TMenuItem; 408 menuFilterClear: TMenuItem;
409 SynMemoSQLLog: TSynMemo; 409 SynMemoSQLLog: TSynMemo;
410 Insert1: TMenuItem; 410 Insert1: TMenuItem;
411 Cancelediting1: TMenuItem; 411 Cancelediting1: TMenuItem;
412 DataPost1: TMenuItem; 412 DataPost1: TMenuItem;
413 menuShowSizeColumn: TMenuItem; 413 menuShowSizeColumn: TMenuItem;
414 menuSelectBGColor: TMenuItem; 414 menuSelectBGColor: TMenuItem;
415 actPreviousTab: TPreviousTab; 415 actPreviousTab: TPreviousTab;
416 actNextTab: TNextTab; 416 actNextTab: TNextTab;
417 Nexttab1: TMenuItem; 417 Nexttab1: TMenuItem;
418 Previoustab1: TMenuItem; 418 Previoustab1: TMenuItem;
419 menuConnectTo: TMenuItem; 419 menuConnectTo: TMenuItem;
420 actSelectAll: TAction; 420 actSelectAll: TAction;
421 actSelectAll1: TMenuItem; 421 actSelectAll1: TMenuItem;
422 N13: TMenuItem; 422 N13: TMenuItem;
423 ProgressBarStatus: TProgressBar; 423 ProgressBarStatus: TProgressBar;
424 menuRecentFilters: TMenuItem; 424 menuRecentFilters: TMenuItem;
425 comboRecentFilters: TComboBox; 425 comboRecentFilters: TComboBox;
426 lblRecentFilters: TLabel; 426 lblRecentFilters: TLabel;
427 Copy2: TMenuItem; 427 Copy2: TMenuItem;
428 N26: TMenuItem; 428 N26: TMenuItem;
429 actSessionManager: TAction; 429 actSessionManager: TAction;
430 Sessionmanager1: TMenuItem; 430 Sessionmanager1: TMenuItem;
431 actCreateRoutine: TAction; 431 actCreateRoutine: TAction;
432 btnExit: TToolButton; 432 btnExit: TToolButton;
433 lblSorryNoData: TLabel; 433 lblSorryNoData: TLabel;
434 menuPrint: TMenuItem; 434 menuPrint: TMenuItem;
435 menuEditObject: TMenuItem; 435 menuEditObject: TMenuItem;
436 menuCreateObject: TMenuItem; 436 menuCreateObject: TMenuItem;
437 menuDeleteObject: TMenuItem; 437 menuDeleteObject: TMenuItem;
438 menuMaintenance2: TMenuItem; 438 menuMaintenance2: TMenuItem;
439 menuEmptyTables: TMenuItem; 439 menuEmptyTables: TMenuItem;
440 menuCreateDB: TMenuItem; 440 menuCreateDB: TMenuItem;
441 menuCreateTable: TMenuItem; 441 menuCreateTable: TMenuItem;
442 menuCreateTableCopy: TMenuItem; 442 menuCreateTableCopy: TMenuItem;
443 menuCreateView: TMenuItem; 443 menuCreateView: TMenuItem;
444 menuCreateRoutine: TMenuItem; 444 menuCreateRoutine: TMenuItem;
445 tabEditor: TTabSheet; 445 tabEditor: TTabSheet;
446 popupRefresh: TPopupMenu; 446 popupRefresh: TPopupMenu;
447 menuAutoRefreshSetInterval: TMenuItem; 447 menuAutoRefreshSetInterval: TMenuItem;
448 menuAutoRefresh: TMenuItem; 448 menuAutoRefresh: TMenuItem;
449 popupMainTabs: TPopupMenu; 449 popupMainTabs: TPopupMenu;
450 menuNewQueryTab: TMenuItem; 450 menuNewQueryTab: TMenuItem;
451 menuCloseTab: TMenuItem; 451 menuCloseTab: TMenuItem;
452 actNewQueryTab: TAction; 452 actNewQueryTab: TAction;
453 actCloseQueryTab: TAction; 453 actCloseQueryTab: TAction;
454 Newquerytab1: TMenuItem; 454 Newquerytab1: TMenuItem;
455 Closetab1: TMenuItem; 455 Closetab1: TMenuItem;
456 pnlRight: TPanel; 456 pnlRight: TPanel;
457 btnCloseFilterPanel: TSpeedButton; 457 btnCloseFilterPanel: TSpeedButton;
458 actFilterPanel: TAction; 458 actFilterPanel: TAction;
459 actFindInVT1: TMenuItem; 459 actFindInVT1: TMenuItem;
460 TimerFilterVT: TTimer; 460 TimerFilterVT: TTimer;
461 actFindTextOnServer: TAction; 461 actFindTextOnServer: TAction;
462 actFindTextOnServer1: TMenuItem; 462 actFindTextOnServer1: TMenuItem;
463 Findtextonserver1: TMenuItem; 463 Findtextonserver1: TMenuItem;
464 actBulkTableEdit: TAction; 464 actBulkTableEdit: TAction;
465 menuBulkTableEdit: TMenuItem; 465 menuBulkTableEdit: TMenuItem;
466 menuQueryHelpersGenerateInsert: TMenuItem; 466 menuQueryHelpersGenerateInsert: TMenuItem;
467 menuQueryHelpersGenerateUpdate: TMenuItem; 467 menuQueryHelpersGenerateUpdate: TMenuItem;
468 menuQueryHelpersGenerateDelete: TMenuItem; 468 menuQueryHelpersGenerateDelete: TMenuItem;
469 actCreateTrigger: TAction; 469 actCreateTrigger: TAction;
470 menuCreateTrigger: TMenuItem; 470 menuCreateTrigger: TMenuItem;
471 menuQueryCut: TMenuItem; 471 menuQueryCut: TMenuItem;
472 menuQuerySelectall: TMenuItem; 472 menuQuerySelectall: TMenuItem;
473 actDataDuplicateRow: TAction; 473 actDataDuplicateRow: TAction;
474 Duplicaterow1: TMenuItem; 474 Duplicaterow1: TMenuItem;
475 Bulktableeditor1: TMenuItem; 475 Bulktableeditor1: TMenuItem;
476 actSelectInverse: TAction; 476 actSelectInverse: TAction;
477 Inverseselection1: TMenuItem; 477 Inverseselection1: TMenuItem;
478 actDataResetSorting: TAction; 478 actDataResetSorting: TAction;
479 Resetsorting1: TMenuItem; 479 Resetsorting1: TMenuItem;
480 actReformatSQL: TAction; 480 actReformatSQL: TAction;
481 ReformatSQL1: TMenuItem; 481 ReformatSQL1: TMenuItem;
482 btnReformatSQL: TToolButton; 482 btnReformatSQL: TToolButton;
483 ReformatSQL2: TMenuItem; 483 ReformatSQL2: TMenuItem;
484 menuQueryInsertFunction: TMenuItem; 484 menuQueryInsertFunction: TMenuItem;
485 menuFilterInsertFunction: TMenuItem; 485 menuFilterInsertFunction: TMenuItem;
486 actBlobAsText: TAction; 486 actBlobAsText: TAction;
487 btnBlobAsText: TToolButton; 487 btnBlobAsText: TToolButton;
488 actQueryFindAgain: TAction; 488 actQueryFindAgain: TAction;
489 Search1: TMenuItem; 489 Search1: TMenuItem;
490 Findtext1: TMenuItem; 490 Findtext1: TMenuItem;
491 actQueryFindAgain1: TMenuItem; 491 actQueryFindAgain1: TMenuItem;
492 Replacetext1: TMenuItem; 492 Replacetext1: TMenuItem;
493 lblExplainProcess: TLabel; 493 lblExplainProcess: TLabel;
494 menuExplainProcess: TMenuItem; 494 menuExplainProcess: TMenuItem;
495 ToolButton2: TToolButton; 495 ToolButton2: TToolButton;
496 tbtnDataShowAll: TToolButton; 496 tbtnDataShowAll: TToolButton;
497 tbtnDataNext: TToolButton; 497 tbtnDataNext: TToolButton;
498 actDataShowNext: TAction; 498 actDataShowNext: TAction;
499 actDataShowAll: TAction; 499 actDataShowAll: TAction;
500 QFvalues: TMenuItem; 500 QFvalues: TMenuItem;
501 tabDatabases: TTabSheet; 501 tabDatabases: TTabSheet;
502 ListDatabases: TVirtualStringTree; 502 ListDatabases: TVirtualStringTree;
503 menuFetchDBitems: TMenuItem; 503 menuFetchDBitems: TMenuItem;
504 actRunRoutines: TAction; 504 actRunRoutines: TAction;
505 Runroutines1: TMenuItem; 505 Runroutines1: TMenuItem;
506 actCreateEvent: TAction; 506 actCreateEvent: TAction;
507 Event1: TMenuItem; 507 Event1: TMenuItem;
508 tabsetQuery: TTabSet; 508 tabsetQuery: TTabSet;
509 BalloonHint1: TBalloonHint; 509 BalloonHint1: TBalloonHint;
510 actDataSetNull: TAction; 510 actDataSetNull: TAction;
511 pnlPreview: TPanel; 511 pnlPreview: TPanel;
512 spltPreview: TSplitter; 512 spltPreview: TSplitter;
513 imgPreview: TImage; 513 imgPreview: TImage;
514 lblPreviewTitle: TLabel; 514 lblPreviewTitle: TLabel;
515 ToolBarPreview: TToolBar; 515 ToolBarPreview: TToolBar;
516 btnPreviewCopy: TToolButton; 516 btnPreviewCopy: TToolButton;
517 btnPreviewSaveToFile: TToolButton; 517 btnPreviewSaveToFile: TToolButton;
518 btnPreviewClose: TToolButton; 518 btnPreviewClose: TToolButton;
519 actDataSaveBlobToFile: TAction; 519 actDataSaveBlobToFile: TAction;
520 SaveBLOBtofile1: TMenuItem; 520 SaveBLOBtofile1: TMenuItem;
521 DataUNIXtimestamp: TMenuItem; 521 DataUNIXtimestamp: TMenuItem;
522 treeQueryHelpers: TVirtualStringTree; 522 treeQueryHelpers: TVirtualStringTree;
523 popupExecuteQuery: TPopupMenu; 523 popupExecuteQuery: TPopupMenu;
524 Run1: TMenuItem; 524 Run1: TMenuItem;
525 RunSelection1: TMenuItem; 525 RunSelection1: TMenuItem;
526 Runcurrentquery1: TMenuItem; 526 Runcurrentquery1: TMenuItem;
527 ApplicationEvents1: TApplicationEvents; 527 ApplicationEvents1: TApplicationEvents;
528 actDisconnect: TAction; 528 actDisconnect: TAction;
529 Copylinetonewquerytab1: TMenuItem; 529 Copylinetonewquerytab1: TMenuItem;
530 menuLogHorizontalScrollbar: TMenuItem; 530 menuLogHorizontalScrollbar: TMenuItem;
531 actBatchInOneGo: TAction; 531 actBatchInOneGo: TAction;
532 Runbatchinonego1: TMenuItem; 532 Runbatchinonego1: TMenuItem;
533 actSingleQueries: TAction; 533 actSingleQueries: TAction;
534 Sendqueriesonebyone1: TMenuItem; 534 Sendqueriesonebyone1: TMenuItem;
535 N3: TMenuItem; 535 N3: TMenuItem;
536 btnCancelOperation: TToolButton; 536 btnCancelOperation: TToolButton;
537 actCancelOperation: TAction; 537 actCancelOperation: TAction;
538 actToggleComment: TAction; 538 actToggleComment: TAction;
539 Uncomment1: TMenuItem; 539 Uncomment1: TMenuItem;
540 actSynchronizeDatabase: TAction; 540 actSynchronizeDatabase: TAction;
541 Disconnect1: TMenuItem; 541 Disconnect1: TMenuItem;
542 N4: TMenuItem; 542 N4: TMenuItem;
543 ImportCSVfile1: TMenuItem; 543 ImportCSVfile1: TMenuItem;
544 LoadSQLfile1: TMenuItem; 544 LoadSQLfile1: TMenuItem;
545 InsertfilesintoTEXTBLOBfields1: TMenuItem; 545 InsertfilesintoTEXTBLOBfields1: TMenuItem;
546 N9: TMenuItem; 546 N9: TMenuItem;
547 ExportdatabaseasSQL1: TMenuItem; 547 ExportdatabaseasSQL1: TMenuItem;
548 Exportgridrows1: TMenuItem; 548 Exportgridrows1: TMenuItem;
549 Synchronizedatabase2: TMenuItem; 549 Synchronizedatabase2: TMenuItem;
550 QF20: TMenuItem; 550 QF20: TMenuItem;
551 DataDefaultValue: TMenuItem; 551 DataDefaultValue: TMenuItem;
552 actLaunchCommandline: TAction; 552 actLaunchCommandline: TAction;
553 Launchcommandline1: TMenuItem; 553 Launchcommandline1: TMenuItem;
554 menuClearQueryHistory: TMenuItem; 554 menuClearQueryHistory: TMenuItem;
555 procedure actCreateDBObjectExecute(Sender: TObject); 555 procedure actCreateDBObjectExecute(Sender: TObject);
556 procedure menuConnectionsPopup(Sender: TObject); 556 procedure menuConnectionsPopup(Sender: TObject);
557 procedure actExitApplicationExecute(Sender: TObject); 557 procedure actExitApplicationExecute(Sender: TObject);
558 procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; 558 procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
559 procedure FormDestroy(Sender: TObject); 559 procedure FormDestroy(Sender: TObject);
560 procedure FormCreate(Sender: TObject); 560 procedure FormCreate(Sender: TObject);
561 procedure Startup; 561 procedure Startup;
562 procedure FormResize(Sender: TObject); 562 procedure FormResize(Sender: TObject);
563 procedure actUserManagerExecute(Sender: TObject); 563 procedure actUserManagerExecute(Sender: TObject);
564 procedure actAboutBoxExecute(Sender: TObject); 564 procedure actAboutBoxExecute(Sender: TObject);
565 procedure actApplyFilterExecute(Sender: TObject); 565 procedure actApplyFilterExecute(Sender: TObject);
566 procedure actClearEditorExecute(Sender: TObject); 566 procedure actClearEditorExecute(Sender: TObject);
567 procedure actTableToolsExecute(Sender: TObject); 567 procedure actTableToolsExecute(Sender: TObject);
568 procedure actPrintListExecute(Sender: TObject); 568 procedure actPrintListExecute(Sender: TObject);
569 procedure actCopyTableExecute(Sender: TObject); 569 procedure actCopyTableExecute(Sender: TObject);
570 procedure ShowStatusMsg(Msg: String=''; PanelNr: Integer=6); 570 procedure ShowStatusMsg(Msg: String=''; PanelNr: Integer=6);
571 procedure actExecuteQueryExecute(Sender: TObject); 571 procedure actExecuteQueryExecute(Sender: TObject);
572 procedure actCreateDatabaseExecute(Sender: TObject); 572 procedure actCreateDatabaseExecute(Sender: TObject);
573 procedure actDataCancelChangesExecute(Sender: TObject); 573 procedure actDataCancelChangesExecute(Sender: TObject);
574 procedure actExportDataExecute(Sender: TObject); 574 procedure actExportDataExecute(Sender: TObject);
575 procedure actDataPreviewExecute(Sender: TObject); 575 procedure actDataPreviewExecute(Sender: TObject);
576 procedure UpdatePreviewPanel; 576 procedure UpdatePreviewPanel;
577 procedure actInsertFilesExecute(Sender: TObject); 577 procedure actInsertFilesExecute(Sender: TObject);
578 procedure actDataDeleteExecute(Sender: TObject); 578 procedure actDataDeleteExecute(Sender: TObject);
579 procedure actDataFirstExecute(Sender: TObject); 579 procedure actDataFirstExecute(Sender: TObject);
580 procedure actDataInsertExecute(Sender: TObject); 580 procedure actDataInsertExecute(Sender: TObject);
581 procedure actDataLastExecute(Sender: TObject); 581 procedure actDataLastExecute(Sender: TObject);
582 procedure actDataPostChangesExecute(Sender: TObject); 582 procedure actDataPostChangesExecute(Sender: TObject);
583 procedure actDropObjectsExecute(Sender: TObject); 583 procedure actDropObjectsExecute(Sender: TObject);
584 procedure actEmptyTablesExecute(Sender: TObject); 584 procedure actEmptyTablesExecute(Sender: TObject);
585 procedure actExportSettingsExecute(Sender: TObject); 585 procedure actExportSettingsExecute(Sender: TObject);
586 procedure actFlushExecute(Sender: TObject); 586 procedure actFlushExecute(Sender: TObject);
587 procedure actImportCSVExecute(Sender: TObject); 587 procedure actImportCSVExecute(Sender: TObject);
588 procedure actImportSettingsExecute(Sender: TObject); 588 procedure actImportSettingsExecute(Sender: TObject);
589 procedure actLoadSQLExecute(Sender: TObject); 589 procedure actLoadSQLExecute(Sender: TObject);
590 procedure actNewWindowExecute(Sender: TObject); 590 procedure actNewWindowExecute(Sender: TObject);
591 procedure actSessionManagerExecute(Sender: TObject); 591 procedure actSessionManagerExecute(Sender: TObject);
592 procedure actPreferencesExecute(Sender: TObject); 592 procedure actPreferencesExecute(Sender: TObject);
593 procedure actQueryFindReplaceExecute(Sender: TObject); 593 procedure actQueryFindReplaceExecute(Sender: TObject);
594 procedure actQueryStopOnErrorsExecute(Sender: TObject); 594 procedure actQueryStopOnErrorsExecute(Sender: TObject);
595 procedure actQueryWordWrapExecute(Sender: TObject); 595 procedure actQueryWordWrapExecute(Sender: TObject);
596 procedure actReadmeExecute(Sender: TObject); 596 procedure actReadmeExecute(Sender: TObject);
597 procedure actRefreshExecute(Sender: TObject); 597 procedure actRefreshExecute(Sender: TObject);
598 procedure actRemoveFilterExecute(Sender: TObject); 598 procedure actRemoveFilterExecute(Sender: TObject);
599 procedure actSaveSQLExecute(Sender: TObject); 599 procedure actSaveSQLExecute(Sender: TObject);
600 procedure actSaveSQLAsExecute(Sender: TObject); 600 procedure actSaveSQLAsExecute(Sender: TObject);
601 procedure actSaveSQLSnippetExecute(Sender: TObject); 601 procedure actSaveSQLSnippetExecute(Sender: TObject);
602 procedure actSetDelimiterExecute(Sender: TObject); 602 procedure actSetDelimiterExecute(Sender: TObject);
603 procedure actSQLhelpExecute(Sender: TObject); 603 procedure actSQLhelpExecute(Sender: TObject);
604 procedure actUpdateCheckExecute(Sender: TObject); 604 procedure actUpdateCheckExecute(Sender: TObject);
605 procedure actWebbrowse(Sender: TObject); 605 procedure actWebbrowse(Sender: TObject);
606 procedure actSelectTreeBackgroundExecute(Sender: TObject); 606 procedure actSelectTreeBackgroundExecute(Sender: TObject);
607 procedure popupQueryPopup(Sender: TObject); 607 procedure popupQueryPopup(Sender: TObject);
608 procedure btnDataClick(Sender: TObject); 608 procedure btnDataClick(Sender: TObject);
609 procedure ListTablesChange(Sender: TBaseVirtualTree; Node: PVirtualNode); 609 procedure ListTablesChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
610 procedure SynCompletionProposalAfterCodeCompletion(Sender: TObject; 610 procedure SynCompletionProposalAfterCodeCompletion(Sender: TObject;
611 const Value: String; Shift: TShiftState; Index: Integer; EndToken: Char); 611 const Value: String; Shift: TShiftState; Index: Integer; EndToken: Char);
612 procedure SynCompletionProposalCodeCompletion(Sender: TObject; 612 procedure SynCompletionProposalCodeCompletion(Sender: TObject;
613 var Value: String; Shift: TShiftState; Index: Integer; EndToken: Char); 613 var Value: String; Shift: TShiftState; Index: Integer; EndToken: Char);
614 procedure SynCompletionProposalExecute(Kind: SynCompletionType; 614 procedure SynCompletionProposalExecute(Kind: SynCompletionType;
615 Sender: TObject; var CurrentInput: String; var x, y: Integer; 615 Sender: TObject; var CurrentInput: String; var x, y: Integer;
616 var CanExecute: Boolean); 616 var CanExecute: Boolean);
617 procedure ParameterCompletionProposalExecute(Kind: SynCompletionType; Sender: TObject; 617 procedure ParameterCompletionProposalExecute(Kind: SynCompletionType; Sender: TObject;
618 var CurrentInput: string; var x, y: Integer; var CanExecute: Boolean); 618 var CurrentInput: string; var x, y: Integer; var CanExecute: Boolean);
619 procedure PageControlMainChange(Sender: TObject); 619 procedure PageControlMainChange(Sender: TObject);
620 procedure PageControlMainChanging(Sender: TObject; var AllowChange: Boolean); 620 procedure PageControlMainChanging(Sender: TObject; var AllowChange: Boolean);
621 procedure PageControlHostChange(Sender: TObject); 621 procedure PageControlHostChange(Sender: TObject);
622 procedure ValidateControls(Sender: TObject); 622 procedure ValidateControls(Sender: TObject);
623 procedure ValidateQueryControls(Sender: TObject); 623 procedure ValidateQueryControls(Sender: TObject);
624 procedure DataGridBeforePaint(Sender: TBaseVirtualTree; 624 procedure DataGridBeforePaint(Sender: TBaseVirtualTree;
625 TargetCanvas: TCanvas); 625 TargetCanvas: TCanvas);
626 procedure LogSQL(Msg: String; Category: TDBLogCategory=lcInfo; Connection: TDBConnection=nil); 626 procedure LogSQL(Msg: String; Category: TDBLogCategory=lcInfo; Connection: TDBConnection=nil);
627 procedure KillProcess(Sender: TObject); 627 procedure KillProcess(Sender: TObject);
628 procedure SynMemoQueryStatusChange(Sender: TObject; Changes: TSynStatusChanges); 628 procedure SynMemoQueryStatusChange(Sender: TObject; Changes: TSynStatusChanges);
629 procedure TimerHostUptimeTimer(Sender: TObject); 629 procedure TimerHostUptimeTimer(Sender: TObject);
630 procedure ListTablesNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; 630 procedure ListTablesNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
631 Column: TColumnIndex; NewText: String); 631 Column: TColumnIndex; NewText: String);
632 procedure TimerConnectedTimer(Sender: TObject); 632 procedure TimerConnectedTimer(Sender: TObject);
633 procedure Clear2Click(Sender: TObject); 633 procedure Clear2Click(Sender: TObject);
634 procedure QuickFilterClick(Sender: TObject); 634 procedure QuickFilterClick(Sender: TObject);
635 procedure AutoRefreshSetInterval(Sender: TObject); 635 procedure AutoRefreshSetInterval(Sender: TObject);
636 procedure AutoRefreshToggle(Sender: TObject); 636 procedure AutoRefreshToggle(Sender: TObject);
637 procedure SynMemoQueryDragOver(Sender, Source: TObject; X, Y: Integer; 637 procedure SynMemoQueryDragOver(Sender, Source: TObject; X, Y: Integer;
638 State: TDragState; var Accept: Boolean); 638 State: TDragState; var Accept: Boolean);
639 procedure SynMemoQueryDragDrop(Sender, Source: TObject; X, Y: Integer); 639 procedure SynMemoQueryDragDrop(Sender, Source: TObject; X, Y: Integer);
640 procedure SynMemoQueryDropFiles(Sender: TObject; X, Y: Integer; AFiles: TStrings); 640 procedure SynMemoQueryDropFiles(Sender: TObject; X, Y: Integer; AFiles: TStrings);
641 procedure popupHostPopup(Sender: TObject); 641 procedure popupHostPopup(Sender: TObject);
642 procedure Saveastextfile1Click(Sender: TObject); 642 procedure Saveastextfile1Click(Sender: TObject);
643 procedure popupDBPopup(Sender: TObject); 643 procedure popupDBPopup(Sender: TObject);
644 procedure popupDataGridPopup(Sender: TObject); 644 procedure popupDataGridPopup(Sender: TObject);
645 procedure QFvaluesClick(Sender: TObject); 645 procedure QFvaluesClick(Sender: TObject);
646 procedure DataInsertValueClick(Sender: TObject); 646 procedure DataInsertValueClick(Sender: TObject);
647 procedure InsertValue(Sender: TObject); 647 procedure InsertValue(Sender: TObject);
648 procedure actDataSetNullExecute(Sender: TObject); 648 procedure actDataSetNullExecute(Sender: TObject);
649 procedure AnyGridCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; 649 procedure AnyGridCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode;
650 Column: TColumnIndex; out EditLink: IVTEditLink); 650 Column: TColumnIndex; out EditLink: IVTEditLink);
651 procedure AnyGridEditCancelled(Sender: TBaseVirtualTree; Column: TColumnIndex); 651 procedure AnyGridEditCancelled(Sender: TBaseVirtualTree; Column: TColumnIndex);
652 procedure AnyGridEdited(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: 652 procedure AnyGridEdited(Sender: TBaseVirtualTree; Node: PVirtualNode; Column:
653 TColumnIndex); 653 TColumnIndex);
654 procedure AnyGridEditing(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: 654 procedure AnyGridEditing(Sender: TBaseVirtualTree; Node: PVirtualNode; Column:
655 TColumnIndex; var Allowed: Boolean); 655 TColumnIndex; var Allowed: Boolean);
656 procedure AnyGridFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: 656 procedure AnyGridFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode:
657 PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); 657 PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean);
658 procedure AnyGridGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: 658 procedure AnyGridGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column:
659 TColumnIndex; TextType: TVSTTextType; var CellText: String); 659 TColumnIndex; TextType: TVSTTextType; var CellText: String);
660 procedure DataGridHeaderClick(Sender: TVTHeader; HitInfo: TVTHeaderHitInfo); 660 procedure DataGridHeaderClick(Sender: TVTHeader; HitInfo: TVTHeaderHitInfo);
661 procedure AnyGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 661 procedure AnyGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
662 procedure AnyGridMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; 662 procedure AnyGridMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer;
663 MousePos: TPoint; var Handled: Boolean); 663 MousePos: TPoint; var Handled: Boolean);
664 procedure AnyGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: 664 procedure AnyGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column:
665 TColumnIndex; NewText: String); 665 TColumnIndex; NewText: String);
666 procedure AnyGridPaintText(Sender: TBaseVirtualTree; const TargetCanvas: 666 procedure AnyGridPaintText(Sender: TBaseVirtualTree; const TargetCanvas:
667 TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); 667 TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
668 procedure menuDeleteSnippetClick(Sender: TObject); 668 procedure menuDeleteSnippetClick(Sender: TObject);
669 procedure menuExploreClick(Sender: TObject); 669 procedure menuExploreClick(Sender: TObject);
670 procedure menuInsertSnippetAtCursorClick(Sender: TObject); 670 procedure menuInsertSnippetAtCursorClick(Sender: TObject);
671 procedure menuLoadSnippetClick(Sender: TObject); 671 procedure menuLoadSnippetClick(Sender: TObject);
672 procedure AnyGridHeaderClick(Sender: TVTHeader; HitInfo: TVTHeaderHitInfo); 672 procedure AnyGridHeaderClick(Sender: TVTHeader; HitInfo: TVTHeaderHitInfo);
673 procedure AnyGridCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: 673 procedure AnyGridCompareNodes(Sender: TBaseVirtualTree; Node1, Node2:
674 PVirtualNode; Column: TColumnIndex; var Result: Integer); 674 PVirtualNode; Column: TColumnIndex; var Result: Integer);
675 procedure AnyGridHeaderDraggedOut(Sender: TVTHeader; Column: TColumnIndex; 675 procedure AnyGridHeaderDraggedOut(Sender: TVTHeader; Column: TColumnIndex;
676 DropPosition: TPoint); 676 DropPosition: TPoint);
677 procedure AnyGridIncrementalSearch(Sender: TBaseVirtualTree; Node: PVirtualNode; const SearchText: String; 677 procedure AnyGridIncrementalSearch(Sender: TBaseVirtualTree; Node: PVirtualNode; const SearchText: String;
678 var Result: Integer); 678 var Result: Integer);
679 procedure SetMainTab(Page: TTabSheet); 679 procedure SetMainTab(Page: TTabSheet);
680 procedure DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; 680 procedure DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
681 Column: TColumnIndex); 681 Column: TColumnIndex);
682 procedure DBtreeDblClick(Sender: TObject); 682 procedure DBtreeDblClick(Sender: TObject);
683 procedure DBtreeGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; 683 procedure DBtreeGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
684 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var 684 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var
685 ImageIndex: Integer); 685 ImageIndex: Integer);
686 procedure DBtreeGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: 686 procedure DBtreeGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize:
687 Integer); 687 Integer);
688 procedure DBtreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: 688 procedure DBtreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column:
689 TColumnIndex; TextType: TVSTTextType; var CellText: String); 689 TColumnIndex; TextType: TVSTTextType; var CellText: String);
690 procedure DBtreeInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var 690 procedure DBtreeInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var
691 ChildCount: Cardinal); 691 ChildCount: Cardinal);
692 procedure DBtreeInitNode(Sender: TBaseVirtualTree; ParentNode, Node: 692 procedure DBtreeInitNode(Sender: TBaseVirtualTree; ParentNode, Node:
693 PVirtualNode; var InitialStates: TVirtualNodeInitStates); 693 PVirtualNode; var InitialStates: TVirtualNodeInitStates);
694 procedure DBtreePaintText(Sender: TBaseVirtualTree; const TargetCanvas: 694 procedure DBtreePaintText(Sender: TBaseVirtualTree; const TargetCanvas:
695 TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); 695 TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
696 procedure editFilterSearchChange(Sender: TObject); 696 procedure editFilterSearchChange(Sender: TObject);
697 procedure editFilterSearchEnter(Sender: TObject); 697 procedure editFilterSearchEnter(Sender: TObject);
698 procedure editFilterSearchExit(Sender: TObject); 698 procedure editFilterSearchExit(Sender: TObject);
699 procedure menuLogToFileClick(Sender: TObject); 699 procedure menuLogToFileClick(Sender: TObject);
700 procedure menuOpenLogFolderClick(Sender: TObject); 700 procedure menuOpenLogFolderClick(Sender: TObject);
701 procedure AnyGridGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; 701 procedure AnyGridGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode;
702 Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var 702 Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var
703 HintText: String); 703 HintText: String);
704 procedure ListTablesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; 704 procedure ListTablesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;
705 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; 705 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
706 var ContentRect: TRect); 706 var ContentRect: TRect);
707 procedure ListProcessesFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); 707 procedure ListProcessesFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
708 procedure editFilterVTChange(Sender: TObject); 708 procedure editFilterVTChange(Sender: TObject);
709 procedure ListVariablesDblClick(Sender: TObject); 709 procedure ListVariablesDblClick(Sender: TObject);
710 procedure menuEditVariableClick(Sender: TObject); 710 procedure menuEditVariableClick(Sender: TObject);
711 procedure menuTreeCollapseAllClick(Sender: TObject); 711 procedure menuTreeCollapseAllClick(Sender: TObject);
712 procedure menuTreeExpandAllClick(Sender: TObject); 712 procedure menuTreeExpandAllClick(Sender: TObject);
713 procedure SynMemoFilterStatusChange(Sender: TObject; Changes: TSynStatusChanges); 713 procedure SynMemoFilterStatusChange(Sender: TObject; Changes: TSynStatusChanges);
714 procedure AnyGridAfterCellPaint(Sender: TBaseVirtualTree; 714 procedure AnyGridAfterCellPaint(Sender: TBaseVirtualTree;
715 TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; 715 TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
716 CellRect: TRect); 716 CellRect: TRect);
717 procedure menuShowSizeColumnClick(Sender: TObject); 717 procedure menuShowSizeColumnClick(Sender: TObject);
718 procedure AnyGridBeforeCellPaint(Sender: TBaseVirtualTree; 718 procedure AnyGridBeforeCellPaint(Sender: TBaseVirtualTree;
719 TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; 719 TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
720 CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); 720 CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
721 procedure pnlQueryMemoCanResize(Sender: TObject; var NewWidth, 721 procedure pnlQueryMemoCanResize(Sender: TObject; var NewWidth,
722 NewHeight: Integer; var Resize: Boolean); 722 NewHeight: Integer; var Resize: Boolean);
723 procedure AnyGridMouseUp(Sender: TObject; Button: TMouseButton; 723 procedure AnyGridMouseUp(Sender: TObject; Button: TMouseButton;
724 Shift: TShiftState; X, Y: Integer); 724 Shift: TShiftState; X, Y: Integer);
725 procedure File1Click(Sender: TObject); 725 procedure File1Click(Sender: TObject);
726 procedure HostListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; 726 procedure HostListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
727 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); 727 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
728 procedure HostListGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; 728 procedure HostListGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
729 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer); 729 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
730 procedure HostListBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas); 730 procedure HostListBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
731 procedure HostListBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; 731 procedure HostListBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;
732 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; 732 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
733 var ContentRect: TRect); 733 var ContentRect: TRect);
734 procedure ListTablesBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas); 734 procedure ListTablesBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
735 procedure ListTablesGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; 735 procedure ListTablesGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind;
736 Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer); 736 Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
737 procedure ListTablesGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer); 737 procedure ListTablesGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
738 procedure ListTablesGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; 738 procedure ListTablesGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
739 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); 739 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
740 procedure ListTablesInitNode(Sender: TBaseVirtualTree; ParentNode, 740 procedure ListTablesInitNode(Sender: TBaseVirtualTree; ParentNode,
741 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); 741 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
742 procedure AnyGridAfterPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas); 742 procedure AnyGridAfterPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
743 procedure actCopyOrCutExecute(Sender: TObject); 743 procedure actCopyOrCutExecute(Sender: TObject);
744 procedure actPasteExecute(Sender: TObject); 744 procedure actPasteExecute(Sender: TObject);
745 procedure actSelectAllExecute(Sender: TObject); 745 procedure actSelectAllExecute(Sender: TObject);
746 procedure EnumerateRecentFilters; 746 procedure EnumerateRecentFilters;
747 procedure LoadRecentFilter(Sender: TObject); 747 procedure LoadRecentFilter(Sender: TObject);
748 procedure ListTablesEditing(Sender: TBaseVirtualTree; Node: PVirtualNode; 748 procedure ListTablesEditing(Sender: TBaseVirtualTree; Node: PVirtualNode;
749 Column: TColumnIndex; var Allowed: Boolean); 749 Column: TColumnIndex; var Allowed: Boolean);
750 procedure DBtreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode); 750 procedure DBtreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
751 procedure ListTablesDblClick(Sender: TObject); 751 procedure ListTablesDblClick(Sender: TObject);
752 procedure panelTopDblClick(Sender: TObject); 752 procedure panelTopDblClick(Sender: TObject);
753 procedure PageControlMainMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 753 procedure PageControlMainMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
754 procedure actNewQueryTabExecute(Sender: TObject); 754 procedure actNewQueryTabExecute(Sender: TObject);
755 procedure actCloseQueryTabExecute(Sender: TObject); 755 procedure actCloseQueryTabExecute(Sender: TObject);
756 procedure menuCloseQueryTab(Sender: TObject); 756 procedure menuCloseQueryTab(Sender: TObject);
757 procedure CloseQueryTab(PageIndex: Integer); 757 procedure CloseQueryTab(PageIndex: Integer);
758 procedure CloseButtonOnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 758 procedure CloseButtonOnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
759 procedure CloseButtonOnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 759 procedure CloseButtonOnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
760 function GetMainTabAt(X, Y: Integer): Integer; 760 function GetMainTabAt(X, Y: Integer): Integer;
761 procedure FixQueryTabCloseButtons; 761 procedure FixQueryTabCloseButtons;
762 function ActiveQueryTab: TQueryTab; 762 function ActiveQueryTab: TQueryTab;
763 function ActiveOrEmptyQueryTab(ConsiderActiveTab: Boolean): TQueryTab; 763 function ActiveOrEmptyQueryTab(ConsiderActiveTab: Boolean): TQueryTab;
764 function GetQueryTabByNumber(Number: Integer): TQueryTab; 764 function GetQueryTabByNumber(Number: Integer): TQueryTab;
765 function GetQueryTabByHelpers(FindTree: TBaseVirtualTree): TQueryTab; 765 function GetQueryTabByHelpers(FindTree: TBaseVirtualTree): TQueryTab;
766 function ActiveQueryMemo: TSynMemo; 766 function ActiveQueryMemo: TSynMemo;
767 function ActiveQueryHelpers: TVirtualStringTree; 767 function ActiveQueryHelpers: TVirtualStringTree;
768 function ActiveSynMemo: TSynMemo; 768 function ActiveSynMemo: TSynMemo;
769 function QueryTabActive: Boolean; 769 function QueryTabActive: Boolean;
770 function IsQueryTab(PageIndex: Integer; IncludeFixed: Boolean): Boolean; 770 function IsQueryTab(PageIndex: Integer; IncludeFixed: Boolean): Boolean;
771 procedure popupMainTabsPopup(Sender: TObject); 771 procedure popupMainTabsPopup(Sender: TObject);
772 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 772 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
773 procedure actFilterPanelExecute(Sender: TObject); 773 procedure actFilterPanelExecute(Sender: TObject);
774 procedure TimerFilterVTTimer(Sender: TObject); 774 procedure TimerFilterVTTimer(Sender: TObject);
775 procedure PageControlMainContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean); 775 procedure PageControlMainContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
776 procedure menuQueryHelpersGenerateStatementClick(Sender: TObject); 776 procedure menuQueryHelpersGenerateStatementClick(Sender: TObject);
777 procedure actSelectInverseExecute(Sender: TObject); 777 procedure actSelectInverseExecute(Sender: TObject);
778 procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; 778 procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
779 var Handled: Boolean); 779 var Handled: Boolean);
780 procedure actDataResetSortingExecute(Sender: TObject); 780 procedure actDataResetSortingExecute(Sender: TObject);
781 procedure actReformatSQLExecute(Sender: TObject); 781 procedure actReformatSQLExecute(Sender: TObject);
782 procedure DBtreeFocusChanging(Sender: TBaseVirtualTree; OldNode, 782 procedure DBtreeFocusChanging(Sender: TBaseVirtualTree; OldNode,
783 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; 783 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
784 var Allowed: Boolean); 784 var Allowed: Boolean);
785 procedure actBlobAsTextExecute(Sender: TObject); 785 procedure actBlobAsTextExecute(Sender: TObject);
786 procedure SynMemoQueryReplaceText(Sender: TObject; const ASearch, 786 procedure SynMemoQueryReplaceText(Sender: TObject; const ASearch,
787 AReplace: string; Line, Column: Integer; var Action: TSynReplaceAction); 787 AReplace: string; Line, Column: Integer; var Action: TSynReplaceAction);
788 procedure SynMemoQueryPaintTransient(Sender: TObject; Canvas: TCanvas; 788 procedure SynMemoQueryPaintTransient(Sender: TObject; Canvas: TCanvas;
789 TransientType: TTransientType); 789 TransientType: TTransientType);
790 procedure actQueryFindAgainExecute(Sender: TObject); 790 procedure actQueryFindAgainExecute(Sender: TObject);
791 procedure AnyGridScroll(Sender: TBaseVirtualTree; DeltaX, DeltaY: Integer); 791 procedure AnyGridScroll(Sender: TBaseVirtualTree; DeltaX, DeltaY: Integer);
792 procedure lblExplainProcessClick(Sender: TObject); 792 procedure lblExplainProcessClick(Sender: TObject);
793 procedure actDataShowNextExecute(Sender: TObject); 793 procedure actDataShowNextExecute(Sender: TObject);
794 procedure actDataShowAllExecute(Sender: TObject); 794 procedure actDataShowAllExecute(Sender: TObject);
795 procedure AnyGridInitNode(Sender: TBaseVirtualTree; ParentNode, 795 procedure AnyGridInitNode(Sender: TBaseVirtualTree; ParentNode,
796 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); 796 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
797 procedure editFilterVTRightButtonClick(Sender: TObject); 797 procedure editFilterVTRightButtonClick(Sender: TObject);
798 procedure AnyGridFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; 798 procedure AnyGridFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
799 Column: TColumnIndex); 799 Column: TColumnIndex);
800 procedure ListTablesKeyPress(Sender: TObject; var Key: Char); 800 procedure ListTablesKeyPress(Sender: TObject; var Key: Char);
801 procedure DBtreeFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode); 801 procedure DBtreeFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
802 procedure ListDatabasesBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas); 802 procedure ListDatabasesBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
803 procedure ListDatabasesGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; 803 procedure ListDatabasesGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
804 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); 804 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
805 procedure ListDatabasesInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode; 805 procedure ListDatabasesInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
806 var InitialStates: TVirtualNodeInitStates); 806 var InitialStates: TVirtualNodeInitStates);
807 procedure ListDatabasesGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer); 807 procedure ListDatabasesGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
808 procedure ListDatabasesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; 808 procedure ListDatabasesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;
809 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; 809 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
810 var ContentRect: TRect); 810 var ContentRect: TRect);
811 procedure menuFetchDBitemsClick(Sender: TObject); 811 procedure menuFetchDBitemsClick(Sender: TObject);
812 procedure ListDatabasesGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; 812 procedure ListDatabasesGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
813 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer); 813 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
814 procedure ListDatabasesDblClick(Sender: TObject); 814 procedure ListDatabasesDblClick(Sender: TObject);
815 procedure actRunRoutinesExecute(Sender: TObject); 815 procedure actRunRoutinesExecute(Sender: TObject);
816 procedure AnyGridGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer); 816 procedure AnyGridGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
817 procedure tabsetQueryClick(Sender: TObject); 817 procedure tabsetQueryClick(Sender: TObject);
818 procedure tabsetQueryGetImageIndex(Sender: TObject; TabIndex: Integer; var ImageIndex: Integer); 818 procedure tabsetQueryGetImageIndex(Sender: TObject; TabIndex: Integer; var ImageIndex: Integer);
819 procedure tabsetQueryMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 819 procedure tabsetQueryMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
820 procedure tabsetQueryMouseLeave(Sender: TObject); 820 procedure tabsetQueryMouseLeave(Sender: TObject);
821 procedure StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect); 821 procedure StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
822 procedure StatusBarMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 822 procedure StatusBarMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
823 procedure StatusBarMouseLeave(Sender: TObject); 823 procedure StatusBarMouseLeave(Sender: TObject);
824 procedure AnyGridStartOperation(Sender: TBaseVirtualTree; OperationKind: TVTOperationKind); 824 procedure AnyGridStartOperation(Sender: TBaseVirtualTree; OperationKind: TVTOperationKind);
825 procedure AnyGridEndOperation(Sender: TBaseVirtualTree; OperationKind: TVTOperationKind); 825 procedure AnyGridEndOperation(Sender: TBaseVirtualTree; OperationKind: TVTOperationKind);
826 procedure actDataPreviewUpdate(Sender: TObject); 826 procedure actDataPreviewUpdate(Sender: TObject);
827 procedure spltPreviewMoved(Sender: TObject); 827 procedure spltPreviewMoved(Sender: TObject);
828 procedure actDataSaveBlobToFileExecute(Sender: TObject); 828 procedure actDataSaveBlobToFileExecute(Sender: TObject);
829 procedure DataGridColumnResize(Sender: TVTHeader; Column: TColumnIndex); 829 procedure DataGridColumnResize(Sender: TVTHeader; Column: TColumnIndex);
830 procedure comboDBFilterChange(Sender: TObject); 830 procedure comboDBFilterChange(Sender: TObject);
831 procedure comboDBFilterExit(Sender: TObject); 831 procedure comboDBFilterExit(Sender: TObject);
832 procedure comboDBFilterDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); 832 procedure comboDBFilterDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
833 procedure comboDBFilterDragDrop(Sender, Source: TObject; X, Y: Integer); 833 procedure comboDBFilterDragDrop(Sender, Source: TObject; X, Y: Integer);
834 procedure comboDBFilterKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 834 procedure comboDBFilterKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
835 procedure DBtreeAfterPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas); 835 procedure DBtreeAfterPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
836 procedure treeQueryHelpersGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; 836 procedure treeQueryHelpersGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
837 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); 837 Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
838 procedure treeQueryHelpersInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode; 838 procedure treeQueryHelpersInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
839 var InitialStates: TVirtualNodeInitStates); 839 var InitialStates: TVirtualNodeInitStates);
840 procedure treeQueryHelpersInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; 840 procedure treeQueryHelpersInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
841 var ChildCount: Cardinal); 841 var ChildCount: Cardinal);
842 procedure treeQueryHelpersGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; 842 procedure treeQueryHelpersGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
843 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer); 843 Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
844 procedure treeQueryHelpersBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; 844 procedure treeQueryHelpersBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;
845 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; 845 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
846 var ContentRect: TRect); 846 var ContentRect: TRect);
847 procedure treeQueryHelpersDblClick(Sender: TObject); 847 procedure treeQueryHelpersDblClick(Sender: TObject);
848 procedure treeQueryHelpersContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean); 848 procedure treeQueryHelpersContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
849 procedure treeQueryHelpersFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode); 849 procedure treeQueryHelpersFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
850 procedure treeQueryHelpersPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; 850 procedure treeQueryHelpersPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas;
851 Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); 851 Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
852 procedure treeQueryHelpersFocusChanging(Sender: TBaseVirtualTree; OldNode, 852 procedure treeQueryHelpersFocusChanging(Sender: TBaseVirtualTree; OldNode,
853 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); 853 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean);
854 procedure treeQueryHelpersResize(Sender: TObject); 854 procedure treeQueryHelpersResize(Sender: TObject);
855 procedure ApplicationEvents1Deactivate(Sender: TObject); 855 procedure ApplicationEvents1Deactivate(Sender: TObject);
856 procedure actDisconnectExecute(Sender: TObject); 856 procedure actDisconnectExecute(Sender: TObject);
857 procedure menuEditObjectClick(Sender: TObject); 857 procedure menuEditObjectClick(Sender: TObject);
858 procedure Copylinetonewquerytab1Click(Sender: TObject); 858 procedure Copylinetonewquerytab1Click(Sender: TObject);
859 procedure menuLogHorizontalScrollbarClick(Sender: TObject); 859 procedure menuLogHorizontalScrollbarClick(Sender: TObject);
860 procedure actBatchInOneGoExecute(Sender: TObject); 860 procedure actBatchInOneGoExecute(Sender: TObject);
861 procedure actCancelOperationExecute(Sender: TObject); 861 procedure actCancelOperationExecute(Sender: TObject);
862 procedure AnyGridChange(Sender: TBaseVirtualTree; Node: PVirtualNode); 862 procedure AnyGridChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
863 procedure actToggleCommentExecute(Sender: TObject); 863 procedure actToggleCommentExecute(Sender: TObject);
864 procedure actSynchronizeDatabaseExecute(Sender: TObject); 864 procedure actSynchronizeDatabaseExecute(Sender: TObject);
865 procedure DBtreeBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; 865 procedure DBtreeBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;
866 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; 866 Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
867 var ContentRect: TRect); 867 var ContentRect: TRect);
868 procedure actLaunchCommandlineExecute(Sender: TObject); 868 procedure actLaunchCommandlineExecute(Sender: TObject);
869 procedure menuClearQueryHistoryClick(Sender: TObject); 869 procedure menuClearQueryHistoryClick(Sender: TObject);
870 private 870 private
871 FLastHintMousepos: TPoint; 871 FLastHintMousepos: TPoint;
872 FLastHintControlIndex: Integer; 872 FLastHintControlIndex: Integer;
873 FDelimiter: String; 873 FDelimiter: String;
874 FFileNameSessionLog: String; 874 FFileNameSessionLog: String;
875 FFileHandleSessionLog: Textfile; 875 FFileHandleSessionLog: Textfile;
876 FLastMouseUpOnPageControl: Cardinal; 876 FLastMouseUpOnPageControl: Cardinal;
877 FLastTabNumberOnMouseUp: Integer; 877 FLastTabNumberOnMouseUp: Integer;
878 FLastMouseDownCloseButton: TObject; 878 FLastMouseDownCloseButton: TObject;
879 // Filter text per tab for filter panel 879 // Filter text per tab for filter panel
880 FFilterTextDatabases, 880 FFilterTextDatabases,
881 FFilterTextEditor, 881 FFilterTextEditor,
882 FFilterTextVariables, 882 FFilterTextVariables,
883 FFilterTextStatus, 883 FFilterTextStatus,
884 FFilterTextProcessList, 884 FFilterTextProcessList,
885 FFilterTextCommandStats, 885 FFilterTextCommandStats,
886 FFilterTextDatabase, 886 FFilterTextDatabase,
887 FFilterTextData: String; 887 FFilterTextData: String;
888 FTreeRefreshInProgress: Boolean; 888 FTreeRefreshInProgress: Boolean;
889 FCmdlineFilenames: TStringlist; 889 FCmdlineFilenames: TStringlist;
890 FCmdlineConnectionParams: TConnectionParameters; 890 FCmdlineConnectionParams: TConnectionParameters;
891 FSearchReplaceExecuted: Boolean; 891 FSearchReplaceExecuted: Boolean;
892 FDataGridColumnWidthsCustomized: Boolean; 892 FDataGridColumnWidthsCustomized: Boolean;
893 FSnippetFilenames: TStringList; 893 FSnippetFilenames: TStringList;
894 FConnections: TDBConnectionList; 894 FConnections: TDBConnectionList;
895 FTreeClickHistory: TNodeArray; 895 FTreeClickHistory: TNodeArray;
896 FOperationTicker: Cardinal; 896 FOperationTicker: Cardinal;
897 FOperatingGrid: TBaseVirtualTree; 897 FOperatingGrid: TBaseVirtualTree;
898 FActiveDbObj: TDBObject; 898 FActiveDbObj: TDBObject;
899 FIsWine: Boolean; 899 FIsWine: Boolean;
900 FBtnAddTab: TSpeedButton; 900 FBtnAddTab: TSpeedButton;
901 FDBObjectsMaxSize: Int64; 901 FDBObjectsMaxSize: Int64;
902 FDBObjectsMaxRows: Int64; 902 FDBObjectsMaxRows: Int64;
903 FSearchReplaceDialog: TfrmSearchReplace; 903 FSearchReplaceDialog: TfrmSearchReplace;
904 FPreferencesDialog: Toptionsform; 904 FPreferencesDialog: Toptionsform;
905 905
906 // Host subtabs backend structures 906 // Host subtabs backend structures
907 FHostListResults: TDBQueryList; 907 FHostListResults: TDBQueryList;
908 FHostTabCaptions: TStringList; 908 FHostTabCaptions: TStringList;
909 FStatusServerUptime: Integer; 909 FStatusServerUptime: Integer;
910 FProcessListMaxTime: Int64; 910 FProcessListMaxTime: Int64;
911 FCommandStatsQueryCount: Int64; 911 FCommandStatsQueryCount: Int64;
912 FCommandStatsServerUptime: Integer; 912 FCommandStatsServerUptime: Integer;
913 913
914 // Common directories 914 // Common directories
915 FDirnameCommonAppData: String; 915 FDirnameCommonAppData: String;
916 FDirnameUserAppData: String; 916 FDirnameUserAppData: String;
917 FDirnameSnippets: String; 917 FDirnameSnippets: String;
918 918
919 procedure ParseCommandLineParameters(Parameters: TStringlist); 919 procedure ParseCommandLineParameters(Parameters: TStringlist);
920 procedure SetDelimiter(Value: String); 920 procedure SetDelimiter(Value: String);
921 procedure DisplayRowCountStats(Sender: TBaseVirtualTree); 921 procedure DisplayRowCountStats(Sender: TBaseVirtualTree);
922 procedure insertFunction(Sender: TObject); 922 procedure insertFunction(Sender: TObject);
923 function GetActiveConnection: TDBConnection; 923 function GetActiveConnection: TDBConnection;
924 function GetActiveDatabase: String; 924 function GetActiveDatabase: String;
925 procedure SetActiveDatabase(db: String; Connection: TDBConnection); 925 procedure SetActiveDatabase(db: String; Connection: TDBConnection);
926 procedure SetActiveDBObj(Obj: TDBObject); 926 procedure SetActiveDBObj(Obj: TDBObject);
927 procedure ToggleFilterPanel(ForceVisible: Boolean = False); 927 procedure ToggleFilterPanel(ForceVisible: Boolean = False);
928 procedure AutoCalcColWidth(Tree: TVirtualStringTree; Column: TColumnIndex); 928 procedure AutoCalcColWidth(Tree: TVirtualStringTree; Column: TColumnIndex);
929 procedure PlaceObjectEditor(Obj: TDBObject); 929 procedure PlaceObjectEditor(Obj: TDBObject);
930 procedure SetTabCaption(PageIndex: Integer; Text: String); 930 procedure SetTabCaption(PageIndex: Integer; Text: String);
931 function ConfirmTabClose(PageIndex: Integer): Boolean; 931 function ConfirmTabClose(PageIndex: Integer): Boolean;
932 procedure UpdateFilterPanel(Sender: TObject); 932 procedure UpdateFilterPanel(Sender: TObject);
933 procedure ConnectionReady(Connection: TDBConnection; Database: String); 933 procedure ConnectionReady(Connection: TDBConnection; Database: String);
934 procedure DBObjectsCleared(Connection: TDBConnection; Database: String); 934 procedure DBObjectsCleared(Connection: TDBConnection; Database: String);
935 procedure DatabaseChanged(Connection: TDBConnection; Database: String); 935 procedure DatabaseChanged(Connection: TDBConnection; Database: String);
936 procedure DoSearchReplace; 936 procedure DoSearchReplace;
937 procedure UpdateLineCharPanel; 937 procedure UpdateLineCharPanel;
938 procedure SetSnippetFilenames; 938 procedure SetSnippetFilenames;
939 function TreeClickHistoryPrevious(MayBeNil: Boolean=False): PVirtualNode; 939 function TreeClickHistoryPrevious(MayBeNil: Boolean=False): PVirtualNode;
940 procedure OperationRunning(Runs: Boolean); 940 procedure OperationRunning(Runs: Boolean);
941 function RunQueryFiles(Filenames: TStrings; Encoding: TEncoding): Boolean; 941 function RunQueryFiles(Filenames: TStrings; Encoding: TEncoding): Boolean;
942 public 942 public
943 QueryTabs: TObjectList<TQueryTab>; 943 QueryTabs: TObjectList<TQueryTab>;
944 ActiveObjectEditor: TDBObjectEditor; 944 ActiveObjectEditor: TDBObjectEditor;
945 FileEncodings: TStringList; 945 FileEncodings: TStringList;
946 946
947 // Variables set by preferences dialog 947 // Variables set by preferences dialog
948 prefRememberFilters: Boolean; 948 prefRememberFilters: Boolean;
949 prefLogsqlnum: Integer; 949 prefLogsqlnum: Integer;
950 prefLogSqlWidth: Integer; 950 prefLogSqlWidth: Integer;
951 prefDirnameSessionLogs: String; 951 prefDirnameSessionLogs: String;
952 prefMaxColWidth: Integer; 952 prefMaxColWidth: Integer;
953 prefGridRowcountStep: Integer; 953 prefGridRowcountStep: Integer;
954 prefGridRowcountMax: Integer; 954 prefGridRowcountMax: Integer;
955 prefGridRowsLineCount: Word; 955 prefGridRowsLineCount: Word;
956 prefLogToFile: Boolean; 956 prefLogToFile: Boolean;
957 prefLogErrors: Boolean; 957 prefLogErrors: Boolean;
958 prefLogUserSQL: Boolean; 958 prefLogUserSQL: Boolean;
959 prefLogSQL: Boolean; 959 prefLogSQL: Boolean;
960 prefLogInfos: Boolean; 960 prefLogInfos: Boolean;
961 prefLogDebug: Boolean; 961 prefLogDebug: Boolean;
962 prefEnableBinaryEditor: Boolean; 962 prefEnableBinaryEditor: Boolean;
963 prefEnableDatetimeEditor: Boolean; 963 prefEnableDatetimeEditor: Boolean;
964 prefPrefillDateTime: Boolean; 964 prefPrefillDateTime: Boolean;
965 prefEnableEnumEditor: Boolean; 965 prefEnableEnumEditor: Boolean;
966 prefEnableSetEditor: Boolean; 966 prefEnableSetEditor: Boolean;
967 prefNullColorDefault: TColor; 967 prefNullColorDefault: TColor;
968 prefNullBG: TColor; 968 prefNullBG: TColor;
969 prefDisplayBars: Boolean; 969 prefDisplayBars: Boolean;
970 prefBarColor: TColor; 970 prefBarColor: TColor;
971 prefCompletionProposal: Boolean; 971 prefCompletionProposal: Boolean;
972 prefMaxQueryResults: Integer; 972 prefMaxQueryResults: Integer;
973 973
974 // Data grid related stuff 974 // Data grid related stuff
975 DataGridHiddenColumns: TStringList; 975 DataGridHiddenColumns: TStringList;
976 DataGridSortColumns: TOrderColArray; 976 DataGridSortColumns: TOrderColArray;
977 DataGridWantedRowCount: Int64; 977 DataGridWantedRowCount: Int64;
978 DataGridDB: String; 978 DataGridDB: String;
979 DataGridTable: String; 979 DataGridTable: String;
980 DataGridFocusedCell: TStringList; 980 DataGridFocusedCell: TStringList;
981 DataGridFocusedNodeIndex: Int64; 981 DataGridFocusedNodeIndex: Int64;
982 DataGridFocusedColumnName: String; 982 DataGridFocusedColumnName: String;
983 DataGridResult: TDBQuery; 983 DataGridResult: TDBQuery;
984 DataGridFullRowMode: Boolean; 984 DataGridFullRowMode: Boolean;
985 SelectedTableColumns: TTableColumnList; 985 SelectedTableColumns: TTableColumnList;
986 SelectedTableKeys: TTableKeyList; 986 SelectedTableKeys: TTableKeyList;
987 SelectedTableForeignKeys: TForeignKeyList; 987 SelectedTableForeignKeys: TForeignKeyList;
988 FilterPanelManuallyOpened: Boolean; 988 FilterPanelManuallyOpened: Boolean;
989 989
990 // Executable file details 990 // Executable file details
991 AppVerMajor: Integer; 991 AppVerMajor: Integer;
992 AppVerMinor: Integer; 992 AppVerMinor: Integer;
993 AppVerRelease: Integer; 993 AppVerRelease: Integer;
994 AppVerRevision: Integer; 994 AppVerRevision: Integer;
995 AppVersion: String; 995 AppVersion: String;
996 AppDescription: String; 996 AppDescription: String;
997 997
998 // Task button interface 998 // Task button interface
999 TaskbarList: ITaskbarList; 999 TaskbarList: ITaskbarList;
1000 TaskbarList2: ITaskbarList2; 1000 TaskbarList2: ITaskbarList2;
1001 TaskbarList3: ITaskbarList3; 1001 TaskbarList3: ITaskbarList3;
1002 TaskbarList4: ITaskbarList4; 1002 TaskbarList4: ITaskbarList4;
1003 1003
1004 property Connections: TDBConnectionList read FConnections; 1004 property Connections: TDBConnectionList read FConnections;
1005 property Delimiter: String read FDelimiter write SetDelimiter; 1005 property Delimiter: String read FDelimiter write SetDelimiter;
1006 property IsWine: Boolean read FIsWine; 1006 property IsWine: Boolean read FIsWine;
1007 procedure PaintColorBar(Value, Max: Extended; TargetCanvas: TCanvas; CellRect: TRect); 1007 procedure PaintColorBar(Value, Max: Extended; TargetCanvas: TCanvas; CellRect: TRect);
1008 procedure CallSQLHelpWithKeyword( keyword: String ); 1008 procedure CallSQLHelpWithKeyword( keyword: String );
1009 procedure AddOrRemoveFromQueryLoadHistory(Filename: String; AddIt: Boolean; CheckIfFileExists: Boolean); 1009 procedure AddOrRemoveFromQueryLoadHistory(Filename: String; AddIt: Boolean; CheckIfFileExists: Boolean);
1010 procedure popupQueryLoadClick( sender: TObject ); 1010 procedure popupQueryLoadClick( sender: TObject );
1011 procedure FillPopupQueryLoad; 1011 procedure FillPopupQueryLoad;
1012 procedure PopupQueryLoadRemoveAbsentFiles(Sender: TObject); 1012 procedure PopupQueryLoadRemoveAbsentFiles(Sender: TObject);
1013 procedure PopupQueryLoadRemoveAllFiles(Sender: TObject); 1013 procedure PopupQueryLoadRemoveAllFiles(Sender: TObject);
1014 procedure SessionConnect(Sender: TObject); 1014 procedure SessionConnect(Sender: TObject);
1015 function InitConnection(Params: TConnectionParameters; ActivateMe: Boolean; var Connection: TDBConnection): Boolean; 1015 function InitConnection(Params: TConnectionParameters; ActivateMe: Boolean; var Connection: TDBConnection): Boolean;
1016 procedure ConnectionsNotify(Sender: TObject; const Item: TDBConnection; Action: TCollectionNotification); 1016 procedure ConnectionsNotify(Sender: TObject; const Item: TDBConnection; Action: TCollectionNotification);
1017 function ActiveGrid: TVirtualStringTree; 1017 function ActiveGrid: TVirtualStringTree;
1018 function GridResult(Grid: TBaseVirtualTree): TDBQuery; 1018 function GridResult(Grid: TBaseVirtualTree): TDBQuery;
1019 property ActiveConnection: TDBConnection read GetActiveConnection; 1019 property ActiveConnection: TDBConnection read GetActiveConnection;
1020 property ActiveDatabase: String read GetActiveDatabase; 1020 property ActiveDatabase: String read GetActiveDatabase;
1021 property ActiveDbObj: TDBObject read FActiveDbObj write SetActiveDBObj; 1021 property ActiveDbObj: TDBObject read FActiveDbObj write SetActiveDBObj;
1022 procedure ActivateFileLogging; 1022 procedure ActivateFileLogging;
1023 procedure DeactivateFileLogging; 1023 procedure DeactivateFileLogging;
1024 procedure RefreshTree(FocusNewObject: TDBObject=nil); 1024 procedure RefreshTree(FocusNewObject: TDBObject=nil);
1025 function GetRootNode(Tree: TBaseVirtualTree; Connection: TDBConnection): PVirtualNode; 1025 function GetRootNode(Tree: TBaseVirtualTree; Connection: TDBConnection): PVirtualNode;
1026 function FindDBObjectNode(Tree: TBaseVirtualTree; Obj: TDBObject): PVirtualNode; 1026 function FindDBObjectNode(Tree: TBaseVirtualTree; Obj: TDBObject): PVirtualNode;
1027 function FindDBNode(Tree: TBaseVirtualTree; Connection: TDBConnection; db: String): PVirtualNode; 1027 function FindDBNode(Tree: TBaseVirtualTree; Connection: TDBConnection; db: String): PVirtualNode;
1028 procedure CalcNullColors; 1028 procedure CalcNullColors;
1029 procedure HandleDataGridAttributes(RefreshingData: Boolean); 1029 procedure HandleDataGridAttributes(RefreshingData: Boolean);
1030 function GetRegKeyTable: String; 1030 function GetRegKeyTable: String;
1031 procedure SaveListSetup( List: TVirtualStringTree ); 1031 procedure SaveListSetup( List: TVirtualStringTree );
1032 procedure RestoreListSetup( List: TVirtualStringTree ); 1032 procedure RestoreListSetup( List: TVirtualStringTree );
1033 procedure UpdateEditorTab; 1033 procedure UpdateEditorTab;
1034 procedure SetWindowCaption; 1034 procedure SetWindowCaption;
1035 procedure OnMessageHandler(var Msg: TMsg; var Handled: Boolean); 1035 procedure OnMessageHandler(var Msg: TMsg; var Handled: Boolean);
1036 procedure DefaultHandler(var Message); override; 1036 procedure DefaultHandler(var Message); override;
1037 procedure SetupSynEditors; 1037 procedure SetupSynEditors;
1038 function AnyGridEnsureFullRow(Grid: TVirtualStringTree; Node: PVirtualNode): Boolean; 1038 function AnyGridEnsureFullRow(Grid: TVirtualStringTree; Node: PVirtualNode): Boolean;
1039 procedure DataGridEnsureFullRows(Grid: TVirtualStringTree; SelectedOnly: Boolean); 1039 procedure DataGridEnsureFullRows(Grid: TVirtualStringTree; SelectedOnly: Boolean);
1040 function GetEncodingByName(Name: String): TEncoding; 1040 function GetEncodingByName(Name: String): TEncoding;
1041 function GetEncodingName(Encoding: TEncoding): String; 1041 function GetEncodingName(Encoding: TEncoding): String;
1042 function GetCharsetByEncoding(Encoding: TEncoding): String; 1042 function GetCharsetByEncoding(Encoding: TEncoding): String;
1043 procedure RefreshHelperNode(NodeIndex: Cardinal); 1043 procedure RefreshHelperNode(NodeIndex: Cardinal);
1044 procedure BeforeQueryExecution(Thread: TQueryThread); 1044 procedure BeforeQueryExecution(Thread: TQueryThread);
1045 procedure AfterQueryExecution(Thread: TQueryThread); 1045 procedure AfterQueryExecution(Thread: TQueryThread);
1046 procedure FinishedQueryExecution(Thread: TQueryThread); 1046 procedure FinishedQueryExecution(Thread: TQueryThread);
1047 procedure EnableProgress(MaxValue: Integer); 1047 procedure EnableProgress(MaxValue: Integer);
1048 procedure DisableProgress; 1048 procedure DisableProgress;
1049 procedure SetProgressPosition(Value: Integer); 1049 procedure SetProgressPosition(Value: Integer);
1050 procedure ProgressStep; 1050 procedure ProgressStep;
1051 procedure SetProgressState(State: TProgressbarState); 1051 procedure SetProgressState(State: TProgressbarState);
1052 end; 1052 end;
1053 1053
1054 1054
1055 var 1055 var
1056 MainForm: TMainForm; 1056 MainForm: TMainForm;
1057 SecondInstMsgId: UINT = 0; 1057 SecondInstMsgId: UINT = 0;
1058 1058
1059 const 1059 const
1060 // Customized messages 1060 // Customized messages
1061 MSG_UPDATECHECK = WM_USER + 1; 1061 MSG_UPDATECHECK = WM_USER + 1;
1062 MSG_PREFERENCES = WM_USER + 2; 1062 MSG_PREFERENCES = WM_USER + 2;
1063 MSG_ABOUT = WM_USER + 3; 1063 MSG_ABOUT = WM_USER + 3;
1064 CheckedStates = [csCheckedNormal, csCheckedPressed, csMixedNormal, csMixedPressed]; 1064 CheckedStates = [csCheckedNormal, csCheckedPressed, csMixedNormal, csMixedPressed];
1065 1065
1066 {$I const.inc} 1066 {$I const.inc}
1067 1067
1068 1068
1069 implementation 1069 implementation
1070 1070
1071 uses 1071 uses
1072 About, printlist, mysql_structures, UpdateCheck, runsqlfile, 1072 About, printlist, mysql_structures, UpdateCheck, runsqlfile,
1073 column_selection, data_sorting, grideditlinks, ExportGrid, jpeg, GIFImg; 1073 column_selection, data_sorting, grideditlinks, ExportGrid, jpeg, GIFImg;
1074 1074
1075 1075
1076 1076
1077 {$R *.DFM} 1077 {$R *.DFM}
1078 1078
1079 1079
1080 procedure TMainForm.ShowStatusMsg(Msg: String=''; PanelNr: Integer=6); 1080 procedure TMainForm.ShowStatusMsg(Msg: String=''; PanelNr: Integer=6);
1081 var 1081 var
1082 PanelRect: TRect; 1082 PanelRect: TRect;
1083 begin 1083 begin
1084 // Show message in some statusbar panel 1084 // Show message in some statusbar panel
1085 if (PanelNr = 6) and (Msg = '') then 1085 if (PanelNr = 6) and (Msg = '') then
1086 Msg := SIdle; 1086 Msg := SIdle;
1087 if Msg <> StatusBar.Panels[PanelNr].Text then begin 1087 if Msg <> StatusBar.Panels[PanelNr].Text then begin
1088 StatusBar.Panels[PanelNr].Text := Msg; 1088 StatusBar.Panels[PanelNr].Text := Msg;
1089 if PanelNr = 6 then begin 1089 if PanelNr = 6 then begin
1090 // Immediately repaint this special panel, as it holds critical update messages, 1090 // Immediately repaint this special panel, as it holds critical update messages,
1091 // while avoiding StatusBar.Repaint which refreshes all panels 1091 // while avoiding StatusBar.Repaint which refreshes all panels
1092 SendMessage(StatusBar.Handle, SB_GETRECT, PanelNr, Integer(@PanelRect)); 1092 SendMessage(StatusBar.Handle, SB_GETRECT, PanelNr, Integer(@PanelRect));
1093 StatusBar.OnDrawPanel(StatusBar, StatusBar.Panels[PanelNr], PanelRect); 1093 StatusBar.OnDrawPanel(StatusBar, StatusBar.Panels[PanelNr], PanelRect);
1094 end; 1094 end;
1095 end; 1095 end;
1096 end; 1096 end;
1097 1097
1098 1098
1099 procedure TMainForm.StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; 1099 procedure TMainForm.StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
1100 const Rect: TRect); 1100 const Rect: TRect);
1101 var 1101 var
1102 PanelRect: TRect; 1102 PanelRect: TRect;
1103 ImageIndex: Integer; 1103 ImageIndex: Integer;
1104 Conn: TDBConnection; 1104 Conn: TDBConnection;
1105 begin 1105 begin
1106 // Refresh one status bar panel, probably with icon 1106 // Refresh one status bar panel, probably with icon
1107 ImageIndex := -1; 1107 ImageIndex := -1;
1108 case Panel.Index of 1108 case Panel.Index of
1109 2: ImageIndex := 149; 1109 2: ImageIndex := 149;
1110 3: begin 1110 3: begin
1111 Conn := ActiveConnection; 1111 Conn := ActiveConnection;
1112 if Conn <> nil then 1112 if Conn <> nil then
1113 ImageIndex := Conn.Parameters.ImageIndex; 1113 ImageIndex := Conn.Parameters.ImageIndex;
1114 end; 1114 end;
1115 6: begin 1115 6: begin
1116 if Panel.Text = SIdle then 1116 if Panel.Text = SIdle then
1117 ImageIndex := 151 // Green dot 1117 ImageIndex := 151 // Green dot
1118 else 1118 else
1119 ImageIndex := 150; // Hourglass 1119 ImageIndex := 150; // Hourglass
1120 end; 1120 end;
1121 end; 1121 end;
1122 PanelRect := Rect; 1122 PanelRect := Rect;
1123 StatusBar.Canvas.FillRect(PanelRect); 1123 StatusBar.Canvas.FillRect(PanelRect);
1124 if ImageIndex > -1 then begin 1124 if ImageIndex > -1 then begin
1125 ImageListMain.Draw(StatusBar.Canvas, PanelRect.Left, PanelRect.Top, ImageIndex, true); 1125 ImageListMain.Draw(StatusBar.Canvas, PanelRect.Left, PanelRect.Top, ImageIndex, true);
1126 OffsetRect(PanelRect, ImageListMain.Width+2, 0); 1126 OffsetRect(PanelRect, ImageListMain.Width+2, 0);
1127 end; 1127 end;
1128 DrawText(StatusBar.Canvas.Handle, PChar(Panel.Text), -1, PanelRect, DT_SINGLELINE or DT_VCENTER); 1128 DrawText(StatusBar.Canvas.Handle, PChar(Panel.Text), -1, PanelRect, DT_SINGLELINE or DT_VCENTER);
1129 end; 1129 end;
1130 1130
1131 1131
1132 procedure TMainForm.StatusBarMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 1132 procedure TMainForm.StatusBarMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
1133 var 1133 var
1134 MouseP: TPoint; 1134 MouseP: TPoint;
1135 Bar: TStatusBar; 1135 Bar: TStatusBar;
1136 PanelRect: TRect; 1136 PanelRect: TRect;
1137 i: Integer; 1137 i: Integer;
1138 Infos: TStringList; 1138 Infos: TStringList;
1139 begin 1139 begin
1140 // Display various server, client and connection related details in a hint 1140 // Display various server, client and connection related details in a hint
1141 if (FLastHintMousepos.X = X) and (FLastHintMousepos.Y = Y) then 1141 if (FLastHintMousepos.X = X) and (FLastHintMousepos.Y = Y) then
1142 Exit; 1142 Exit;
1143 FLastHintMousepos := Point(X, Y); 1143 FLastHintMousepos := Point(X, Y);
1144 MouseP := StatusBar.ClientOrigin; 1144 MouseP := StatusBar.ClientOrigin;
1145 Inc(MouseP.X, X); 1145 Inc(MouseP.X, X);
1146 Inc(MouseP.Y, Y); 1146 Inc(MouseP.Y, Y);
1147 Bar := Sender as TStatusBar; 1147 Bar := Sender as TStatusBar;
1148 for i:=0 to Bar.Panels.Count-1 do begin 1148 for i:=0 to Bar.Panels.Count-1 do begin
1149 SendMessage(Bar.Handle, SB_GETRECT, i, Integer(@PanelRect)); 1149 SendMessage(Bar.Handle, SB_GETRECT, i, Integer(@PanelRect));
1150 if PtInRect(PanelRect, FLastHintMousepos) then 1150 if PtInRect(PanelRect, FLastHintMousepos) then
1151 break; 1151 break;
1152 end; 1152 end;
1153 if i = FLastHintControlIndex then 1153 if i = FLastHintControlIndex then
1154 Exit; 1154 Exit;
1155 FLastHintControlIndex := i; 1155 FLastHintControlIndex := i;
1156 if FLastHintControlIndex = 3 then begin 1156 if FLastHintControlIndex = 3 then begin
1157 Infos := ActiveConnection.ConnectionInfo; 1157 Infos := ActiveConnection.ConnectionInfo;
1158 BalloonHint1.Description := ''; 1158 BalloonHint1.Description := '';
1159 for i:=0 to Infos.Count-1 do 1159 for i:=0 to Infos.Count-1 do
1160 BalloonHint1.Description := BalloonHint1.Description + Infos.Names[i] + ': ' + Infos.ValueFromIndex[i] + CRLF; 1160 BalloonHint1.Description := BalloonHint1.Description + Infos.Names[i] + ': ' + Infos.ValueFromIndex[i] + CRLF;
1161 BalloonHint1.Description := Trim(BalloonHint1.Description); 1161 BalloonHint1.Description := Trim(BalloonHint1.Description);
1162 OffsetRect(PanelRect, Bar.ClientOrigin.X, Bar.ClientOrigin.Y); 1162 OffsetRect(PanelRect, Bar.ClientOrigin.X, Bar.ClientOrigin.Y);
1163 BalloonHint1.ShowHint(PanelRect); 1163 BalloonHint1.ShowHint(PanelRect);
1164 end else 1164 end else
1165 Bar.OnMouseLeave(Sender); 1165 Bar.OnMouseLeave(Sender);
1166 end; 1166 end;
1167 1167
1168 1168
1169 procedure TMainForm.StatusBarMouseLeave(Sender: TObject); 1169 procedure TMainForm.StatusBarMouseLeave(Sender: TObject);
1170 begin 1170 begin
1171 BalloonHint1.HideHint; 1171 BalloonHint1.HideHint;
1172 FLastHintControlIndex := -1; 1172 FLastHintControlIndex := -1;
1173 end; 1173 end;
1174 1174
1175 1175
1176 procedure TMainForm.actExitApplicationExecute(Sender: TObject); 1176 procedure TMainForm.actExitApplicationExecute(Sender: TObject);
1177 begin 1177 begin
1178 Close; 1178 Close;
1179 end; 1179 end;
1180 1180
1181 procedure TMainForm.actFlushExecute(Sender: TObject); 1181 procedure TMainForm.actFlushExecute(Sender: TObject);
1182 var 1182 var
1183 flushwhat: String; 1183 flushwhat: String;
1184 begin 1184 begin
1185 flushwhat := UpperCase(TAction(Sender).Caption); 1185 flushwhat := UpperCase(TAction(Sender).Caption);
1186 flushwhat := StripHotkey(flushwhat); 1186 flushwhat := StripHotkey(flushwhat);
1187 try 1187 try
1188 ActiveConnection.Query('FLUSH ' + flushwhat); 1188 ActiveConnection.Query('FLUSH ' + flushwhat);
1189 if Sender = actFlushTableswithreadlock then begin 1189 if Sender = actFlushTableswithreadlock then begin
1190 MessageDialog( 1190 MessageDialog(
1191 'Tables have been flushed and read lock acquired.'#10 + 1191 'Tables have been flushed and read lock acquired.'#10 +
1192 'Perform backup or snapshot of table data files now.'#10 + 1192 'Perform backup or snapshot of table data files now.'#10 +
1193 'Press OK to unlock when done...', 1193 'Press OK to unlock when done...',
1194 mtInformation, [mbOk] 1194 mtInformation, [mbOk]
1195 ); 1195 );
1196 ActiveConnection.Query('UNLOCK TABLES'); 1196 ActiveConnection.Query('UNLOCK TABLES');
1197 end; 1197 end;
1198 except 1198 except
1199 on E:EDatabaseError do 1199 on E:EDatabaseError do
1200 ErrorDialog(E.Message); 1200 ErrorDialog(E.Message);
1201 end; 1201 end;
1202 end; 1202 end;
1203 1203
1204 1204
1205 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 1205 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
1206 var 1206 var
1207 i: Integer; 1207 i: Integer;
1208 begin 1208 begin
1209 // Prompt on modified changes 1209 // Prompt on modified changes
1210 CanClose := True; 1210 CanClose := True;
1211 // Unsaved changes in some query tab? 1211 // Unsaved changes in some query tab?
1212 for i:=0 to QueryTabs.Count-1 do begin 1212 for i:=0 to QueryTabs.Count-1 do begin
1213 CanClose := ConfirmTabClose(i+tabQuery.PageIndex); 1213 CanClose := ConfirmTabClose(i+tabQuery.PageIndex);
1214 if not CanClose then 1214 if not CanClose then
1215 Exit; 1215 Exit;
1216 end; 1216 end;
1217 // Unsaved modified table, trigger, view or routine? 1217 // Unsaved modified table, trigger, view or routine?
1218 if Assigned(ActiveObjectEditor) then 1218 if Assigned(ActiveObjectEditor) then
1219 CanClose := not (ActiveObjectEditor.DeInit in [mrAbort, mrCancel]); 1219 CanClose := not (ActiveObjectEditor.DeInit in [mrAbort, mrCancel]);
1220 end; 1220 end;
1221 1221
1222 procedure TMainForm.FormDestroy(Sender: TObject); 1222 procedure TMainForm.FormDestroy(Sender: TObject);
1223 var 1223 var
1224 OpenSessions: String; 1224 OpenSessions: String;
1225 Connection: TDBConnection; 1225 Connection: TDBConnection;
1226 begin 1226 begin
1227 // Destroy dialogs 1227 // Destroy dialogs
1228 FreeAndNil(FSearchReplaceDialog); 1228 FreeAndNil(FSearchReplaceDialog);
1229 1229
1230 // Save opened session names in root folder 1230 // Save opened session names in root folder
1231 OpenRegistry; 1231 OpenRegistry;
1232 OpenSessions := ''; 1232 OpenSessions := '';
1233 for Connection in Connections do 1233 for Connection in Connections do
1234 OpenSessions := OpenSessions + Connection.Parameters.SessionName + DELIM; 1234 OpenSessions := OpenSessions + Connection.Parameters.SessionName + DELIM;
1235 Delete(OpenSessions, Length(OpenSessions)-Length(DELIM)+1, Length(DELIM)); 1235 Delete(OpenSessions, Length(OpenSessions)-Length(DELIM)+1, Length(DELIM));
1236 MainReg.WriteString(REGNAME_LASTSESSIONS, OpenSessions); 1236 MainReg.WriteString(REGNAME_LASTSESSIONS, OpenSessions);
1237 if Assigned(ActiveConnection) then 1237 if Assigned(ActiveConnection) then
1238 MainReg.WriteString(REGNAME_LASTACTIVESESSION, ActiveConnection.Parameters.SessionName); 1238 MainReg.WriteString(REGNAME_LASTACTIVESESSION, ActiveConnection.Parameters.SessionName);
1239 1239
1240 // Some grid editors access the registry - be sure these are gone before freeing MainReg 1240 // Some grid editors access the registry - be sure these are gone before freeing MainReg
1241 QueryTabs.Clear; 1241 QueryTabs.Clear;
1242 DataGrid.EndEditNode; 1242 DataGrid.EndEditNode;
1243 1243
1244 // Clearing query and browse data. 1244 // Clearing query and browse data.
1245 FreeAndNil(DataGridResult); 1245 FreeAndNil(DataGridResult);
1246 1246
1247 // Close database connections 1247 // Close database connections
1248 Connections.Clear; 1248 Connections.Clear;
1249 1249
1250 // Save various settings 1250 // Save various settings
1251 OpenRegistry; 1251 OpenRegistry;
1252 MainReg.WriteInteger(REGNAME_TOOLBAR2LEFT, ToolBarStandard.Left); 1252 MainReg.WriteInteger(REGNAME_TOOLBAR2LEFT, ToolBarStandard.Left);
1253 MainReg.WriteInteger(REGNAME_TOOLBAR2TOP, ToolBarStandard.Top); 1253 MainReg.WriteInteger(REGNAME_TOOLBAR2TOP, ToolBarStandard.Top);
1254 MainReg.WriteInteger(REGNAME_TOOLBARDATALEFT, ToolBarData.Left); 1254 MainReg.WriteInteger(REGNAME_TOOLBARDATALEFT, ToolBarData.Left);
1255 MainReg.WriteInteger(REGNAME_TOOLBARDATATOP, ToolBarData.Top); 1255 MainReg.WriteInteger(REGNAME_TOOLBARDATATOP, ToolBarData.Top);
1256 MainReg.WriteInteger(REGNAME_TOOLBARQUERYLEFT, ToolBarQuery.Left); 1256 MainReg.WriteInteger(REGNAME_TOOLBARQUERYLEFT, ToolBarQuery.Left);
1257 MainReg.WriteInteger(REGNAME_TOOLBARQUERYTOP, ToolBarQuery.Top); 1257 MainReg.WriteInteger(REGNAME_TOOLBARQUERYTOP, ToolBarQuery.Top);
1258 MainReg.WriteBool(REGNAME_STOPONERRORSINBATCH, actQueryStopOnErrors.Checked); 1258 MainReg.WriteBool(REGNAME_STOPONERRORSINBATCH, actQueryStopOnErrors.Checked);
1259 MainReg.WriteBool(REGNAME_BLOBASTEXT, actBlobAsText.Checked); 1259 MainReg.WriteBool(REGNAME_BLOBASTEXT, actBlobAsText.Checked);
1260 MainReg.WriteString( REGNAME_DELIMITER, Delimiter ); 1260 MainReg.WriteString( REGNAME_DELIMITER, Delimiter );
1261 MainReg.WriteInteger( REGNAME_QUERYMEMOHEIGHT, pnlQueryMemo.Height ); 1261 MainReg.WriteInteger( REGNAME_QUERYMEMOHEIGHT, pnlQueryMemo.Height );
1262 MainReg.WriteInteger( REGNAME_QUERYHELPERSWIDTH, treeQueryHelpers.Width ); 1262 MainReg.WriteInteger( REGNAME_QUERYHELPERSWIDTH, treeQueryHelpers.Width );
1263 MainReg.WriteInteger( REGNAME_DBTREEWIDTH, pnlLeft.width ); 1263 MainReg.WriteInteger( REGNAME_DBTREEWIDTH, pnlLeft.width );
1264 MainReg.WriteString( REGNAME_DATABASE_FILTER, comboDBFilter.Items.Text ); 1264 MainReg.WriteString( REGNAME_DATABASE_FILTER, comboDBFilter.Items.Text );
1265 MainReg.WriteInteger(REGNAME_PREVIEW_HEIGHT, pnlPreview.Height); 1265 MainReg.WriteInteger(REGNAME_PREVIEW_HEIGHT, pnlPreview.Height);
1266 MainReg.WriteBool(REGNAME_PREVIEW_ENABLED, actDataPreview.Checked); 1266 MainReg.WriteBool(REGNAME_PREVIEW_ENABLED, actDataPreview.Checked);
1267 MainReg.WriteInteger( REGNAME_SQLOUTHEIGHT, SynMemoSQLLog.Height ); 1267 MainReg.WriteInteger( REGNAME_SQLOUTHEIGHT, SynMemoSQLLog.Height );
1268 MainReg.WriteBool(REGNAME_FILTERACTIVE, pnlFilterVT.Tag=Integer(True)); 1268 MainReg.WriteBool(REGNAME_FILTERACTIVE, pnlFilterVT.Tag=Integer(True));
1269 MainReg.WriteBool(REGNAME_WRAPLINES, actQueryWordWrap.Checked); 1269 MainReg.WriteBool(REGNAME_WRAPLINES, actQueryWordWrap.Checked);
1270 MainReg.WriteBool(REGNAME_SINGLEQUERIES, actSingleQueries.Checked); 1270 MainReg.WriteBool(REGNAME_SINGLEQUERIES, actSingleQueries.Checked);
1271 MainReg.WriteBool(REGNAME_LOG_HORIZONTALSCROLLBAR, SynMemoSQLLog.ScrollBars = ssBoth); 1271 MainReg.WriteBool(REGNAME_LOG_HORIZONTALSCROLLBAR, SynMemoSQLLog.ScrollBars = ssBoth);
1272 MainReg.WriteBool(REGNAME_WINMAXIMIZED, WindowState=wsMaximized); 1272 MainReg.WriteBool(REGNAME_WINMAXIMIZED, WindowState=wsMaximized);
1273 MainReg.WriteInteger(REGNAME_WINONMONITOR, Monitor.MonitorNum); 1273 MainReg.WriteInteger(REGNAME_WINONMONITOR, Monitor.MonitorNum);
1274 // Window dimensions are only valid when WindowState is normal. 1274 // Window dimensions are only valid when WindowState is normal.
1275 if WindowState = wsNormal then begin 1275 if WindowState = wsNormal then begin
1276 MainReg.WriteInteger(REGNAME_WINLEFT, Left); 1276 MainReg.WriteInteger(REGNAME_WINLEFT, Left);
1277 MainReg.WriteInteger(REGNAME_WINTOP, Top); 1277 MainReg.WriteInteger(REGNAME_WINTOP, Top);
1278 MainReg.WriteInteger(REGNAME_WINWIDTH, Width); 1278 MainReg.WriteInteger(REGNAME_WINWIDTH, Width);
1279 MainReg.WriteInteger(REGNAME_WINHEIGHT, Height); 1279 MainReg.WriteInteger(REGNAME_WINHEIGHT, Height);
1280 end; 1280 end;
1281 SaveListSetup(ListDatabases); 1281 SaveListSetup(ListDatabases);
1282 SaveListSetup(ListVariables); 1282 SaveListSetup(ListVariables);
1283 SaveListSetup(ListStatus); 1283 SaveListSetup(ListStatus);
1284 SaveListSetup(ListProcesses); 1284 SaveListSetup(ListProcesses);
1285 SaveListSetup(ListCommandStats); 1285 SaveListSetup(ListCommandStats);
1286 SaveListSetup(ListTables); 1286 SaveListSetup(ListTables);
1287 1287
1288 if prefLogToFile then 1288 if prefLogToFile then
1289 DeactivateFileLogging; 1289 DeactivateFileLogging;
1290 1290
1291 if MainReg <> nil then begin 1291 if MainReg <> nil then begin
1292 MainReg.CloseKey; 1292 MainReg.CloseKey;
1293 // Export settings into textfile in portable mode. 1293 // Export settings into textfile in portable mode.
1294 HandlePortableSettings(False); 1294 HandlePortableSettings(False);
1295 MainReg.Free; 1295 MainReg.Free;
1296 end; 1296 end;
1297 end; 1297 end;
1298 1298
1299 1299
1300 {*** 1300 {***
1301 OnCreate Event 1301 OnCreate Event
1302 Important to set the windowstate here instead of in OnShow 1302 Important to set the windowstate here instead of in OnShow
1303 because possible windowstate-switching is done with an animation 1303 because possible windowstate-switching is done with an animation
1304 if set in Windows. This animation takes some milliseconds 1304 if set in Windows. This animation takes some milliseconds
1305 to complete and can be annoying. 1305 to complete and can be annoying.
1306 } 1306 }
1307 procedure TMainForm.FormCreate(Sender: TObject); 1307 procedure TMainForm.FormCreate(Sender: TObject);
1308 const 1308 const
1309 VistaFont = 'Segoe UI'; 1309 VistaFont = 'Segoe UI';
1310 var 1310 var
1311 i, j, MonitorIndex: Integer; 1311 i, j, MonitorIndex: Integer;
1312 datafontname: String; 1312 datafontname: String;
1313 datafontsize : Integer; 1313 datafontsize : Integer;
1314 QueryTab: TQueryTab; 1314 QueryTab: TQueryTab;
1315 Action: TAction; 1315 Action: TAction;
1316 dwInfoSize, // Size of VERSIONINFO structure 1316 dwInfoSize, // Size of VERSIONINFO structure
1317 dwVerSize, // Size of Version Info Data 1317 dwVerSize, // Size of Version Info Data
1318 dwWnd: DWORD; // Handle for the size call. 1318 dwWnd: DWORD; // Handle for the size call.
1319 FI: PVSFixedFileInfo; // Delphi structure; see WINDOWS.PAS 1319 FI: PVSFixedFileInfo; // Delphi structure; see WINDOWS.PAS
1320 ptrVerBuf, Translation, Info: Pointer; 1320 ptrVerBuf, Translation, Info: Pointer;
1321 DpiScaleFactor: Double; 1321 DpiScaleFactor: Double;
1322 FunctionCategories: TStringList; 1322 FunctionCategories: TStringList;
1323 miGroup, miFilterGroup, miFunction, miFilterFunction: TMenuItem; 1323 miGroup, miFilterGroup, miFunction, miFilterFunction: TMenuItem;
1324 NTHandle: THandle; 1324 NTHandle: THandle;
1325 wine_nt_to_unix_file_name: procedure(p1:pointer; p2:pointer); stdcall; 1325 wine_nt_to_unix_file_name: procedure(p1:pointer; p2:pointer); stdcall;
1326 begin 1326 begin
1327 caption := APPNAME; 1327 caption := APPNAME;
1328 setLocales; 1328 setLocales;
1329 1329
1330 // Detect version 1330 // Detect version
1331 dwInfoSize := GetFileVersionInfoSize(PChar(Application.ExeName), dwWnd); 1331 dwInfoSize := GetFileVersionInfoSize(PChar(Application.ExeName), dwWnd);
1332 GetMem(ptrVerBuf, dwInfoSize); 1332 GetMem(ptrVerBuf, dwInfoSize);
1333 GetFileVersionInfo(PChar(Application.ExeName), dwWnd, dwInfoSize, ptrVerBuf); 1333 GetFileVersionInfo(PChar(Application.ExeName), dwWnd, dwInfoSize, ptrVerBuf);
1334 VerQueryValue(ptrVerBuf, '\', Pointer(FI), dwVerSize ); 1334 VerQueryValue(ptrVerBuf, '\', Pointer(FI), dwVerSize );
1335 AppVerMajor := HiWord(FI.dwFileVersionMS); 1335 AppVerMajor := HiWord(FI.dwFileVersionMS);
1336 AppVerMinor := LoWord(FI.dwFileVersionMS); 1336 AppVerMinor := LoWord(FI.dwFileVersionMS);
1337 AppVerRelease := HiWord(FI.dwFileVersionLS); 1337 AppVerRelease := HiWord(FI.dwFileVersionLS);
1338 AppVerRevision := LoWord(FI.dwFileVersionLS); 1338 AppVerRevision := LoWord(FI.dwFileVersionLS);
1339 AppVersion := Format('%d.%d.%d.%d', [AppVerMajor, AppVerMinor, AppVerRelease, AppVerRevision]); 1339 AppVersion := Format('%d.%d.%d.%d', [AppVerMajor, AppVerMinor, AppVerRelease, AppVerRevision]);
1340 // Fetch language code and file description 1340 // Fetch language code and file description
1341 VerQueryValue(ptrVerBuf,'\\VarFileInfo\\Translation', Translation, dwInfoSize); 1341 VerQueryValue(ptrVerBuf,'\\VarFileInfo\\Translation', Translation, dwInfoSize);
1342 VerQueryValue(ptrVerBuf, 1342 VerQueryValue(ptrVerBuf,
1343 PChar(Format('\\StringFileInfo\\%.4x%.4x\\%s', 1343 PChar(Format('\\StringFileInfo\\%.4x%.4x\\%s',
1344 [LoWord(Longint(translation^)), HiWord(Longint(Translation^)), 'FileDescription'])), 1344 [LoWord(Longint(translation^)), HiWord(Longint(Translation^)), 'FileDescription'])),
1345 Info, 1345 Info,
1346 dwInfoSize); 1346 dwInfoSize);
1347 SetString(AppDescription, PChar(Info), dwInfoSize-1); 1347 SetString(AppDescription, PChar(Info), dwInfoSize-1);
1348 FreeMem(ptrVerBuf); 1348 FreeMem(ptrVerBuf);
1349 1349
1350 // Detect if we're running on Wine, not on native Windows 1350 // Detect if we're running on Wine, not on native Windows
1351 // Idea taken from http://ruminatedrumblings.blogspot.com/2008/04/detecting-virtualized-environment.html 1351 // Idea taken from http://ruminatedrumblings.blogspot.com/2008/04/detecting-virtualized-environment.html
1352 NTHandle := LoadLibrary('NTDLL.DLL'); 1352 NTHandle := LoadLibrary('NTDLL.DLL');
1353 if NTHandle>32 then 1353 if NTHandle>32 then
1354 wine_nt_to_unix_file_name := GetProcAddress(NTHandle, 'wine_nt_to_unix_file_name'); 1354 wine_nt_to_unix_file_name := GetProcAddress(NTHandle, 'wine_nt_to_unix_file_name');
1355 FIsWine := Assigned(wine_nt_to_unix_file_name); 1355 FIsWine := Assigned(wine_nt_to_unix_file_name);
1356 FreeLibrary(NTHandle); 1356 FreeLibrary(NTHandle);
1357 1357
1358 // Taskbar button interface for Windows 7 1358 // Taskbar button interface for Windows 7
1359 if CheckWin32Version(6, 1) then begin 1359 if CheckWin32Version(6, 1) then begin
1360 TaskbarList := CreateComObject(CLSID_TaskbarList) as ITaskbarList; 1360 TaskbarList := CreateComObject(CLSID_TaskbarList) as ITaskbarList;
1361 TaskbarList.HrInit; 1361 TaskbarList.HrInit;
1362 Supports(TaskbarList, IID_ITaskbarList2, TaskbarList2); 1362 Supports(TaskbarList, IID_ITaskbarList2, TaskbarList2);
1363 Supports(TaskbarList, IID_ITaskbarList3, TaskbarList3); 1363 Supports(TaskbarList, IID_ITaskbarList3, TaskbarList3);
1364 Supports(TaskbarList, IID_ITaskbarList4, TaskbarList4); 1364 Supports(TaskbarList, IID_ITaskbarList4, TaskbarList4);
1365 end; 1365 end;
1366 1366
1367 // "All users" folder for HeidiSQL's data (All Users\Application Data) 1367 // "All users" folder for HeidiSQL's data (All Users\Application Data)
1368 FDirnameCommonAppData := GetShellFolder(CSIDL_COMMON_APPDATA) + '\' + APPNAME + '\'; 1368 FDirnameCommonAppData := GetShellFolder(CSIDL_COMMON_APPDATA) + '\' + APPNAME + '\';
1369 1369
1370 // User folder for HeidiSQL's data (<user name>\Application Data) 1370 // User folder for HeidiSQL's data (<user name>\Application Data)
1371 FDirnameUserAppData := GetShellFolder(CSIDL_APPDATA) + '\' + APPNAME + '\'; 1371 FDirnameUserAppData := GetShellFolder(CSIDL_APPDATA) + '\' + APPNAME + '\';
1372 // Ensure directory exists 1372 // Ensure directory exists
1373 ForceDirectories(FDirnameUserAppData); 1373 ForceDirectories(FDirnameUserAppData);
1374 1374
1375 // Folder which contains snippet-files 1375 // Folder which contains snippet-files
1376 FDirnameSnippets := FDirnameCommonAppData + 'Snippets\'; 1376 FDirnameSnippets := FDirnameCommonAppData + 'Snippets\';
1377 SetSnippetFilenames; 1377 SetSnippetFilenames;
1378 1378
1379 // SQLFiles-History 1379 // SQLFiles-History
1380 FillPopupQueryLoad; 1380 FillPopupQueryLoad;
1381 1381
1382 // Create function menu items in popupQuery and popupFilter 1382 // Create function menu items in popupQuery and popupFilter
1383 menuQueryInsertFunction.Clear; 1383 menuQueryInsertFunction.Clear;
1384 menuFilterInsertFunction.Clear; 1384 menuFilterInsertFunction.Clear;
1385 FunctionCategories := GetFunctionCategories; 1385 FunctionCategories := GetFunctionCategories;
1386 for i:=0 to FunctionCategories.Count-1 do begin 1386 for i:=0 to FunctionCategories.Count-1 do begin
1387 // Create a menu item which gets subitems later 1387 // Create a menu item which gets subitems later
1388 miGroup := TMenuItem.Create(popupQuery); 1388 miGroup := TMenuItem.Create(popupQuery);
1389 miGroup.Caption := FunctionCategories[i]; 1389 miGroup.Caption := FunctionCategories[i];
1390 menuQueryInsertFunction.Add(miGroup); 1390 menuQueryInsertFunction.Add(miGroup);
1391 miFilterGroup := TMenuItem.Create(popupFilter); 1391 miFilterGroup := TMenuItem.Create(popupFilter);
1392 miFilterGroup.Caption := miGroup.Caption; 1392 miFilterGroup.Caption := miGroup.Caption;
1393 menuFilterInsertFunction.Add(miFilterGroup); 1393 menuFilterInsertFunction.Add(miFilterGroup);
1394 for j:=0 to Length(MySqlFunctions)-1 do begin 1394 for j:=0 to Length(MySqlFunctions)-1 do begin
1395 if MySqlFunctions[j].Category <> FunctionCategories[i] then 1395 if MySqlFunctions[j].Category <> FunctionCategories[i] then
1396 continue; 1396 continue;
1397 miFunction := TMenuItem.Create(popupQuery); 1397 miFunction := TMenuItem.Create(popupQuery);
1398 miFunction.Caption := MySqlFunctions[j].Name; 1398 miFunction.Caption := MySqlFunctions[j].Name;
1399 miFunction.ImageIndex := 13; 1399 miFunction.ImageIndex := 13;
1400 // Prevent generating a hotkey 1400 // Prevent generating a hotkey
1401 miFunction.Caption := StringReplace(miFunction.Caption, '&', '&&', [rfReplaceAll]); 1401 miFunction.Caption := StringReplace(miFunction.Caption, '&', '&&', [rfReplaceAll]);
1402 // Prevent generating a seperator line 1402 // Prevent generating a seperator line
1403 if miFunction.Caption = '-' then 1403 if miFunction.Caption = '-' then
1404 miFunction.Caption := '&-'; 1404 miFunction.Caption := '&-';
1405 miFunction.Hint := MySqlFunctions[j].Name + MySqlFunctions[j].Declaration + ' - ' + sstr(MySqlFunctions[j].Description, 200); 1405 miFunction.Hint := MySqlFunctions[j].Name + MySqlFunctions[j].Declaration + ' - ' + sstr(MySqlFunctions[j].Description, 200);
1406 // Prevent generating a seperator for ShortHint and LongHint 1406 // Prevent generating a seperator for ShortHint and LongHint
1407 miFunction.Hint := StringReplace( miFunction.Hint, '|', '¦', [rfReplaceAll] ); 1407 miFunction.Hint := StringReplace( miFunction.Hint, '|', '¦', [rfReplaceAll] );
1408 miFunction.Tag := j; 1408 miFunction.Tag := j;
1409 // Place menuitem on menu 1409 // Place menuitem on menu
1410 miFunction.OnClick := insertFunction; 1410 miFunction.OnClick := insertFunction;
1411 miGroup.Add(miFunction); 1411 miGroup.Add(miFunction);
1412 // Create a copy of the menuitem for popupFilter 1412 // Create a copy of the menuitem for popupFilter
1413 miFilterFunction := TMenuItem.Create(popupFilter); 1413 miFilterFunction := TMenuItem.Create(popupFilter);
1414 miFilterFunction.Caption := miFunction.Caption; 1414 miFilterFunction.Caption := miFunction.Caption;
1415 miFilterFunction.Hint := miFunction.Hint; 1415 miFilterFunction.Hint := miFunction.Hint;
1416 miFilterFunction.ImageIndex := miFunction.ImageIndex; 1416 miFilterFunction.ImageIndex := miFunction.ImageIndex;
1417 miFilterFunction.Tag := miFunction.Tag; 1417 miFilterFunction.Tag := miFunction.Tag;
1418 miFilterFunction.OnClick := miFunction.OnClick; 1418 miFilterFunction.OnClick := miFunction.OnClick;
1419 miFilterFunction.Enabled := miFunction.Enabled; 1419 miFilterFunction.Enabled := miFunction.Enabled;
1420 miFilterGroup.Add(miFilterFunction); 1420 miFilterGroup.Add(miFilterFunction);
1421 end; 1421 end;
1422 end; 1422 end;
1423 FunctionCategories.Free; 1423 FunctionCategories.Free;
1424 1424
1425 Delimiter := GetRegValue(REGNAME_DELIMITER, DEFAULT_DELIMITER); 1425 Delimiter := GetRegValue(REGNAME_DELIMITER, DEFAULT_DELIMITER);
1426 1426
1427 // Delphi work around to force usage of Vista's default font (other OSes will be unaffected) 1427 // Delphi work around to force usage of Vista's default font (other OSes will be unaffected)
1428 if (Win32MajorVersion >= 6) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then begin 1428 if (Win32MajorVersion >= 6) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then begin
1429 Font.Size := Font.Size + 1; 1429 Font.Size := Font.Size + 1;
1430 Font.Name := VistaFont; 1430 Font.Name := VistaFont;
1431 end; 1431 end;
1432 InheritFont(SynCompletionProposal.Font); 1432 InheritFont(SynCompletionProposal.Font);
1433 InheritFont(ParameterCompletionProposal.Font); 1433 InheritFont(ParameterCompletionProposal.Font);
1434 // Simulated link label, has non inherited blue font color 1434 // Simulated link label, has non inherited blue font color
1435 InheritFont(lblExplainProcess.Font); 1435 InheritFont(lblExplainProcess.Font);
1436 1436
1437 StatusBar.Height := GetTextHeight(StatusBar.Font)+4; 1437 StatusBar.Height := GetTextHeight(StatusBar.Font)+4;
1438 // Upscale panels in non-96-DPI mode 1438 // Upscale panels in non-96-DPI mode
1439 DpiScaleFactor := Screen.PixelsPerInch / FORMS_DPI; 1439 DpiScaleFactor := Screen.PixelsPerInch / FORMS_DPI;
1440 for i:=StatusBar.Panels.Count-1 downto 1 do 1440 for i:=StatusBar.Panels.Count-1 downto 1 do
1441 StatusBar.Panels[i].Width := Round(StatusBar.Panels[i].Width * DpiScaleFactor); 1441 StatusBar.Panels[i].Width := Round(StatusBar.Panels[i].Width * DpiScaleFactor);
1442 1442
1443 QueryTab := TQueryTab.Create(Self); 1443 QueryTab := TQueryTab.Create(Self);
1444 QueryTab.TabSheet := tabQuery; 1444 QueryTab.TabSheet := tabQuery;
1445 QueryTab.Number := 1; 1445 QueryTab.Number := 1;
1446 QueryTab.pnlMemo := pnlQueryMemo; 1446 QueryTab.pnlMemo := pnlQueryMemo;
1447 QueryTab.treeHelpers := treeQueryHelpers; 1447 QueryTab.treeHelpers := treeQueryHelpers;
1448 QueryTab.Memo := SynMemoQuery; 1448 QueryTab.Memo := SynMemoQuery;
1449 QueryTab.MemoLineBreaks := lbsNone; 1449 QueryTab.MemoLineBreaks := lbsNone;
1450 QueryTab.spltHelpers := spltQueryHelpers; 1450 QueryTab.spltHelpers := spltQueryHelpers;
1451 QueryTab.spltQuery := spltQuery; 1451 QueryTab.spltQuery := spltQuery;
1452 QueryTab.tabsetQuery := tabsetQuery; 1452 QueryTab.tabsetQuery := tabsetQuery;
1453 QueryTab.ResultTabs := TResultTabs.Create(True); 1453 QueryTab.ResultTabs := TResultTabs.Create(True);
1454 1454
1455 QueryTabs := TObjectList<TQueryTab>.Create(True); 1455 QueryTabs := TObjectList<TQueryTab>.Create(True);
1456 QueryTabs.Add(QueryTab); 1456 QueryTabs.Add(QueryTab);
1457 1457
1458 // Populate generic results for "Host" subtabs 1458 // Populate generic results for "Host" subtabs
1459 FHostListResults := TDBQueryList.Create(False); 1459 FHostListResults := TDBQueryList.Create(False);
1460 FHostTabCaptions := TStringList.Create; 1460 FHostTabCaptions := TStringList.Create;
1461 for i:=0 to PageControlHost.PageCount-1 do begin 1461 for i:=0 to PageControlHost.PageCount-1 do begin
1462 FHostListResults.Add(nil); 1462 FHostListResults.Add(nil);
1463 FHostTabCaptions.Add(PageControlHost.Pages[i].Caption); 1463 FHostTabCaptions.Add(PageControlHost.Pages[i].Caption);
1464 end; 1464 end;
1465 1465
1466 // Enable auto completion in data tab, filter editor 1466 // Enable auto completion in data tab, filter editor
1467 SynCompletionProposal.AddEditor(SynMemoFilter); 1467 SynCompletionProposal.AddEditor(SynMemoFilter);
1468 ParameterCompletionProposal.AddEditor(SynMemoFilter); 1468 ParameterCompletionProposal.AddEditor(SynMemoFilter);
1469 1469
1470 // Fix node height on Virtual Trees for current DPI settings 1470 // Fix node height on Virtual Trees for current DPI settings
1471 FixVT(DBTree); 1471 FixVT(DBTree);
1472 FixVT(ListDatabases); 1472 FixVT(ListDatabases);
1473 FixVT(ListVariables); 1473 FixVT(ListVariables);
1474 FixVT(ListStatus); 1474 FixVT(ListStatus);
1475 FixVT(ListProcesses); 1475 FixVT(ListProcesses);
1476 FixVT(ListCommandStats); 1476 FixVT(ListCommandStats);
1477 FixVT(ListTables); 1477 FixVT(ListTables);
1478 FixVT(treeQueryHelpers); 1478 FixVT(treeQueryHelpers);
1479 1479
1480 // Window position 1480 // Window position
1481 Left := GetRegValue(REGNAME_WINLEFT, Left); 1481 Left := GetRegValue(REGNAME_WINLEFT, Left);
1482 Top := GetRegValue(REGNAME_WINTOP, Top); 1482 Top := GetRegValue(REGNAME_WINTOP, Top);
1483 // .. dimensions 1483 // .. dimensions
1484 Width := GetRegValue(REGNAME_WINWIDTH, Width); 1484 Width := GetRegValue(REGNAME_WINWIDTH, Width);
1485 Height := GetRegValue(REGNAME_WINHEIGHT, Height); 1485 Height := GetRegValue(REGNAME_WINHEIGHT, Height);
1486 // ... state 1486 // ... state
1487 if GetRegValue(REGNAME_WINMAXIMIZED, WindowState=wsMaximized) then 1487 if GetRegValue(REGNAME_WINMAXIMIZED, WindowState=wsMaximized) then
1488 WindowState := wsMaximized; 1488 WindowState := wsMaximized;
1489 // ... and monitor placement 1489 // ... and monitor placement
1490 MonitorIndex := GetRegValue(REGNAME_WINONMONITOR, Monitor.MonitorNum); 1490 MonitorIndex := GetRegValue(REGNAME_WINONMONITOR, Monitor.MonitorNum);
1491 MonitorIndex := Max(0, MonitorIndex); 1491 MonitorIndex := Max(0, MonitorIndex);
1492 MonitorIndex := Min(Screen.MonitorCount-1, MonitorIndex); 1492 MonitorIndex := Min(Screen.MonitorCount-1, MonitorIndex);
1493 MakeFullyVisible(Screen.Monitors[MonitorIndex]); 1493 MakeFullyVisible(Screen.Monitors[MonitorIndex]);
1494 1494
1495 // Position of Toolbars 1495 // Position of Toolbars
1496 ToolBarStandard.Left := GetRegValue(REGNAME_TOOLBAR2LEFT, ToolBarStandard.Left); 1496 ToolBarStandard.Left := GetRegValue(REGNAME_TOOLBAR2LEFT, ToolBarStandard.Left);
1497 ToolBarStandard.Top := GetRegValue(REGNAME_TOOLBAR2TOP, ToolBarStandard.Top); 1497 ToolBarStandard.Top := GetRegValue(REGNAME_TOOLBAR2TOP, ToolBarStandard.Top);
1498 ToolBarData.Left := GetRegValue(REGNAME_TOOLBARDATALEFT, ToolBarData.Left); 1498 ToolBarData.Left := GetRegValue(REGNAME_TOOLBARDATALEFT, ToolBarData.Left);
1499 ToolBarData.Top := GetRegValue(REGNAME_TOOLBARDATATOP, ToolBarData.Top); 1499 ToolBarData.Top := GetRegValue(REGNAME_TOOLBARDATATOP, ToolBarData.Top);
1500 ToolBarQuery.Left := GetRegValue(REGNAME_TOOLBARQUERYLEFT, ToolBarQuery.Left); 1500 ToolBarQuery.Left := GetRegValue(REGNAME_TOOLBARQUERYLEFT, ToolBarQuery.Left);
1501 ToolBarQuery.Top := GetRegValue(REGNAME_TOOLBARQUERYTOP, ToolBarQuery.Top); 1501 ToolBarQuery.Top := GetRegValue(REGNAME_TOOLBARQUERYTOP, ToolBarQuery.Top);
1502 actQueryStopOnErrors.Checked := GetRegValue(REGNAME_STOPONERRORSINBATCH, DEFAULT_STOPONERRORSINBATCH); 1502 actQueryStopOnErrors.Checked := GetRegValue(REGNAME_STOPONERRORSINBATCH, DEFAULT_STOPONERRORSINBATCH);
1503 actBlobAsText.Checked := GetRegValue(REGNAME_BLOBASTEXT, DEFAULT_BLOBASTEXT); 1503 actBlobAsText.Checked := GetRegValue(REGNAME_BLOBASTEXT, DEFAULT_BLOBASTEXT);
1504 actQueryWordWrap.Checked := GetRegValue(REGNAME_WRAPLINES, actQueryWordWrap.Checked); 1504 actQueryWordWrap.Checked := GetRegValue(REGNAME_WRAPLINES, actQueryWordWrap.Checked);
1505 actSingleQueries.Checked := GetRegValue(REGNAME_SINGLEQUERIES, actSingleQueries.Checked); 1505 actSingleQueries.Checked := GetRegValue(REGNAME_SINGLEQUERIES, actSingleQueries.Checked);
1506 actBatchInOneGo.Checked := not GetRegValue(REGNAME_SINGLEQUERIES, actSingleQueries.Checked); 1506 actBatchInOneGo.Checked := not GetRegValue(REGNAME_SINGLEQUERIES, actSingleQueries.Checked);
1507 1507
1508 pnlQueryMemo.Height := GetRegValue(REGNAME_QUERYMEMOHEIGHT, pnlQueryMemo.Height); 1508 pnlQueryMemo.Height := GetRegValue(REGNAME_QUERYMEMOHEIGHT, pnlQueryMemo.Height);
1509 treeQueryHelpers.Width := GetRegValue(REGNAME_QUERYHELPERSWIDTH, treeQueryHelpers.Width); 1509 treeQueryHelpers.Width := GetRegValue(REGNAME_QUERYHELPERSWIDTH, treeQueryHelpers.Width);
1510 pnlLeft.Width := GetRegValue(REGNAME_DBTREEWIDTH, pnlLeft.Width); 1510 pnlLeft.Width := GetRegValue(REGNAME_DBTREEWIDTH, pnlLeft.Width);
1511 pnlPreview.Height := GetRegValue(REGNAME_PREVIEW_HEIGHT, pnlPreview.Height); 1511 pnlPreview.Height := GetRegValue(REGNAME_PREVIEW_HEIGHT, pnlPreview.Height);
1512 if GetRegValue(REGNAME_PREVIEW_ENABLED, actDataPreview.Checked) and (not actDataPreview.Checked) then 1512 if GetRegValue(REGNAME_PREVIEW_ENABLED, actDataPreview.Checked) and (not actDataPreview.Checked) then
1513 actDataPreviewExecute(actDataPreview); 1513 actDataPreviewExecute(actDataPreview);
1514 SynMemoSQLLog.Height := GetRegValue(REGNAME_SQLOUTHEIGHT, SynMemoSQLLog.Height); 1514 SynMemoSQLLog.Height := GetRegValue(REGNAME_SQLOUTHEIGHT, SynMemoSQLLog.Height);
1515 // Force status bar position to below log memo 1515 // Force status bar position to below log memo
1516 StatusBar.Top := SynMemoSQLLog.Top + SynMemoSQLLog.Height; 1516 StatusBar.Top := SynMemoSQLLog.Top + SynMemoSQLLog.Height;
1517 prefMaxColWidth := GetRegValue(REGNAME_MAXCOLWIDTH, DEFAULT_MAXCOLWIDTH); 1517 prefMaxColWidth := GetRegValue(REGNAME_MAXCOLWIDTH, DEFAULT_MAXCOLWIDTH);
1518 prefGridRowcountMax := GetRegValue(REGNAME_MAXTOTALROWS, DEFAULT_MAXTOTALROWS); 1518 prefGridRowcountMax := GetRegValue(REGNAME_MAXTOTALROWS, DEFAULT_MAXTOTALROWS);
1519 prefGridRowcountStep := GetRegValue(REGNAME_ROWSPERSTEP, DEFAULT_ROWSPERSTEP); 1519 prefGridRowcountStep := GetRegValue(REGNAME_ROWSPERSTEP, DEFAULT_ROWSPERSTEP);
1520 prefGridRowsLineCount := GetRegValue(REGNAME_GRIDROWSLINECOUNT, DEFAULT_GRIDROWSLINECOUNT); 1520 prefGridRowsLineCount := GetRegValue(REGNAME_GRIDROWSLINECOUNT, DEFAULT_GRIDROWSLINECOUNT);
1521 actDataShowNext.Hint := 'Show next '+FormatNumber(prefGridRowcountStep)+' rows ...'; 1521 actDataShowNext.Hint := 'Show next '+FormatNumber(prefGridRowcountStep)+' rows ...';
1522 actAboutBox.Caption := 'About '+APPNAME+' '+AppVersion; 1522 actAboutBox.Caption := 'About '+APPNAME+' '+AppVersion;
1523 // Fix registry entry from older versions which can have 0 here which makes no sense 1523 // Fix registry entry from older versions which can have 0 here which makes no sense
1524 // since the autosetting was removed 1524 // since the autosetting was removed
1525 if prefMaxColWidth <= 0 then 1525 if prefMaxColWidth <= 0 then
1526 prefMaxColWidth := DEFAULT_MAXCOLWIDTH; 1526 prefMaxColWidth := DEFAULT_MAXCOLWIDTH;
1527 prefLogsqlnum := GetRegValue(REGNAME_LOGSQLNUM, DEFAULT_LOGSQLNUM); 1527 prefLogsqlnum := GetRegValue(REGNAME_LOGSQLNUM, DEFAULT_LOGSQLNUM);
1528 prefLogSqlWidth := GetRegValue(REGNAME_LOGSQLWIDTH, DEFAULT_LOGSQLWIDTH); 1528 prefLogSqlWidth := GetRegValue(REGNAME_LOGSQLWIDTH, DEFAULT_LOGSQLWIDTH);
1529 prefDirnameSessionLogs := GetRegValue(REGNAME_LOGDIR, FDirnameUserAppData + 'Sessionlogs\'); 1529 prefDirnameSessionLogs := GetRegValue(REGNAME_LOGDIR, FDirnameUserAppData + 'Sessionlogs\');
1530 // Activate logging 1530 // Activate logging
1531 if GetRegValue(REGNAME_LOGTOFILE, DEFAULT_LOGTOFILE) then 1531 if GetRegValue(REGNAME_LOGTOFILE, DEFAULT_LOGTOFILE) then
1532 ActivateFileLogging; 1532 ActivateFileLogging;
1533 prefRememberFilters := GetRegValue(REGNAME_REMEMBERFILTERS, DEFAULT_REMEMBERFILTERS); 1533 prefRememberFilters := GetRegValue(REGNAME_REMEMBERFILTERS, DEFAULT_REMEMBERFILTERS);
1534 if GetRegValue(REGNAME_LOG_HORIZONTALSCROLLBAR, SynMemoSQLLog.ScrollBars = ssBoth) then 1534 if GetRegValue(REGNAME_LOG_HORIZONTALSCROLLBAR, SynMemoSQLLog.ScrollBars = ssBoth) then
1535 menuLogHorizontalScrollbar.OnClick(menuLogHorizontalScrollbar); 1535 menuLogHorizontalScrollbar.OnClick(menuLogHorizontalScrollbar);
1536 prefLogErrors := GetRegValue(REGNAME_LOG_ERRORS, DEFAULT_LOG_ERRORS); 1536 prefLogErrors := GetRegValue(REGNAME_LOG_ERRORS, DEFAULT_LOG_ERRORS);
1537 prefLogUserSQL := GetRegValue(REGNAME_LOG_USERSQL, DEFAULT_LOG_USERSQL); 1537 prefLogUserSQL := GetRegValue(REGNAME_LOG_USERSQL, DEFAULT_LOG_USERSQL);
1538 prefLogSQL := GetRegValue(REGNAME_LOG_SQL, DEFAULT_LOG_SQL); 1538 prefLogSQL := GetRegValue(REGNAME_LOG_SQL, DEFAULT_LOG_SQL);
1539 prefLogInfos := GetRegValue(REGNAME_LOG_INFOS, DEFAULT_LOG_INFOS); 1539 prefLogInfos := GetRegValue(REGNAME_LOG_INFOS, DEFAULT_LOG_INFOS);
1540 prefLogDebug := GetRegValue(REGNAME_LOG_DEBUG, DEFAULT_LOG_DEBUG); 1540 prefLogDebug := GetRegValue(REGNAME_LOG_DEBUG, DEFAULT_LOG_DEBUG);
1541 prefDisplayBars := GetRegValue(REGNAME_DISPLAYBARS, DEFAULT_DISPLAYBARS); 1541 prefDisplayBars := GetRegValue(REGNAME_DISPLAYBARS, DEFAULT_DISPLAYBARS);
1542 prefBarColor := GetRegValue(REGNAME_BARCOLOR, DEFAULT_BARCOLOR); 1542 prefBarColor := GetRegValue(REGNAME_BARCOLOR, DEFAULT_BARCOLOR);
1543 prefCompletionProposal := GetRegValue(REGNAME_COMPLETIONPROPOSAL, DEFAULT_COMPLETIONPROPOSAL); 1543 prefCompletionProposal := GetRegValue(REGNAME_COMPLETIONPROPOSAL, DEFAULT_COMPLETIONPROPOSAL);
1544 prefMaxQueryResults := GetRegValue(REGNAME_MAXQUERYRESULTS, DEFAULT_MAXQUERYRESULTS); 1544 prefMaxQueryResults := GetRegValue(REGNAME_MAXQUERYRESULTS, DEFAULT_MAXQUERYRESULTS);
1545 1545
1546 // Data-Font: 1546 // Data-Font:
1547 datafontname := GetRegValue(REGNAME_DATAFONTNAME, DEFAULT_DATAFONTNAME); 1547 datafontname := GetRegValue(REGNAME_DATAFONTNAME, DEFAULT_DATAFONTNAME);
1548 datafontsize := GetRegValue(REGNAME_DATAFONTSIZE, DEFAULT_DATAFONTSIZE); 1548 datafontsize := GetRegValue(REGNAME_DATAFONTSIZE, DEFAULT_DATAFONTSIZE);
1549 DataGrid.Font.Name := datafontname; 1549 DataGrid.Font.Name := datafontname;
1550 QueryGrid.Font.Name := datafontname; 1550 QueryGrid.Font.Name := datafontname;
1551 DataGrid.Font.Size := datafontsize; 1551 DataGrid.Font.Size := datafontsize;
1552 QueryGrid.Font.Size := datafontsize; 1552 QueryGrid.Font.Size := datafontsize;
1553 FixVT(DataGrid, prefGridRowsLineCount); 1553 FixVT(DataGrid, prefGridRowsLineCount);
1554 FixVT(QueryGrid, prefGridRowsLineCount); 1554 FixVT(QueryGrid, prefGridRowsLineCount);
1555 // Load color settings 1555 // Load color settings
1556 DatatypeCategories[dtcInteger].Color := GetRegValue(REGNAME_FIELDCOLOR_INTEGER, DEFAULT_FIELDCOLOR_INTEGER); 1556 DatatypeCategories[dtcInteger].Color := GetRegValue(REGNAME_FIELDCOLOR_INTEGER, DEFAULT_FIELDCOLOR_INTEGER);
1557 DatatypeCategories[dtcReal].Color := GetRegValue(REGNAME_FIELDCOLOR_REAL, DEFAULT_FIELDCOLOR_REAL); 1557 DatatypeCategories[dtcReal].Color := GetRegValue(REGNAME_FIELDCOLOR_REAL, DEFAULT_FIELDCOLOR_REAL);
1558 DatatypeCategories[dtcText].Color := GetRegValue(REGNAME_FIELDCOLOR_TEXT, DEFAULT_FIELDCOLOR_TEXT); 1558 DatatypeCategories[dtcText].Color := GetRegValue(REGNAME_FIELDCOLOR_TEXT, DEFAULT_FIELDCOLOR_TEXT);
1559 DatatypeCategories[dtcBinary].Color := GetRegValue(REGNAME_FIELDCOLOR_BINARY, DEFAULT_FIELDCOLOR_BINARY); 1559 DatatypeCategories[dtcBinary].Color := GetRegValue(REGNAME_FIELDCOLOR_BINARY, DEFAULT_FIELDCOLOR_BINARY);
1560 DatatypeCategories[dtcTemporal].Color := GetRegValue(REGNAME_FIELDCOLOR_DATETIME, DEFAULT_FIELDCOLOR_DATETIME); 1560 DatatypeCategories[dtcTemporal].Color := GetRegValue(REGNAME_FIELDCOLOR_DATETIME, DEFAULT_FIELDCOLOR_DATETIME);
1561 DatatypeCategories[dtcSpatial].Color := GetRegValue(REGNAME_FIELDCOLOR_SPATIAL, DEFAULT_FIELDCOLOR_SPATIAL); 1561 DatatypeCategories[dtcSpatial].Color := GetRegValue(REGNAME_FIELDCOLOR_SPATIAL, DEFAULT_FIELDCOLOR_SPATIAL);
1562 DatatypeCategories[dtcOther].Color := GetRegValue(REGNAME_FIELDCOLOR_OTHER, DEFAULT_FIELDCOLOR_OTHER); 1562 DatatypeCategories[dtcOther].Color := GetRegValue(REGNAME_FIELDCOLOR_OTHER, DEFAULT_FIELDCOLOR_OTHER);
1563 prefNullBG := GetRegValue(REGNAME_BG_NULL, DEFAULT_BG_NULL); 1563 prefNullBG := GetRegValue(REGNAME_BG_NULL, DEFAULT_BG_NULL);
1564 CalcNullColors; 1564 CalcNullColors;
1565 // Editor enablings 1565 // Editor enablings
1566 prefEnableBinaryEditor := GetRegValue(REGNAME_FIELDEDITOR_BINARY, DEFAULT_FIELDEDITOR_BINARY); 1566 prefEnableBinaryEditor := GetRegValue(REGNAME_FIELDEDITOR_BINARY, DEFAULT_FIELDEDITOR_BINARY);
1567 prefEnableDatetimeEditor := GetRegValue(REGNAME_FIELDEDITOR_DATETIME, DEFAULT_FIELDEDITOR_DATETIME); 1567 prefEnableDatetimeEditor := GetRegValue(REGNAME_FIELDEDITOR_DATETIME, DEFAULT_FIELDEDITOR_DATETIME);
1568 prefPrefillDateTime := GetRegValue(REGNAME_PREFILL_DATETIME, DEFAULT_PREFILL_DATETIME); 1568 prefPrefillDateTime := GetRegValue(REGNAME_PREFILL_DATETIME, DEFAULT_PREFILL_DATETIME);
1569 prefEnableEnumEditor := GetRegValue(REGNAME_FIELDEDITOR_ENUM, DEFAULT_FIELDEDITOR_ENUM); 1569 prefEnableEnumEditor := GetRegValue(REGNAME_FIELDEDITOR_ENUM, DEFAULT_FIELDEDITOR_ENUM);
1570 prefEnableSetEditor := GetRegValue(REGNAME_FIELDEDITOR_SET, DEFAULT_FIELDEDITOR_SET); 1570 prefEnableSetEditor := GetRegValue(REGNAME_FIELDEDITOR_SET, DEFAULT_FIELDEDITOR_SET);
1571 1571
1572 // Switch off/on displaying table/db sized in tree 1572 // Switch off/on displaying table/db sized in tree
1573 menuShowSizeColumn.Checked := GetRegValue(REGNAME_SIZECOL_TREE, DEFAULT_SIZECOL_TREE); 1573 menuShowSizeColumn.Checked := GetRegValue(REGNAME_SIZECOL_TREE, DEFAULT_SIZECOL_TREE);
1574 if menuShowSizeColumn.Checked then 1574 if menuShowSizeColumn.Checked then
1575 DBtree.Header.Columns[1].Options := DBtree.Header.Columns[1].Options + [coVisible] 1575 DBtree.Header.Columns[1].Options := DBtree.Header.Columns[1].Options + [coVisible]
1576 else 1576 else
1577 DBtree.Header.Columns[1].Options := DBtree.Header.Columns[1].Options - [coVisible]; 1577 DBtree.Header.Columns[1].Options := DBtree.Header.Columns[1].Options - [coVisible];
1578 1578
1579 // Restore width of columns of all VirtualTrees 1579 // Restore width of columns of all VirtualTrees
1580 RestoreListSetup(ListDatabases); 1580 RestoreListSetup(ListDatabases);
1581 RestoreListSetup(ListVariables); 1581 RestoreListSetup(ListVariables);
1582 RestoreListSetup(ListStatus); 1582 RestoreListSetup(ListStatus);
1583 RestoreListSetup(ListProcesses); 1583 RestoreListSetup(ListProcesses);
1584 RestoreListSetup(ListCommandStats); 1584 RestoreListSetup(ListCommandStats);
1585 RestoreListSetup(ListTables); 1585 RestoreListSetup(ListTables);
1586 1586
1587 // Shortcuts 1587 // Shortcuts
1588 for i:=0 to ActionList1.ActionCount-1 do begin 1588 for i:=0 to ActionList1.ActionCount-1 do begin
1589 Action := TAction(ActionList1.Actions[i]); 1589 Action := TAction(ActionList1.Actions[i]);
1590 Action.ShortCut := GetRegValue(REGPREFIX_SHORTCUT1+Action.Name, Action.ShortCut); 1590 Action.ShortCut := GetRegValue(REGPREFIX_SHORTCUT1+Action.Name, Action.ShortCut);
1591 end; 1591 end;
1592 1592
1593 // Place progressbar on the statusbar 1593 // Place progressbar on the statusbar
1594 ProgressBarStatus.Parent := StatusBar; 1594 ProgressBarStatus.Parent := StatusBar;
1595 ProgressBarStatus.Visible := False; 1595 ProgressBarStatus.Visible := False;
1596 1596
1597 // SynMemo font, hightlighting and shortcuts 1597 // SynMemo font, hightlighting and shortcuts
1598 SetupSynEditors; 1598 SetupSynEditors;
1599 1599
1600 FBtnAddTab := TSpeedButton.Create(PageControlMain); 1600 FBtnAddTab := TSpeedButton.Create(PageControlMain);
1601 FBtnAddTab.Parent := PageControlMain; 1601 FBtnAddTab.Parent := PageControlMain;
1602 ImageListMain.GetBitmap(actNewQueryTab.ImageIndex, FBtnAddTab.Glyph); 1602 ImageListMain.GetBitmap(actNewQueryTab.ImageIndex, FBtnAddTab.Glyph);
1603 FBtnAddTab.Height := PageControlMain.TabRect(0).Bottom - PageControlMain.TabRect(0).Top - 2; 1603 FBtnAddTab.Height := PageControlMain.TabRect(0).Bottom - PageControlMain.TabRect(0).Top - 2;
1604 FBtnAddTab.Width := FBtnAddTab.Height; 1604 FBtnAddTab.Width := FBtnAddTab.Height;
1605 FBtnAddTab.Flat := True; 1605 FBtnAddTab.Flat := True;
1606 FBtnAddTab.Hint := actNewQueryTab.Hint; 1606 FBtnAddTab.Hint := actNewQueryTab.Hint;
1607 FBtnAddTab.OnClick := actNewQueryTab.OnExecute; 1607 FBtnAddTab.OnClick := actNewQueryTab.OnExecute;
1608 1608
1609 // Filter panel 1609 // Filter panel
1610 ImageListMain.GetBitmap(134, btnCloseFilterPanel.Glyph); 1610 ImageListMain.GetBitmap(134, btnCloseFilterPanel.Glyph);
1611 if GetRegValue(REGNAME_FILTERACTIVE, DEFAULT_FILTERACTIVE) then 1611 if GetRegValue(REGNAME_FILTERACTIVE, DEFAULT_FILTERACTIVE) then
1612 actFilterPanelExecute(nil); 1612 actFilterPanelExecute(nil);
1613 lblFilterVTInfo.Caption := ''; 1613 lblFilterVTInfo.Caption := '';
1614 1614
1615 SelectedTableColumns := TTableColumnList.Create; 1615 SelectedTableColumns := TTableColumnList.Create;
1616 SelectedTableKeys := TTableKeyList.Create; 1616 SelectedTableKeys := TTableKeyList.Create;
1617 SelectedTableForeignKeys := TForeignKeyList.Create; 1617 SelectedTableForeignKeys := TForeignKeyList.Create;
1618 1618
1619 // Set up connections list 1619 // Set up connections list
1620 FConnections := TDBConnectionList.Create; 1620 FConnections := TDBConnectionList.Create;
1621 FConnections.OnNotify := ConnectionsNotify; 1621 FConnections.OnNotify := ConnectionsNotify;
1622 1622
1623 // Load database filter items. Was previously bound to sessions before multi connections were implemented 1623 // Load database filter items. Was previously bound to sessions before multi connections were implemented
1624 comboDBFilter.Items.Text := GetRegValue(REGNAME_DATABASE_FILTER, ''); 1624 comboDBFilter.Items.Text := GetRegValue(REGNAME_DATABASE_FILTER, '');
1625 if comboDBFilter.Items.Count > 0 then 1625 if comboDBFilter.Items.Count > 0 then
1626 comboDBFilter.ItemIndex := 0 1626 comboDBFilter.ItemIndex := 0
1627 else 1627 else
1628 comboDBFilter.Text := ''; 1628 comboDBFilter.Text := '';
1629 1629
1630 FTreeRefreshInProgress := False; 1630 FTreeRefreshInProgress := False;
1631 1631
1632 FileEncodings := Explode(',', 'Auto detect (may fail),ANSI,ASCII,Unicode,Unicode Big Endian,UTF-8,UTF-7'); 1632 FileEncodings := Explode(',', 'Auto detect (may fail),ANSI,ASCII,Unicode,Unicode Big Endian,UTF-8,UTF-7');
1633 end; 1633 end;
1634 1634
1635 1635
1636 {** 1636 {**
1637 Check for connection parameters on commandline or show connections form. 1637 Check for connection parameters on commandline or show connections form.
1638 } 1638 }
1639 procedure TMainForm.Startup; 1639 procedure TMainForm.Startup;
1640 var 1640 var
1641 CmdlineParameters, LastSessions: TStringlist; 1641 CmdlineParameters, LastSessions: TStringlist;
1642 Connection: TDBConnection; 1642 Connection: TDBConnection;
1643 LoadedParams: TConnectionParameters; 1643 LoadedParams: TConnectionParameters;
1644 LastUpdatecheck, LastStatsCall, LastConnect: TDateTime; 1644 LastUpdatecheck, LastStatsCall, LastConnect: TDateTime;
1645 UpdatecheckInterval, i: Integer; 1645 UpdatecheckInterval, i: Integer;
1646 DefaultLastrunDate, LastActiveSession, StatsURL: String; 1646 DefaultLastrunDate, LastActiveSession, StatsURL: String;
1647 frm : TfrmUpdateCheck; 1647 frm : TfrmUpdateCheck;
1648 Connected, DecideForStatistic: Boolean; 1648 Connected, DecideForStatistic: Boolean;
1649 StatsCall: TDownloadUrl2; 1649 StatsCall: TDownloadUrl2;
1650 SessionNames: TStringlist; 1650 SessionNames: TStringlist;
1651 DlgResult: TModalResult; 1651 DlgResult: TModalResult;
1652 Tab: TQueryTab; 1652 Tab: TQueryTab;
1653 SessionManager: TConnForm; 1653 SessionManager: TConnForm;
1654 begin 1654 begin
1655 DefaultLastrunDate := '2000-01-01'; 1655 DefaultLastrunDate := '2000-01-01';
1656 1656
1657 // Do an updatecheck if checked in settings 1657 // Do an updatecheck if checked in settings
1658 if GetRegValue(REGNAME_DO_UPDATECHECK, DEFAULT_DO_UPDATECHECK) then begin 1658 if GetRegValue(REGNAME_DO_UPDATECHECK, DEFAULT_DO_UPDATECHECK) then begin
1659 try 1659 try
1660 LastUpdatecheck := StrToDateTime( GetRegValue(REGNAME_LAST_UPDATECHECK, DefaultLastrunDate) ); 1660 LastUpdatecheck := StrToDateTime( GetRegValue(REGNAME_LAST_UPDATECHECK, DefaultLastrunDate) );
1661 except 1661 except
1662 LastUpdatecheck := StrToDateTime( DefaultLastrunDate ); 1662 LastUpdatecheck := StrToDateTime( DefaultLastrunDate );
1663 end; 1663 end;
1664 UpdatecheckInterval := GetRegValue(REGNAME_UPDATECHECK_INTERVAL, DEFAULT_UPDATECHECK_INTERVAL); 1664 UpdatecheckInterval := GetRegValue(REGNAME_UPDATECHECK_INTERVAL, DEFAULT_UPDATECHECK_INTERVAL);
1665 if DaysBetween(Now, LastUpdatecheck) >= UpdatecheckInterval then begin 1665 if DaysBetween(Now, LastUpdatecheck) >= UpdatecheckInterval then begin
1666 frm := TfrmUpdateCheck.Create(Self); 1666 frm := TfrmUpdateCheck.Create(Self);
1667 frm.AutoClose := True; 1667 frm.AutoClose := True;
1668 frm.CheckForBuildsInAutoMode := GetRegValue(REGNAME_DO_UPDATECHECK_BUILDS, DEFAULT_DO_UPDATECHECK_BUILDS); 1668 frm.CheckForBuildsInAutoMode := GetRegValue(REGNAME_DO_UPDATECHECK_BUILDS, DEFAULT_DO_UPDATECHECK_BUILDS);
1669 frm.ShowModal; 1669 frm.ShowModal;
1670 FreeAndNil(frm); 1670 FreeAndNil(frm);
1671 end; 1671 end;
1672 end; 1672 end;
1673 1673
1674 // Get all session names 1674 // Get all session names
1675 SessionNames := TStringlist.Create; 1675 SessionNames := TStringlist.Create;
1676 if MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, true) then 1676 if MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, true) then
1677 MainReg.GetKeyNames(SessionNames); 1677 MainReg.GetKeyNames(SessionNames);
1678 1678
1679 // Call user statistics if checked in settings 1679 // Call user statistics if checked in settings
1680 if GetRegValue(REGNAME_DO_STATISTICS, DEFAULT_DO_STATISTICS) then begin 1680 if GetRegValue(REGNAME_DO_STATISTICS, DEFAULT_DO_STATISTICS) then begin
1681 try 1681 try
1682 LastStatsCall := StrToDateTime( GetRegValue(REGNAME_LAST_STATSCALL, DefaultLastrunDate) ); 1682 LastStatsCall := StrToDateTime( GetRegValue(REGNAME_LAST_STATSCALL, DefaultLastrunDate) );
1683 except 1683 except
1684 LastStatsCall := StrToDateTime( DefaultLastrunDate ); 1684 LastStatsCall := StrToDateTime( DefaultLastrunDate );
1685 end; 1685 end;
1686 if DaysBetween(Now, LastStatsCall) >= 30 then begin 1686 if DaysBetween(Now, LastStatsCall) >= 30 then begin
1687 // Report used SVN revision 1687 // Report used SVN revision
1688 StatsURL := APPDOMAIN + 'savestats.php?c=' + IntToStr(AppVerRevision); 1688 StatsURL := APPDOMAIN + 'savestats.php?c=' + IntToStr(AppVerRevision);
1689 // Enumerate actively used server versions 1689 // Enumerate actively used server versions
1690 for i:=0 to SessionNames.Count-1 do begin 1690 for i:=0 to SessionNames.Count-1 do begin
1691 try 1691 try
1692 LastConnect := StrToDateTime(GetRegValue(REGNAME_LASTCONNECT, DefaultLastrunDate, SessionNames[i])); 1692 LastConnect := StrToDateTime(GetRegValue(REGNAME_LASTCONNECT, DefaultLastrunDate, SessionNames[i]));
1693 except 1693 except
1694 LastConnect := StrToDateTime(DefaultLastrunDate); 1694 LastConnect := StrToDateTime(DefaultLastrunDate);
1695 end; 1695 end;
1696 if LastConnect > LastStatsCall then begin 1696 if LastConnect > LastStatsCall then begin
1697 StatsURL := StatsURL + '&s[]=' + IntToStr(GetRegValue(REGNAME_SERVERVERSION, 0, SessionNames[i])); 1697 StatsURL := StatsURL + '&s[]=' + IntToStr(GetRegValue(REGNAME_SERVERVERSION, 0, SessionNames[i]));
1698 end; 1698 end;
1699 end; 1699 end;
1700 StatsCall := TDownloadUrl2.Create(Self); 1700 StatsCall := TDownloadUrl2.Create(Self);
1701 StatsCall.URL := StatsURL; 1701 StatsCall.URL := StatsURL;
1702 StatsCall.SetUserAgent(APPNAME + ' ' + AppVersion); 1702 StatsCall.SetUserAgent(APPNAME + ' ' + AppVersion);
1703 try 1703 try
1704 StatsCall.ExecuteTarget(nil); 1704 StatsCall.ExecuteTarget(nil);
1705 OpenRegistry; 1705 OpenRegistry;
1706 MainReg.WriteString(REGNAME_LAST_STATSCALL, DateTimeToStr(Now)); 1706 MainReg.WriteString(REGNAME_LAST_STATSCALL, DateTimeToStr(Now));
1707 except 1707 except
1708 // Silently ignore it when the url could not be called over the network. 1708 // Silently ignore it when the url could not be called over the network.
1709 end; 1709 end;
1710 FreeAndNil(StatsCall); 1710 FreeAndNil(StatsCall);
1711 end; 1711 end;
1712 end; 1712 end;
1713 1713
1714 // Ask if we shall activate statistic calls. Would be used by noone otherwise. 1714 // Ask if we shall activate statistic calls. Would be used by noone otherwise.
1715 OpenRegistry; 1715 OpenRegistry;
1716 if not Mainreg.ValueExists(REGNAME_DO_STATISTICS) then begin 1716 if not Mainreg.ValueExists(REGNAME_DO_STATISTICS) then begin
1717 DecideForStatistic := MessageDialog(APPNAME + ' has a new statistics feature: If activated, server and client versions '+ 1717 DecideForStatistic := MessageDialog(APPNAME + ' has a new statistics feature: If activated, server and client versions '+
1718 'are reported once per month and displayed on heidisql.com.'+CRLF+CRLF+'Activate this feature?', 1718 'are reported once per month and displayed on heidisql.com.'+CRLF+CRLF+'Activate this feature?',
1719 mtConfirmation, [mbYes, mbNo]) = mrYes; 1719 mtConfirmation, [mbYes, mbNo]) = mrYes;
1720 Mainreg.WriteBool(REGNAME_DO_STATISTICS, DecideForStatistic); 1720 Mainreg.WriteBool(REGNAME_DO_STATISTICS, DecideForStatistic);
1721 end; 1721 end;
1722 1722
1723 Connected := False; 1723 Connected := False;
1724 1724
1725 OpenRegistry; 1725 OpenRegistry;
1726 CmdlineParameters := TStringList.Create; 1726 CmdlineParameters := TStringList.Create;
1727 for i:=1 to ParamCount do 1727 for i:=1 to ParamCount do
1728 CmdlineParameters.Add(ParamStr(i)); 1728 CmdlineParameters.Add(ParamStr(i));
1729 ParseCommandLineParameters(CmdlineParameters); 1729 ParseCommandLineParameters(CmdlineParameters);
1730 if Assigned(FCmdlineConnectionParams) then begin 1730 if Assigned(FCmdlineConnectionParams) then begin
1731 // Minimal parameter for command line mode is hostname 1731 // Minimal parameter for command line mode is hostname
1732 Connected := InitConnection(FCmdlineConnectionParams, True, Connection); 1732 Connected := InitConnection(FCmdlineConnectionParams, True, Connection);
1733 end else if GetRegValue(REGNAME_AUTORECONNECT, DEFAULT_AUTORECONNECT) then begin 1733 end else if GetRegValue(REGNAME_AUTORECONNECT, DEFAULT_AUTORECONNECT) then begin
1734 // Auto connection via preference setting 1734 // Auto connection via preference setting
1735 // Do not autoconnect if we're in commandline mode and the connection was not successful 1735 // Do not autoconnect if we're in commandline mode and the connection was not successful
1736 LastSessions := Explode(DELIM, GetRegValue(REGNAME_LASTSESSIONS, '')); 1736 LastSessions := Explode(DELIM, GetRegValue(REGNAME_LASTSESSIONS, ''));
1737 LastActiveSession := GetRegValue(REGNAME_LASTACTIVESESSION, ''); 1737 LastActiveSession := GetRegValue(REGNAME_LASTACTIVESESSION, '');
1738 for i:=LastSessions.Count-1 downto 0 do begin 1738 for i:=LastSessions.Count-1 downto 0 do begin
1739 if SessionNames.IndexOf(LastSessions[i]) = -1 then 1739 if SessionNames.IndexOf(LastSessions[i]) = -1 then
1740 LastSessions.Delete(i); 1740 LastSessions.Delete(i);
1741 end; 1741 end;
1742 if LastSessions.Count > 0 then begin 1742 if LastSessions.Count > 0 then begin
1743 if LastSessions.IndexOf(LastActiveSession) = -1 then 1743 if LastSessions.IndexOf(LastActiveSession) = -1 then
1744 LastActiveSession := LastSessions[0]; 1744 LastActiveSession := LastSessions[0];
1745 for i:=0 to LastSessions.Count-1 do begin 1745 for i:=0 to LastSessions.Count-1 do begin
1746 try 1746 try
1747 LoadedParams := TConnectionParameters.ReadFromRegistry(LastSessions[i]); 1747 LoadedParams := TConnectionParameters.ReadFromRegistry(LastSessions[i]);
1748 if InitConnection(LoadedParams, LastActiveSession=LastSessions[i], Connection) then 1748 if InitConnection(LoadedParams, LastActiveSession=LastSessions[i], Connection) then
1749 Connected := True; 1749 Connected := True;
1750 except on E:Exception do 1750 except on E:Exception do
1751 ErrorDialog(E.Message); 1751 ErrorDialog(E.Message);
1752 end; 1752 end;
1753 end; 1753 end;
1754 end; 1754 end;
1755 end; 1755 end;
1756 1756
1757 // Display session manager 1757 // Display session manager
1758 if not Connected then begin 1758 if not Connected then begin
1759 // Cannot be done in OnCreate because we need ready forms here: 1759 // Cannot be done in OnCreate because we need ready forms here:
1760 SessionManager := TConnForm.Create(Self); 1760 SessionManager := TConnForm.Create(Self);
1761 DlgResult := mrCancel; 1761 DlgResult := mrCancel;
1762 try 1762 try
1763 DlgResult := SessionManager.ShowModal; 1763 DlgResult := SessionManager.ShowModal;
1764 SessionManager.Free; 1764 SessionManager.Free;
1765 except 1765 except
1766 // Work around VCL bug: Suppress access violation in TCustomForm.IsFormSizeStored 1766 // Work around VCL bug: Suppress access violation in TCustomForm.IsFormSizeStored
1767 // when closing dialog via Alt+F4 1767 // when closing dialog via Alt+F4
1768 end; 1768 end;
1769 if DlgResult = mrCancel then begin 1769 if DlgResult = mrCancel then begin
1770 Free; 1770 Free;
1771 Exit; 1771 Exit;
1772 end; 1772 end;
1773 end; 1773 end;
1774 1774
1775 // Load SQL file(s) by command line 1775 // Load SQL file(s) by command line
1776 if not RunQueryFiles(FCmdlineFilenames, nil) then begin 1776 if not RunQueryFiles(FCmdlineFilenames, nil) then begin
1777 for i:=0 to FCmdlineFilenames.Count-1 do begin 1777 for i:=0 to FCmdlineFilenames.Count-1 do begin
1778 Tab := ActiveOrEmptyQueryTab(False); 1778 Tab := ActiveOrEmptyQueryTab(False);
1779 Tab.LoadContents(FCmdlineFilenames[i], True, nil); 1779 Tab.LoadContents(FCmdlineFilenames[i], True, nil);
1780 if i = FCmdlineFilenames.Count-1 then 1780 if i = FCmdlineFilenames.Count-1 then
1781 SetMainTab(Tab.TabSheet); 1781 SetMainTab(Tab.TabSheet);
1782 end; 1782 end;
1783 end; 1783 end;
1784 end; 1784 end;
1785 1785
1786 1786
1787 procedure TMainForm.ParseCommandLineParameters(Parameters: TStringlist); 1787 procedure TMainForm.ParseCommandLineParameters(Parameters: TStringlist);
1788 var 1788 var
1789 rx: TRegExpr; 1789 rx: TRegExpr;
1790 AllParams, SessName, Host, User, Pass, Socket: String; 1790 AllParams, SessName, Host, User, Pass, Socket: String;
1791 i, Port: Integer; 1791 i, Port: Integer;
1792 1792
1793 function GetParamValue(ShortName, LongName: String): String; 1793 function GetParamValue(ShortName, LongName: String): String;
1794 begin 1794 begin
1795 Result := ''; 1795 Result := '';
1796 rx.Expression := '\s(\-'+ShortName+'|\-\-'+LongName+')\s*\=?\s*([^\-]\S*)'; 1796 rx.Expression := '\s(\-'+ShortName+'|\-\-'+LongName+')\s*\=?\s*([^\-]\S*)';
1797 if rx.Exec(AllParams) then 1797 if rx.Exec(AllParams) then
1798 Result := rx.Match[2]; 1798 Result := rx.Match[2];
1799 end; 1799 end;
1800 1800
1801 begin 1801 begin
1802 // Initialize and clear variables 1802 // Initialize and clear variables
1803 if not Assigned(FCmdlineFilenames) then 1803 if not Assigned(FCmdlineFilenames) then
1804 FCmdlineFilenames := TStringlist.Create; 1804 FCmdlineFilenames := TStringlist.Create;
1805 FCmdlineFilenames.Clear; 1805 FCmdlineFilenames.Clear;
1806 SessName := ''; 1806 SessName := '';
1807 FreeAndNil(FCmdlineConnectionParams); 1807 FreeAndNil(FCmdlineConnectionParams);
1808 1808
1809 // Prepend a space, so the regular expression can request a mandantory space 1809 // Prepend a space, so the regular expression can request a mandantory space
1810 // before each param name including the first one 1810 // before each param name including the first one
1811 AllParams := ' ' + ImplodeStr(' ', Parameters); 1811 AllParams := ' ' + ImplodeStr(' ', Parameters);
1812 rx := TRegExpr.Create; 1812 rx := TRegExpr.Create;
1813 SessName := GetParamValue('d', 'description'); 1813 SessName := GetParamValue('d', 'description');
1814 if SessName <> '' then begin 1814 if SessName <> '' then begin
1815 try 1815 try
1816 FCmdlineConnectionParams := TConnectionParameters.ReadFromRegistry(SessName); 1816 FCmdlineConnectionParams := TConnectionParameters.ReadFromRegistry(SessName);
1817 except 1817 except
1818 on E:Exception do begin 1818 on E:Exception do begin
1819 // Session params not found in registry 1819 // Session params not found in registry
1820 LogSQL(E.Message); 1820 LogSQL(E.Message);
1821 SessName := ''; 1821 SessName := '';
1822 end; 1822 end;
1823 end; 1823 end;
1824 1824
1825 end; 1825 end;
1826 1826
1827 // Test if params were passed. If given, override previous values loaded from registry. 1827 // Test if params were passed. If given, override previous values loaded from registry.
1828 // Enables the user to log into a session with a different, non-stored user: -dSession -uSomeOther 1828 // Enables the user to log into a session with a different, non-stored user: -dSession -uSomeOther
1829 Host := GetParamValue('h', 'host'); 1829 Host := GetParamValue('h', 'host');
1830 User := GetParamValue('u', 'user'); 1830 User := GetParamValue('u', 'user');
1831 Pass := GetParamValue('p', 'password'); 1831 Pass := GetParamValue('p', 'password');
1832 Socket := GetParamValue('S', 'socket'); 1832 Socket := GetParamValue('S', 'socket');
1833 Port := StrToIntDef(GetParamValue('P', 'port'), 0); 1833 Port := StrToIntDef(GetParamValue('P', 'port'), 0);
1834 // Leave out support for startup script, seems reasonable for command line connecting 1834 // Leave out support for startup script, seems reasonable for command line connecting
1835 1835
1836 if (Host <> '') or (User <> '') or (Pass <> '') or (Port <> 0) or (Socket <> '') then begin 1836 if (Host <> '') or (User <> '') or (Pass <> '') or (Port <> 0) or (Socket <> '') then begin
1837 if not Assigned(FCmdlineConnectionParams) then begin 1837 if not Assigned(FCmdlineConnectionParams) then begin
1838 FCmdlineConnectionParams := TConnectionParameters.Create; 1838 FCmdlineConnectionParams := TConnectionParameters.Create;
1839 FCmdlineConnectionParams.SessionName := SessName; 1839 FCmdlineConnectionParams.SessionName := SessName;
1840 end; 1840 end;
1841 if Host <> '' then FCmdlineConnectionParams.Hostname := Host; 1841 if Host <> '' then FCmdlineConnectionParams.Hostname := Host;
1842 if User <> '' then FCmdlineConnectionParams.Username := User; 1842 if User <> '' then FCmdlineConnectionParams.Username := User;
1843 if Pass <> '' then FCmdlineConnectionParams.Password := Pass; 1843 if Pass <> '' then FCmdlineConnectionParams.Password := Pass;
1844 if Port <> 0 then FCmdlineConnectionParams.Port := Port; 1844 if Port <> 0 then FCmdlineConnectionParams.Port := Port;
1845 if Socket <> '' then begin 1845 if Socket <> '' then begin
1846 FCmdlineConnectionParams.Hostname := Socket; 1846 FCmdlineConnectionParams.Hostname := Socket;
1847 FCmdlineConnectionParams.NetType := ntMySQL_NamedPipe; 1847 FCmdlineConnectionParams.NetType := ntMySQL_NamedPipe;
1848 end; 1848 end;
1849 // Ensure we have a session name to pass to InitConnection 1849 // Ensure we have a session name to pass to InitConnection
1850 if (FCmdlineConnectionParams.SessionName = '') and (FCmdlineConnectionParams.Hostname <> '') then 1850 if (FCmdlineConnectionParams.SessionName = '') and (FCmdlineConnectionParams.Hostname <> '') then
1851 FCmdlineConnectionParams.SessionName := FCmdlineConnectionParams.Hostname; 1851 FCmdlineConnectionParams.SessionName := FCmdlineConnectionParams.Hostname;
1852 end; 1852 end;
1853 1853
1854 // Check for valid filename(s) in parameters 1854 // Check for valid filename(s) in parameters
1855 for i:=0 to Parameters.Count-1 do begin 1855 for i:=0 to Parameters.Count-1 do begin
1856 if FileExists(Parameters[i]) then 1856 if FileExists(Parameters[i]) then
1857 FCmdlineFilenames.Add(Parameters[i]); 1857 FCmdlineFilenames.Add(Parameters[i]);
1858 end; 1858 end;
1859 end; 1859 end;
1860 1860
1861 1861
1862 procedure TMainForm.actSessionManagerExecute(Sender: TObject); 1862 procedure TMainForm.actSessionManagerExecute(Sender: TObject);
1863 var 1863 var
1864 Dialog: TConnForm; 1864 Dialog: TConnForm;
1865 begin 1865 begin
1866 Dialog := TConnForm.Create(Self); 1866 Dialog := TConnForm.Create(Self);
1867 Dialog.ShowModal; 1867 Dialog.ShowModal;
1868 end; 1868 end;
1869 1869
1870 1870
1871 procedure TMainForm.actDisconnectExecute(Sender: TObject); 1871 procedure TMainForm.actDisconnectExecute(Sender: TObject);
1872 var 1872 var
1873 Connection: TDBConnection; 1873 Connection: TDBConnection;
1874 Node: PVirtualNode; 1874 Node: PVirtualNode;
1875 DlgResult: Integer; 1875 DlgResult: Integer;
1876 Dialog: TConnForm; 1876 Dialog: TConnForm;
1877 begin 1877 begin
1878 // Disconnect active connection. If it's the last, exit application 1878 // Disconnect active connection. If it's the last, exit application
1879 Connection := ActiveConnection; 1879 Connection := ActiveConnection;
1880 // Find and remove connection node from tree 1880 // Find and remove connection node from tree
1881 Node := GetRootNode(DBtree, Connection); 1881 Node := GetRootNode(DBtree, Connection);
1882 DBTree.DeleteNode(Node, True); 1882 DBTree.DeleteNode(Node, True);
1883 FConnections.Remove(Connection); 1883 FConnections.Remove(Connection);
1884 // TODO: focus last session? 1884 // TODO: focus last session?
1885 SelectNode(DBtree, GetNextNode(DBtree, nil)); 1885 SelectNode(DBtree, GetNextNode(DBtree, nil));
1886 if FConnections.Count = 0 then begin 1886 if FConnections.Count = 0 then begin
1887 Dialog := TConnForm.Create(Self); 1887 Dialog := TConnForm.Create(Self);
1888 DlgResult := Dialog.ShowModal; 1888 DlgResult := Dialog.ShowModal;
1889 if DlgResult = mrCancel then 1889 if DlgResult = mrCancel then
1890 actExitApplication.Execute; 1890 actExitApplication.Execute;
1891 end; 1891 end;
1892 end; 1892 end;
1893 1893
1894 1894
1895 procedure TMainForm.ConnectionsNotify(Sender: TObject; const Item: TDBConnection; Action: TCollectionNotification); 1895 procedure TMainForm.ConnectionsNotify(Sender: TObject; const Item: TDBConnection; Action: TCollectionNotification);
1896 var 1896 var
1897 Results: TDBQuery; 1897 Results: TDBQuery;
1898 Tab: TQueryTab; 1898 Tab: TQueryTab;
1899 ResultTab: TResultTab; 1899 ResultTab: TResultTab;
1900 i: Integer; 1900 i: Integer;
1901 Keys: TStringList; 1901 Keys: TStringList;
1902 rx: TRegExpr; 1902 rx: TRegExpr;
1903 begin 1903 begin
1904 // Connection removed or added 1904 // Connection removed or added
1905 case Action of 1905 case Action of
1906 cnRemoved, cnExtracted: begin 1906 cnRemoved, cnExtracted: begin
1907 // Post pending UPDATE 1907 // Post pending UPDATE
1908 Results := GridResult(DataGrid); 1908 Results := GridResult(DataGrid);
1909 if Assigned(Results) and Results.Modified then 1909 if Assigned(Results) and Results.Modified then
1910 actDataPostChangesExecute(DataGrid); 1910 actDataPostChangesExecute(DataGrid);
1911 1911
1912 // Remove result sets which may cause AVs when disconnected 1912 // Remove result sets which may cause AVs when disconnected
1913 for Tab in QueryTabs do begin 1913 for Tab in QueryTabs do begin
1914 if Assigned(Tab.QueryProfile) and (Tab.QueryProfile.Connection = Item) then 1914 if Assigned(Tab.QueryProfile) and (Tab.QueryProfile.Connection = Item) then
1915 FreeAndNil(Tab.QueryProfile); 1915 FreeAndNil(Tab.QueryProfile);
1916 for ResultTab in Tab.ResultTabs do begin 1916 for ResultTab in Tab.ResultTabs do begin
1917 if ResultTab.Results.Connection = Item then begin 1917 if ResultTab.Results.Connection = Item then begin
1918 Tab.ResultTabs.Clear; 1918 Tab.ResultTabs.Clear;
1919 Tab.tabsetQuery.Tabs.Clear; 1919 Tab.tabsetQuery.Tabs.Clear;
1920 break; 1920 break;
1921 end; 1921 end;
1922 end; 1922 end;
1923 end; 1923 end;
1924 for i:=0 to FHostListResults.Count-1 do begin 1924 for i:=0 to FHostListResults.Count-1 do begin
1925 if (FHostListResults[i] <> nil) and (FHostListResults[i].Connection = Item) then begin 1925 if (FHostListResults[i] <> nil) and (FHostListResults[i].Connection = Item) then begin
1926 FHostListResults[i].Free; 1926 FHostListResults[i].Free;
1927 FHostListResults[i] := nil; 1927 FHostListResults[i] := nil;
1928 end; 1928 end;
1929 end; 1929 end;
1930 1930
1931 // Remove filters if unwanted 1931 // Remove filters if unwanted
1932 if not prefRememberFilters then begin 1932 if not prefRememberFilters then begin
1933 OpenRegistry(Item.Parameters.SessionName); 1933 OpenRegistry(Item.Parameters.SessionName);
1934 Keys := TStringList.Create; 1934 Keys := TStringList.Create;
1935 MainReg.GetKeyNames(Keys); 1935 MainReg.GetKeyNames(Keys);
1936 rx := TRegExpr.Create; 1936 rx := TRegExpr.Create;
1937 rx.Expression := '.+'+QuoteRegExprMetaChars(DELIM)+'.+'; 1937 rx.Expression := '.+'+QuoteRegExprMetaChars(DELIM)+'.+';
1938 for i:=0 to Keys.Count-1 do begin 1938 for i:=0 to Keys.Count-1 do begin
1939 if rx.Exec(Keys[i]) then 1939 if rx.Exec(Keys[i]) then
1940 MainReg.DeleteKey(Keys[i]); 1940 MainReg.DeleteKey(Keys[i]);
1941 end; 1941 end;
1942 rx.Free; 1942 rx.Free;
1943 end; 1943 end;
1944 1944
1945 FreeAndNil(ActiveObjectEditor); 1945 FreeAndNil(ActiveObjectEditor);
1946 RefreshHelperNode(HELPERNODE_PROFILE); 1946 RefreshHelperNode(HELPERNODE_PROFILE);
1947 RefreshHelperNode(HELPERNODE_COLUMNS); 1947 RefreshHelperNode(HELPERNODE_COLUMNS);
1948 1948
1949 // Last chance to access connection related properties before disconnecting 1949 // Last chance to access connection related properties before disconnecting
1950 OpenRegistry(Item.Parameters.SessionName); 1950 OpenRegistry(Item.Parameters.SessionName);
1951 MainReg.WriteString(REGNAME_LASTUSEDDB, Item.Database); 1951 MainReg.WriteString(REGNAME_LASTUSEDDB, Item.Database);
1952 1952
1953 // Disconnect 1953 // Disconnect
1954 Item.Active := False; 1954 Item.Active := False;
1955 end; 1955 end;
1956 1956
1957 // New connection 1957 // New connection
1958 cnAdded: DBTree.InsertNode(DBTree.GetLastChild(nil), amInsertAfter); 1958 cnAdded: DBTree.InsertNode(DBTree.GetLastChild(nil), amInsertAfter);
1959 end; 1959 end;
1960 end; 1960 end;
1961 1961
1962 1962
1963 procedure TMainForm.actCreateDatabaseExecute(Sender: TObject); 1963 procedure TMainForm.actCreateDatabaseExecute(Sender: TObject);
1964 var 1964 var
1965 Dialog: TCreateDatabaseForm; 1965 Dialog: TCreateDatabaseForm;
1966 begin 1966 begin
1967 // Create database: 1967 // Create database:
1968 Dialog := TCreateDatabaseForm.Create(Self); 1968 Dialog := TCreateDatabaseForm.Create(Self);
1969 // Rely on the modalresult being set correctly 1969 // Rely on the modalresult being set correctly
1970 if Dialog.ShowModal = mrOK then 1970 if Dialog.ShowModal = mrOK then
1971 RefreshTree; 1971 RefreshTree;
1972 end; 1972 end;
1973 1973
1974 1974
1975 procedure TMainForm.actImportCSVExecute(Sender: TObject); 1975 procedure TMainForm.actImportCSVExecute(Sender: TObject);
1976 var 1976 var
1977 Dialog: Tloaddataform; 1977 Dialog: Tloaddataform;
1978 begin 1978 begin
1979 // Import Textfile 1979 // Import Textfile
1980 Dialog := Tloaddataform.Create(Self); 1980 Dialog := Tloaddataform.Create(Self);
1981 Dialog.ShowModal; 1981 Dialog.ShowModal;
1982 end; 1982 end;
1983 1983
1984 procedure TMainForm.actPreferencesExecute(Sender: TObject); 1984 procedure TMainForm.actPreferencesExecute(Sender: TObject);
1985 begin 1985 begin
1986 // Preferences 1986 // Preferences
1987 FPreferencesDialog := Toptionsform.Create(Self); 1987 FPreferencesDialog := Toptionsform.Create(Self);
1988 FPreferencesDialog.ShowModal; 1988 FPreferencesDialog.ShowModal;
1989 end; 1989 end;
1990 1990
1991 procedure TMainForm.actReadmeExecute(Sender: TObject); 1991 procedure TMainForm.actReadmeExecute(Sender: TObject);
1992 begin 1992 begin
1993 // show readme.txt 1993 // show readme.txt
1994 ShellExec( 'readme.txt', ExtractFilePath(paramstr(0)) ); 1994 ShellExec( 'readme.txt', ExtractFilePath(paramstr(0)) );
1995 end; 1995 end;
1996 1996
1997 procedure TMainForm.FormResize(Sender: TObject); 1997 procedure TMainForm.FormResize(Sender: TObject);
1998 var 1998 var
1999 i, room: Integer; 1999 i, room: Integer;
2000 PanelRect: TRect; 2000 PanelRect: TRect;
2001 begin 2001 begin
2002 // Exit early when user pressed "Cancel" on connection dialog 2002 // Exit early when user pressed "Cancel" on connection dialog
2003 if csDestroying in ComponentState then 2003 if csDestroying in ComponentState then
2004 Exit; 2004 Exit;
2005 room := 0; 2005 room := 0;
2006 for i := 1 to Statusbar.Panels.Count - 1 do 2006 for i := 1 to Statusbar.Panels.Count - 1 do
2007 inc(room, Statusbar.Panels[i].Width); 2007 inc(room, Statusbar.Panels[i].Width);
2008 StatusBar.Panels[0].Width := Statusbar.Width - room; 2008 StatusBar.Panels[0].Width := Statusbar.Width - room;
2009 // Retreive the rectancle of the statuspanel (in our case the fifth panel) 2009 // Retreive the rectancle of the statuspanel (in our case the fifth panel)
2010 SendMessage(StatusBar.Handle, SB_GETRECT, 5, Integer(@PanelRect)); 2010 SendMessage(StatusBar.Handle, SB_GETRECT, 5, Integer(@PanelRect));
2011 // Position the progressbar over the panel on the statusbar 2011 // Position the progressbar over the panel on the statusbar
2012 with PanelRect do 2012 with PanelRect do
2013 ProgressBarStatus.SetBounds(Left, Top, Right-Left, Bottom-Top); 2013 ProgressBarStatus.SetBounds(Left, Top, Right-Left, Bottom-Top);
2014 lblDataTop.Width := pnlDataTop.Width - tlbDataButtons.Width - 10; 2014 lblDataTop.Width := pnlDataTop.Width - tlbDataButtons.Width - 10;
2015 FixQueryTabCloseButtons; 2015 FixQueryTabCloseButtons;
2016 end; 2016 end;
2017 2017
2018 procedure TMainForm.actUserManagerExecute(Sender: TObject); 2018 procedure TMainForm.actUserManagerExecute(Sender: TObject);
2019 var 2019 var
2020 Dialog: TUserManagerForm; 2020 Dialog: TUserManagerForm;
2021 begin 2021 begin
2022 Dialog := TUserManagerForm.Create(Self); 2022 Dialog := TUserManagerForm.Create(Self);
2023 Dialog.ShowModal; 2023 Dialog.ShowModal;
2024 end; 2024 end;
2025 2025
2026 procedure TMainForm.actAboutBoxExecute(Sender: TObject); 2026 procedure TMainForm.actAboutBoxExecute(Sender: TObject);
2027 var 2027 var
2028 Box: TAboutBox; 2028 Box: TAboutBox;
2029 begin 2029 begin
2030 // Info-Box 2030 // Info-Box
2031 Box := TAboutBox.Create(Self); 2031 Box := TAboutBox.Create(Self);
2032 Box.ShowModal; 2032 Box.ShowModal;
2033 Box.Free; 2033 Box.Free;
2034 end; 2034 end;
2035 2035
2036 procedure TMainForm.actClearEditorExecute(Sender: TObject); 2036 procedure TMainForm.actClearEditorExecute(Sender: TObject);
2037 var 2037 var
2038 m: TSynMemo; 2038 m: TSynMemo;
2039 begin 2039 begin
2040 if Sender = actClearQueryEditor then 2040 if Sender = actClearQueryEditor then
2041 m := ActiveQueryMemo 2041 m := ActiveQueryMemo
2042 else begin 2042 else begin
2043 m := SynMemoFilter; 2043 m := SynMemoFilter;
2044 editFilterSearch.Clear; 2044 editFilterSearch.Clear;
2045 end; 2045 end;
2046 m.SelectAll; 2046 m.SelectAll;
2047 m.SelText := ''; 2047 m.SelText := '';
2048 m.SelStart := 0; 2048 m.SelStart := 0;
2049 m.SelEnd := 0; 2049 m.SelEnd := 0;
2050 if QueryTabActive then begin 2050 if QueryTabActive then begin
2051 ActiveQueryTab.MemoFilename := ''; 2051 ActiveQueryTab.MemoFilename := '';
2052 ActiveQueryTab.Memo.Modified := False; 2052 ActiveQueryTab.Memo.Modified := False;
2053 end; 2053 end;
2054 if m = SynMemoFilter then 2054 if m = SynMemoFilter then
2055 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False); 2055 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False);
2056 end; 2056 end;
2057 2057
2058 procedure TMainForm.actTableToolsExecute(Sender: TObject); 2058 procedure TMainForm.actTableToolsExecute(Sender: TObject);
2059 var 2059 var
2060 Act: TAction; 2060 Act: TAction;
2061 InDBTree: Boolean; 2061 InDBTree: Boolean;
2062 Node: PVirtualNode; 2062 Node: PVirtualNode;
2063 DBObj: PDBObject; 2063 DBObj: PDBObject;
2064 Dialog: TfrmTableTools; 2064 Dialog: TfrmTableTools;
2065 begin 2065 begin
2066 // Show table tools dialog 2066 // Show table tools dialog
2067 Dialog := TfrmTableTools.Create(Self); 2067 Dialog := TfrmTableTools.Create(Self);
2068 Act := Sender as TAction; 2068 Act := Sender as TAction;
2069 Dialog.PreSelectObjects.Clear; 2069 Dialog.PreSelectObjects.Clear;
2070 InDBTree := (Act.ActionComponent is TMenuItem) 2070 InDBTree := (Act.ActionComponent is TMenuItem)
2071 and (TPopupMenu((Act.ActionComponent as TMenuItem).GetParentMenu).PopupComponent = DBTree); 2071 and (TPopupMenu((Act.ActionComponent as TMenuItem).GetParentMenu).PopupComponent = DBTree);
2072 if InDBTree then 2072 if InDBTree then
2073 Dialog.PreSelectObjects.Add(ActiveDbObj) 2073 Dialog.PreSelectObjects.Add(ActiveDbObj)
2074 else begin 2074 else begin
2075 Node := GetNextNode(ListTables, nil, True); 2075 Node := GetNextNode(ListTables, nil, True);
2076 while Assigned(Node) do begin 2076 while Assigned(Node) do begin
2077 DBObj := ListTables.GetNodeData(Node); 2077 DBObj := ListTables.GetNodeData(Node);
2078 Dialog.PreSelectObjects.Add(DBObj^); 2078 Dialog.PreSelectObjects.Add(DBObj^);
2079 Node := GetNextNode(ListTables, Node, True); 2079 Node := GetNextNode(ListTables, Node, True);
2080 end; 2080 end;
2081 end; 2081 end;
2082 if Sender = actMaintenance then 2082 if Sender = actMaintenance then
2083 Dialog.ToolMode := tmMaintenance 2083 Dialog.ToolMode := tmMaintenance
2084 else if Sender = actFindTextOnServer then 2084 else if Sender = actFindTextOnServer then
2085 Dialog.ToolMode := tmFind 2085 Dialog.ToolMode := tmFind
2086 else if Sender = actExportTables then 2086 else if Sender = actExportTables then
2087 Dialog.ToolMode := tmSQLExport 2087 Dialog.ToolMode := tmSQLExport
2088 else if Sender = actBulkTableEdit then 2088 else if Sender = actBulkTableEdit then
2089 Dialog.ToolMode := tmBulkTableEdit; 2089 Dialog.ToolMode := tmBulkTableEdit;
2090 Dialog.ShowModal; 2090 Dialog.ShowModal;
2091 end; 2091 end;
2092 2092
2093 2093
2094 {** 2094 {**
2095 Edit view 2095 Edit view
2096 } 2096 }
2097 procedure TMainForm.actPrintListExecute(Sender: TObject); 2097 procedure TMainForm.actPrintListExecute(Sender: TObject);
2098 var 2098 var
2099 f: TForm; 2099 f: TForm;
2100 begin 2100 begin
2101 // Print contents of a list or grid 2101 // Print contents of a list or grid
2102 f := TPrintlistForm.Create(Self); 2102 f := TPrintlistForm.Create(Self);
2103 f.ShowModal; 2103 f.ShowModal;
2104 FreeAndNil(f); 2104 FreeAndNil(f);
2105 end; 2105 end;
2106 2106
2107 2107
2108 procedure TMainForm.actCopyTableExecute(Sender: TObject); 2108 procedure TMainForm.actCopyTableExecute(Sender: TObject);
2109 var 2109 var
2110 Dialog: TCopyTableForm; 2110 Dialog: TCopyTableForm;
2111 begin 2111 begin
2112 // copy table 2112 // copy table
2113 Dialog := TCopyTableForm.Create(Self); 2113 Dialog := TCopyTableForm.Create(Self);
2114 Dialog.ShowModal; 2114 Dialog.ShowModal;
2115 end; 2115 end;
2116 2116
2117 2117
2118 procedure TMainForm.menuConnectionsPopup(Sender: TObject); 2118 procedure TMainForm.menuConnectionsPopup(Sender: TObject);
2119 var 2119 var
2120 i: integer; 2120 i: integer;
2121 item: TMenuItem; 2121 item: TMenuItem;
2122 SessionNames: TStringList; 2122 SessionNames: TStringList;
2123 Connection: TDBConnection; 2123 Connection: TDBConnection;
2124 begin 2124 begin
2125 // Delete dynamically added connection menu items. 2125 // Delete dynamically added connection menu items.
2126 menuConnections.Items.Clear; 2126 menuConnections.Items.Clear;
2127 2127
2128 // "Session manager" and "New window" items 2128 // "Session manager" and "New window" items
2129 item := TMenuItem.Create(menuConnections); 2129 item := TMenuItem.Create(menuConnections);
2130 item.Action := actSessionManager; 2130 item.Action := actSessionManager;
2131 item.Default := True; 2131 item.Default := True;
2132 menuConnections.Items.Add(item); 2132 menuConnections.Items.Add(item);
2133 item := TMenuItem.Create(menuConnections); 2133 item := TMenuItem.Create(menuConnections);
2134 item.Action := actNewWindow; 2134 item.Action := actNewWindow;
2135 menuConnections.Items.Add(item); 2135 menuConnections.Items.Add(item);
2136 item := TMenuItem.Create(menuConnections); 2136 item := TMenuItem.Create(menuConnections);
2137 item.Caption := '-'; 2137 item.Caption := '-';
2138 menuConnections.Items.Add(item); 2138 menuConnections.Items.Add(item);
2139 2139
2140 // All sessions 2140 // All sessions
2141 if MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, False) then begin 2141 if MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, False) then begin
2142 SessionNames := TStringList.Create; 2142 SessionNames := TStringList.Create;
2143 MainReg.GetKeyNames(SessionNames); 2143 MainReg.GetKeyNames(SessionNames);
2144 for i:=0 to SessionNames.Count-1 do begin 2144 for i:=0 to SessionNames.Count-1 do begin
2145 item := TMenuItem.Create(menuConnections); 2145 item := TMenuItem.Create(menuConnections);
2146 item.Caption := SessionNames[i]; 2146 item.Caption := SessionNames[i];
2147 item.OnClick := SessionConnect; 2147 item.OnClick := SessionConnect;
2148 item.ImageIndex := 37; 2148 item.ImageIndex := 37;
2149 for Connection in Connections do begin 2149 for Connection in Connections do begin
2150 if SessionNames[i] = Connection.Parameters.SessionName then begin 2150 if SessionNames[i] = Connection.Parameters.SessionName then begin
2151 item.Checked := True; 2151 item.Checked := True;
2152 item.ImageIndex := -1; 2152 item.ImageIndex := -1;
2153 break; 2153 break;
2154 end; 2154 end;
2155 end; 2155 end;
2156 menuConnections.Items.Add(item); 2156 menuConnections.Items.Add(item);
2157 end; 2157 end;
2158 end; 2158 end;
2159 2159
2160 end; 2160 end;
2161 2161
2162 2162
2163 procedure TMainForm.File1Click(Sender: TObject); 2163 procedure TMainForm.File1Click(Sender: TObject);
2164 var 2164 var
2165 Item: TMenuItem; 2165 Item: TMenuItem;
2166 i: Integer; 2166 i: Integer;
2167 SessionNames, ConnectedSessions: TStringList; 2167 SessionNames, ConnectedSessions: TStringList;
2168 begin 2168 begin
2169 // Decide if "Connect to" menu should be enabled 2169 // Decide if "Connect to" menu should be enabled
2170 menuConnectTo.Enabled := False; 2170 menuConnectTo.Enabled := False;
2171 if MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, False) then begin 2171 if MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, False) then begin
2172 menuConnectTo.Enabled := MainReg.HasSubKeys; 2172 menuConnectTo.Enabled := MainReg.HasSubKeys;
2173 if menuConnectTo.Enabled then begin 2173 if menuConnectTo.Enabled then begin
2174 // Add all sessions to submenu 2174 // Add all sessions to submenu
2175 for i := menuConnectTo.Count - 1 downto 0 do 2175 for i := menuConnectTo.Count - 1 downto 0 do
2176 menuConnectTo.Delete(i); 2176 menuConnectTo.Delete(i);
2177 ConnectedSessions := TStringList.Create; 2177 ConnectedSessions := TStringList.Create;
2178 for i:=0 to Connections.Count-1 do 2178 for i:=0 to Connections.Count-1 do
2179 ConnectedSessions.Add(Connections[i].Parameters.SessionName); 2179 ConnectedSessions.Add(Connections[i].Parameters.SessionName);
2180 SessionNames := TStringList.Create; 2180 SessionNames := TStringList.Create;
2181 MainReg.GetKeyNames(SessionNames); 2181 MainReg.GetKeyNames(SessionNames);
2182 for i:=0 to SessionNames.Count-1 do begin 2182 for i:=0 to SessionNames.Count-1 do begin
2183 Item := TMenuItem.Create(menuConnectTo); 2183 Item := TMenuItem.Create(menuConnectTo);
2184 Item.Caption := SessionNames[i]; 2184 Item.Caption := SessionNames[i];
2185 Item.OnClick := SessionConnect; 2185 Item.OnClick := SessionConnect;
2186 Item.ImageIndex := 37; 2186 Item.ImageIndex := 37;
2187 if ConnectedSessions.IndexOf(SessionNames[i]) > -1 then begin 2187 if ConnectedSessions.IndexOf(SessionNames[i]) > -1 then begin
2188 Item.Checked := True; 2188 Item.Checked := True;
2189 Item.ImageIndex := -1; 2189 Item.ImageIndex := -1;
2190 end; 2190 end;
2191 menuConnectTo.Add(Item); 2191 menuConnectTo.Add(Item);
2192 end; 2192 end;
2193 end; 2193 end;
2194 end; 2194 end;
2195 end; 2195 end;
2196 2196
2197 2197
2198 procedure TMainForm.actWebbrowse(Sender: TObject); 2198 procedure TMainForm.actWebbrowse(Sender: TObject);
2199 begin 2199 begin
2200 // Browse to URL (hint) 2200 // Browse to URL (hint)
2201 ShellExec( TAction(Sender).Hint ); 2201 ShellExec( TAction(Sender).Hint );
2202 end; 2202 end;
2203 2203
2204 2204
2205 procedure TMainForm.actExportSettingsExecute(Sender: TObject); 2205 procedure TMainForm.actExportSettingsExecute(Sender: TObject);
2206 begin 2206 begin
2207 // Export settings to .reg-file 2207 // Export settings to .reg-file
2208 if SaveDialog2.Execute then 2208 if SaveDialog2.Execute then
2209 ShellExec('regedit.exe', '', '/e "'+SaveDialog2.FileName+'" HKEY_CURRENT_USER'+REGPATH); 2209 ShellExec('regedit.exe', '', '/e "'+SaveDialog2.FileName+'" HKEY_CURRENT_USER'+REGPATH);
2210 end; 2210 end;
2211 2211
2212 procedure TMainForm.actImportSettingsExecute(Sender: TObject); 2212 procedure TMainForm.actImportSettingsExecute(Sender: TObject);
2213 begin 2213 begin
2214 // Import settings from .reg-file 2214 // Import settings from .reg-file
2215 if OpenDialog2.Execute then 2215 if OpenDialog2.Execute then
2216 ShellExec('regedit.exe', '', '"'+OpenDialog2.FileName+'"'); 2216 ShellExec('regedit.exe', '', '"'+OpenDialog2.FileName+'"');
2217 end; 2217 end;
2218 2218
2219 procedure TMainForm.actExecuteQueryExecute(Sender: TObject); 2219 procedure TMainForm.actExecuteQueryExecute(Sender: TObject);
2220 var 2220 var
2221 Query: TSQLSentence; 2221 Query: TSQLSentence;
2222 ProfileNode: PVirtualNode; 2222 ProfileNode: PVirtualNode;
2223 BatchAll, Batch: TSQLBatch; 2223 BatchAll, Batch: TSQLBatch;
2224 Tab: TQueryTab; 2224 Tab: TQueryTab;
2225 2225
2226 begin 2226 begin
2227 Screen.Cursor := crHourGlass; 2227 Screen.Cursor := crHourGlass;
2228 Tab := ActiveQueryTab; 2228 Tab := ActiveQueryTab;
2229 OperationRunning(True); 2229 OperationRunning(True);
2230 2230
2231 ShowStatusMsg('Splitting SQL queries ...'); 2231 ShowStatusMsg('Splitting SQL queries ...');
2232 Batch := TSQLBatch.Create; 2232 Batch := TSQLBatch.Create;
2233 if Sender = actExecuteCurrentQuery then begin 2233 if Sender = actExecuteCurrentQuery then begin
2234 BatchAll := TSQLBatch.Create; 2234 BatchAll := TSQLBatch.Create;
2235 BatchAll.SQL := Tab.Memo.Text; 2235 BatchAll.SQL := Tab.Memo.Text;
2236 for Query in BatchAll do begin 2236 for Query in BatchAll do begin
2237 if (Tab.Memo.SelStart >= Query.LeftOffset-1) and (Tab.Memo.SelStart < Query.RightOffset) then begin 2237 if (Tab.Memo.SelStart >= Query.LeftOffset-1) and (Tab.Memo.SelStart < Query.RightOffset) then begin
2238 Batch.SQL := Query.SQL; 2238 Batch.SQL := Query.SQL;
2239 Tab.LeftOffsetInMemo := Query.LeftOffset; 2239 Tab.LeftOffsetInMemo := Query.LeftOffset;
2240 break; 2240 break;
2241 end; 2241 end;
2242 end; 2242 end;
2243 BatchAll.Free; 2243 BatchAll.Free;
2244 end else if Sender = actExecuteSelection then begin 2244 end else if Sender = actExecuteSelection then begin
2245 Batch.SQL := Tab.Memo.SelText; 2245 Batch.SQL := Tab.Memo.SelText;
2246 Tab.LeftOffsetInMemo := Tab.Memo.SelStart; 2246 Tab.LeftOffsetInMemo := Tab.Memo.SelStart;
2247 end else begin 2247 end else begin
2248 Batch.SQL := Tab.Memo.Text; 2248 Batch.SQL := Tab.Memo.Text;
2249 Tab.LeftOffsetInMemo := 0; 2249 Tab.LeftOffsetInMemo := 0;
2250 end; 2250 end;
2251 2251
2252 EnableProgress(Batch.Count); 2252 EnableProgress(Batch.Count);
2253 Tab.ResultTabs.Clear; 2253 Tab.ResultTabs.Clear;
2254 Tab.tabsetQuery.Tabs.Clear; 2254 Tab.tabsetQuery.Tabs.Clear;
2255 FreeAndNil(Tab.QueryProfile); 2255 FreeAndNil(Tab.QueryProfile);
2256 ProfileNode := FindNode(Tab.treeHelpers, HELPERNODE_PROFILE, nil); 2256 ProfileNode := FindNode(Tab.treeHelpers, HELPERNODE_PROFILE, nil);
2257 Tab.DoProfile := Assigned(ProfileNode) and (Tab.treeHelpers.CheckState[ProfileNode] in CheckedStates); 2257 Tab.DoProfile := Assigned(ProfileNode) and (Tab.treeHelpers.CheckState[ProfileNode] in CheckedStates);
2258 if Tab.DoProfile then try 2258 if Tab.DoProfile then try
2259 ActiveConnection.Query('SET profiling=1'); 2259 ActiveConnection.Query('SET profiling=1');
2260 except 2260 except
2261 on E:EDatabaseError do begin 2261 on E:EDatabaseError do begin
2262 ErrorDialog('Query profiling requires MySQL 5.0.37 or later, and the server must not be configured with --disable-profiling.', E.Message); 2262 ErrorDialog('Query profiling requires MySQL 5.0.37 or later, and the server must not be configured with --disable-profiling.', E.Message);
2263 Tab.DoProfile := False; 2263 Tab.DoProfile := False;
2264 end; 2264 end;
2265 end; 2265 end;
2266 2266
2267 // Start the execution thread 2267 // Start the execution thread
2268 Screen.Cursor := crAppStart; 2268 Screen.Cursor := crAppStart;
2269 Tab.QueryRunning := True; 2269 Tab.QueryRunning := True;
2270 Tab.ExecutionThread := TQueryThread.Create(ActiveConnection, Batch, Tab.Number); 2270 Tab.ExecutionThread := TQueryThread.Create(ActiveConnection, Batch, Tab.Number);
2271 ValidateQueryControls(Sender); 2271 ValidateQueryControls(Sender);
2272 end; 2272 end;
2273 2273
2274 2274
2275 2275
2276 procedure TMainForm.BeforeQueryExecution(Thread: TQueryThread); 2276 procedure TMainForm.BeforeQueryExecution(Thread: TQueryThread);
2277 var 2277 var
2278 Text: String; 2278 Text: String;
2279 begin 2279 begin
2280 // Update GUI stuff 2280 // Update GUI stuff
2281 Text := 'query #' + FormatNumber(Thread.BatchPosition+1); 2281 Text := 'query #' + FormatNumber(Thread.BatchPosition+1);
2282 if Thread.QueriesInPacket > 1 then 2282 if Thread.QueriesInPacket > 1 then
2283 Text := 'queries #' + FormatNumber(Thread.BatchPosition+1) + ' to #' + FormatNumber(Thread.BatchPosition+Thread.QueriesInPacket); 2283 Text := 'queries #' + FormatNumber(Thread.BatchPosition+1) + ' to #' + FormatNumber(Thread.BatchPosition+Thread.QueriesInPacket);
2284 ShowStatusMsg('Executing '+Text+' of '+FormatNumber(Thread.Batch.Count)+' ...'); 2284 ShowStatusMsg('Executing '+Text+' of '+FormatNumber(Thread.Batch.Count)+' ...');
2285 SetProgressPosition(Thread.BatchPosition); 2285 SetProgressPosition(Thread.BatchPosition);
2286 end; 2286 end;
2287 2287
2288 2288
2289 procedure TMainForm.AfterQueryExecution(Thread: TQueryThread); 2289 procedure TMainForm.AfterQueryExecution(Thread: TQueryThread);
2290 var 2290 var
2291 Tab: TQueryTab; 2291 Tab: TQueryTab;
2292 NewTab: TResultTab; 2292 NewTab: TResultTab;
2293 col: TVirtualTreeColumn; 2293 col: TVirtualTreeColumn;
2294 TabCaption: String; 2294 TabCaption: String;
2295 Results: TDBQuery; 2295 Results: TDBQuery;
2296 i: Integer; 2296 i: Integer;
2297 begin 2297 begin
2298 // Single query or query packet has finished 2298 // Single query or query packet has finished
2299 2299
2300 ShowStatusMsg('Setting up result grid(s) ...'); 2300 ShowStatusMsg('Setting up result grid(s) ...');
2301 Tab := GetQueryTabByNumber(Thread.TabNumber); 2301 Tab := GetQueryTabByNumber(Thread.TabNumber);
2302 2302
2303 // Create result tabs 2303 // Create result tabs
2304 for Results in Thread.Connection.GetLastResults do begin 2304 for Results in Thread.Connection.GetLastResults do begin
2305 NewTab := TResultTab.Create(Tab); 2305 NewTab := TResultTab.Create(Tab);
2306 Tab.ResultTabs.Add(NewTab); 2306 Tab.ResultTabs.Add(NewTab);
2307 NewTab.Results := Results; 2307 NewTab.Results := Results;
2308 try 2308 try
2309 TabCaption := NewTab.Results.TableName; 2309 TabCaption := NewTab.Results.TableName;
2310 except on E:EDatabaseError do 2310 except on E:EDatabaseError do
2311 TabCaption := 'Result #'+IntToStr(Tab.ResultTabs.Count); 2311 TabCaption := 'Result #'+IntToStr(Tab.ResultTabs.Count);
2312 end; 2312 end;
2313 Tab.tabsetQuery.Tabs.Add(TabCaption); 2313 Tab.tabsetQuery.Tabs.Add(TabCaption);
2314 2314
2315 NewTab.Grid.BeginUpdate; 2315 NewTab.Grid.BeginUpdate;
2316 NewTab.Grid.Header.Options := NewTab.Grid.Header.Options + [hoVisible]; 2316 NewTab.Grid.Header.Options := NewTab.Grid.Header.Options + [hoVisible];
2317 NewTab.Grid.Header.Columns.BeginUpdate; 2317 NewTab.Grid.Header.Columns.BeginUpdate;
2318 NewTab.Grid.Header.Columns.Clear; 2318 NewTab.Grid.Header.Columns.Clear;
2319 for i:=0 to NewTab.Results.ColumnCount-1 do begin 2319 for i:=0 to NewTab.Results.ColumnCount-1 do begin
2320 col := NewTab.Grid.Header.Columns.Add; 2320 col := NewTab.Grid.Header.Columns.Add;
2321 col.Text := NewTab.Results.ColumnNames[i]; 2321 col.Text := NewTab.Results.ColumnNames[i];
2322 if NewTab.Results.DataType(i).Category in [dtcInteger, dtcReal] then 2322 if NewTab.Results.DataType(i).Category in [dtcInteger, dtcReal] then
2323 col.Alignment := taRightJustify; 2323 col.Alignment := taRightJustify;
2324 if NewTab.Results.ColIsPrimaryKeyPart(i) then 2324 if NewTab.Results.ColIsPrimaryKeyPart(i) then
2325 col.ImageIndex := ICONINDEX_PRIMARYKEY 2325 col.ImageIndex := ICONINDEX_PRIMARYKEY
2326 else if NewTab.Results.ColIsUniqueKeyPart(i) then 2326 else if NewTab.Results.ColIsUniqueKeyPart(i) then
2327 col.ImageIndex := ICONINDEX_UNIQUEKEY 2327 col.ImageIndex := ICONINDEX_UNIQUEKEY
2328 else if NewTab.Results.ColIsKeyPart(i) then 2328 else if NewTab.Results.ColIsKeyPart(i) then
2329 col.ImageIndex := ICONINDEX_INDEXKEY; 2329 col.ImageIndex := ICONINDEX_INDEXKEY;
2330 end; 2330 end;
2331 NewTab.Grid.Header.Columns.EndUpdate; 2331 NewTab.Grid.Header.Columns.EndUpdate;
2332 NewTab.Grid.RootNodeCount := NewTab.Results.RecordCount; 2332 NewTab.Grid.RootNodeCount := NewTab.Results.RecordCount;
2333 NewTab.Grid.EndUpdate; 2333 NewTab.Grid.EndUpdate;
2334 for i:=0 to NewTab.Grid.Header.Columns.Count-1 do 2334 for i:=0 to NewTab.Grid.Header.Columns.Count-1 do
2335 AutoCalcColWidth(NewTab.Grid, i); 2335 AutoCalcColWidth(NewTab.Grid, i);
2336 if Tab.tabsetQuery.TabIndex = -1 then 2336 if Tab.tabsetQuery.TabIndex = -1 then
2337 Tab.tabsetQuery.TabIndex := 0; 2337 Tab.tabsetQuery.TabIndex := 0;
2338 end; 2338 end;
2339 ShowStatusMsg; 2339 ShowStatusMsg;
2340 end; 2340 end;
2341 2341
2342 2342
2343 procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread); 2343 procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
2344 var 2344 var
2345 Tab, WarningsTab: TQueryTab; 2345 Tab, WarningsTab: TQueryTab;
2346 MetaInfo, ErroneousSQL, RegName, RegItem, MsgTitle, MsgText: String; 2346 MetaInfo, ErroneousSQL, RegName, RegItem, MsgTitle, MsgText: String;
2347 ProfileAllTime: Extended; 2347 ProfileAllTime: Extended;
2348 ProfileNode: PVirtualNode; 2348 ProfileNode: PVirtualNode;
2349 AllRegItems: TStringList; 2349 AllRegItems: TStringList;
2350 History: TQueryHistory; 2350 History: TQueryHistory;
2351 HistoryItem: TQueryHistoryItem; 2351 HistoryItem: TQueryHistoryItem;
2352 Warnings: TDBQuery; 2352 Warnings: TDBQuery;
2353 HistoryNum, MaxWarnings, RegItemsSize: Integer; 2353 HistoryNum, MaxWarnings, RegItemsSize: Integer;
2354 DoDelete: Boolean; 2354 DoDelete: Boolean;
2355 MinDate: TDateTime; 2355 MinDate: TDateTime;
2356 2356
2357 procedure GoToErrorPos(Err: String); 2357 procedure GoToErrorPos(Err: String);
2358 var 2358 var
2359 rx: TRegExpr; 2359 rx: TRegExpr;
2360 SelStart, ErrorPos: Integer; 2360 SelStart, ErrorPos: Integer;
2361 begin 2361 begin
2362 // Try to set memo cursor to the relevant position 2362 // Try to set memo cursor to the relevant position
2363 if Tab.LeftOffsetInMemo > 0 then 2363 if Tab.LeftOffsetInMemo > 0 then
2364 SelStart := Tab.LeftOffsetInMemo-1 2364 SelStart := Tab.LeftOffsetInMemo-1
2365 else 2365 else
2366 SelStart := Thread.Batch[Thread.BatchPosition].LeftOffset-1; 2366 SelStart := Thread.Batch[Thread.BatchPosition].LeftOffset-1;
2367 2367
2368 // Extract erroneous portion of SQL out of error message 2368 // Extract erroneous portion of SQL out of error message
2369 ErroneousSQL := ''; 2369 ErroneousSQL := '';
2370 rx := TRegExpr.Create; 2370 rx := TRegExpr.Create;
2371 rx.Expression := 'for the right syntax to use near ''(.+)'' at line (\d+)'; 2371 rx.Expression := 'for the right syntax to use near ''(.+)'' at line (\d+)';
2372 if rx.Exec(Err) then 2372 if rx.Exec(Err) then
2373 ErroneousSQL := rx.Match[1]; 2373 ErroneousSQL := rx.Match[1];
2374 rx.Expression := 'Duplicate entry ''([^'']+)'''; 2374 rx.Expression := 'Duplicate entry ''([^'']+)''';
2375 if rx.Exec(Err) then 2375 if rx.Exec(Err) then
2376 ErroneousSQL := rx.Match[1]; 2376 ErroneousSQL := rx.Match[1];
2377 rx.Free; 2377 rx.Free;
2378 2378
2379 if ErroneousSQL <> '' then begin 2379 if ErroneousSQL <> '' then begin
2380 // Examine 1kb of memo text at given offset 2380 // Examine 1kb of memo text at given offset
2381 ErrorPos := Pos(ErroneousSQL, Copy(Tab.Memo.Text, SelStart, SIZE_KB)); 2381 ErrorPos := Pos(ErroneousSQL, Copy(Tab.Memo.Text, SelStart, SIZE_KB));
2382 if ErrorPos > 0 then 2382 if ErrorPos > 0 then
2383 Inc(SelStart, ErrorPos-1); 2383 Inc(SelStart, ErrorPos-1);
2384 Tab.Memo.SelLength := 0; 2384 Tab.Memo.SelLength := 0;
2385 Tab.Memo.SelStart := SelStart; 2385 Tab.Memo.SelStart := SelStart;
2386 end; 2386 end;
2387 end; 2387 end;
2388 2388
2389 begin 2389 begin
2390 // Find right query tab 2390 // Find right query tab
2391 Tab := GetQueryTabByNumber(Thread.TabNumber); 2391 Tab := GetQueryTabByNumber(Thread.TabNumber);
2392 2392
2393 // Error handling 2393 // Error handling
2394 if IsNotEmpty(Thread.ErrorMessage) then begin 2394 if IsNotEmpty(Thread.ErrorMessage) then begin
2395 SetProgressState(pbsError); 2395 SetProgressState(pbsError);
2396 GoToErrorPos(Thread.ErrorMessage); 2396 GoToErrorPos(Thread.ErrorMessage);
2397 ErrorDialog(Thread.ErrorMessage); 2397 ErrorDialog(Thread.ErrorMessage);
2398 end; 2398 end;
2399 2399
2400 // Gather meta info for logging 2400 // Gather meta info for logging
2401 MetaInfo := 'Affected rows: '+FormatNumber(Thread.RowsAffected)+ 2401 MetaInfo := 'Affected rows: '+FormatNumber(Thread.RowsAffected)+
2402 ' Found rows: '+FormatNumber(Thread.RowsFound)+ 2402 ' Found rows: '+FormatNumber(Thread.RowsFound)+
2403 ' Warnings: '+FormatNumber(Thread.WarningCount)+ 2403 ' Warnings: '+FormatNumber(Thread.WarningCount)+
2404 ' Duration for ' + FormatNumber(Thread.BatchPosition); 2404 ' Duration for ' + FormatNumber(Thread.BatchPosition);
2405 if Thread.BatchPosition < Thread.Batch.Count then 2405 if Thread.BatchPosition < Thread.Batch.Count then
2406 MetaInfo := MetaInfo + ' of ' + FormatNumber(Thread.Batch.Count); 2406 MetaInfo := MetaInfo + ' of ' + FormatNumber(Thread.Batch.Count);
2407 if Thread.Batch.Count = 1 then 2407 if Thread.Batch.Count = 1 then
2408 MetaInfo := MetaInfo + ' query' 2408 MetaInfo := MetaInfo + ' query'
2409 else 2409 else
2410 MetaInfo := MetaInfo + ' queries'; 2410 MetaInfo := MetaInfo + ' queries';
2411 MetaInfo := MetaInfo + ': '+FormatNumber(Thread.QueryTime/1000, 3) +' sec.'; 2411 MetaInfo := MetaInfo + ': '+FormatNumber(Thread.QueryTime/1000, 3) +' sec.';
2412 if Thread.QueryNetTime > 0 then 2412 if Thread.QueryNetTime > 0 then
2413 MetaInfo := MetaInfo + ' (+ '+FormatNumber(Thread.QueryNetTime/1000, 3) +' sec. network)'; 2413 MetaInfo := MetaInfo + ' (+ '+FormatNumber(Thread.QueryNetTime/1000, 3) +' sec. network)';
2414 LogSQL(MetaInfo); 2414 LogSQL(MetaInfo);
2415 2415
2416 // Display query profile 2416 // Display query profile
2417 if Tab.DoProfile then begin 2417 if Tab.DoProfile then begin
2418 Tab.QueryProfile := Thread.Connection.GetResults('SHOW PROFILE'); 2418 Tab.QueryProfile := Thread.Connection.GetResults('SHOW PROFILE');
2419 Tab.ProfileTime := 0; 2419 Tab.ProfileTime := 0;
2420 Tab.MaxProfileTime := 0; 2420 Tab.MaxProfileTime := 0;
2421 while not Tab.QueryProfile.Eof do begin 2421 while not Tab.QueryProfile.Eof do begin
2422 ProfileAllTime := MakeFloat(Tab.QueryProfile.Col(1)); 2422 ProfileAllTime := MakeFloat(Tab.QueryProfile.Col(1));
2423 Tab.ProfileTime := Tab.ProfileTime + ProfileAllTime; 2423 Tab.ProfileTime := Tab.ProfileTime + ProfileAllTime;
2424 Tab.MaxProfileTime := Max(Time, Tab.MaxProfileTime); 2424 Tab.MaxProfileTime := Max(Time, Tab.MaxProfileTime);
2425 Tab.QueryProfile.Next; 2425 Tab.QueryProfile.Next;
2426 end; 2426 end;
2427 ProfileNode := FindNode(Tab.treeHelpers, HELPERNODE_PROFILE, nil); 2427 ProfileNode := FindNode(Tab.treeHelpers, HELPERNODE_PROFILE, nil);
2428 Tab.treeHelpers.ReinitNode(ProfileNode, True); 2428 Tab.treeHelpers.ReinitNode(ProfileNode, True);
2429 Tab.treeHelpers.InvalidateChildren(ProfileNode, True); 2429 Tab.treeHelpers.InvalidateChildren(ProfileNode, True);
2430 Thread.Connection.Query('SET profiling=0'); 2430 Thread.Connection.Query('SET profiling=0');
2431 end; 2431 end;
2432 2432
2433 // Show warnings 2433 // Show warnings
2434 if Thread.WarningCount > 0 then begin 2434 if Thread.WarningCount > 0 then begin
2435 MsgTitle := 'Your query produced '+FormatNumber(Thread.WarningCount)+' warnings.'; 2435 MsgTitle := 'Your query produced '+FormatNumber(Thread.WarningCount)+' warnings.';
2436 MsgText := ''; 2436 MsgText := '';
2437 Warnings := Thread.Connection.GetResults('SHOW WARNINGS LIMIT 5'); 2437 Warnings := Thread.Connection.GetResults('SHOW WARNINGS LIMIT 5');
2438 if Warnings.RecordCount < Thread.WarningCount then 2438 if Warnings.RecordCount < Thread.WarningCount then
2439 MsgText := MsgText + 'First '+FormatNumber(Warnings.RecordCount)+' warnings:'+CRLF; 2439 MsgText := MsgText + 'First '+FormatNumber(Warnings.RecordCount)+' warnings:'+CRLF;
2440 while not Warnings.Eof do begin 2440 while not Warnings.Eof do begin
2441 MsgText := MsgText + Warnings.Col('Level') + ': ' + Warnings.Col('Message') + CRLF; 2441 MsgText := MsgText + Warnings.Col('Level') + ': ' + Warnings.Col('Message') + CRLF;
2442 Warnings.Next; 2442 Warnings.Next;
2443 end; 2443 end;
2444 MsgText := Trim(MsgText); 2444 MsgText := Trim(MsgText);
2445 if Warnings.RecordCount = Thread.WarningCount then 2445 if Warnings.RecordCount = Thread.WarningCount then
2446 MessageDialog(MsgTitle, MsgText, mtWarning, [mbOk]) 2446 MessageDialog(MsgTitle, MsgText, mtWarning, [mbOk])
2447 else begin 2447 else begin
2448 MsgText := MsgText + CRLF+CRLF + 'Show all warnings in a new query tab?'; 2448 MsgText := MsgText + CRLF+CRLF + 'Show all warnings in a new query tab?';
2449 MaxWarnings := MakeInt(Thread.Connection.GetVar('SELECT @@max_error_count')); 2449 MaxWarnings := MakeInt(Thread.Connection.GetVar('SELECT @@max_error_count'));
2450 if MaxWarnings < Thread.WarningCount then 2450 if MaxWarnings < Thread.WarningCount then
2451 MsgText := MsgText + CRLF+CRLF+ 'The server variable @@max_error_count is currently set to '+IntToStr(MaxWarnings)+', so you won''t see all warnings.'; 2451 MsgText := MsgText + CRLF+CRLF+ 'The server variable @@max_error_count is currently set to '+IntToStr(MaxWarnings)+', so you won''t see all warnings.';
2452 if MessageDialog(MsgTitle, MsgText, mtWarning, [mbYes, mbNo]) = mrYes then begin 2452 if MessageDialog(MsgTitle, MsgText, mtWarning, [mbYes, mbNo]) = mrYes then begin
2453 actNewQueryTab.Execute; 2453 actNewQueryTab.Execute;
2454 WarningsTab := QueryTabs[QueryTabs.Count-1]; 2454 WarningsTab := QueryTabs[QueryTabs.Count-1];
2455 WarningsTab.Memo.Text := 'SHOW WARNINGS'; 2455 WarningsTab.Memo.Text := 'SHOW WARNINGS';
2456 actExecuteQueryExecute(WarningsTab); 2456 actExecuteQueryExecute(WarningsTab);
2457 end; 2457 end;
2458 end; 2458 end;
2459 end; 2459 end;
2460 2460
2461 2461
2462 // Store successful query packet in history if it's not a batch. 2462 // Store successful query packet in history if it's not a batch.
2463 // Assume that a bunch of up to 5 queries is not a batch. 2463 // Assume that a bunch of up to 5 queries is not a batch.
2464 if IsEmpty(Thread.ErrorMessage) and (Thread.Batch.Count <= 5) and (Thread.Batch.Size <= SIZE_MB) then begin 2464 if IsEmpty(Thread.ErrorMessage) and (Thread.Batch.Count <= 5) and (Thread.Batch.Size <= SIZE_MB) then begin
2465 ShowStatusMsg('Updating query history ...'); 2465 ShowStatusMsg('Updating query history ...');
2466 OpenRegistry(Thread.Connection.Parameters.SessionName); 2466 OpenRegistry(Thread.Connection.Parameters.SessionName);
2467 MainReg.OpenKey(REGKEY_QUERYHISTORY, true); 2467 MainReg.OpenKey(REGKEY_QUERYHISTORY, true);
2468 2468
2469 // Load all items so we can clean up 2469 // Load all items so we can clean up
2470 AllRegItems := TStringList.Create; 2470 AllRegItems := TStringList.Create;
2471 MainReg.GetValueNames(AllRegItems); 2471 MainReg.GetValueNames(AllRegItems);
2472 History := TQueryHistory.Create; 2472 History := TQueryHistory.Create;
2473 for RegItem in AllRegItems do begin 2473 for RegItem in AllRegItems do begin
2474 History.ReadItem(RegItem); 2474 History.ReadItem(RegItem);
2475 end; 2475 end;
2476 2476
2477 // Find lowest unused item number 2477 // Find lowest unused item number
2478 HistoryNum := 0; 2478 HistoryNum := 0;
2479 while True do begin 2479 while True do begin
2480 Inc(HistoryNum); 2480 Inc(HistoryNum);
2481 RegName := IntToStr(HistoryNum); 2481 RegName := IntToStr(HistoryNum);
2482 if AllRegItems.IndexOf(RegName) = -1 then 2482 if AllRegItems.IndexOf(RegName) = -1 then
2483 break; 2483 break;
2484 end; 2484 end;
2485 2485
2486 // Sort by date 2486 // Sort by date
2487 History.Sort(TQueryHistoryItemComparer.Create); 2487 History.Sort(TQueryHistoryItemComparer.Create);
2488 2488
2489 // Delete identical history items to avoid spam 2489 // Delete identical history items to avoid spam
2490 // Delete old items 2490 // Delete old items
2491 // Delete items which exceed a max datasize barrier 2491 // Delete items which exceed a max datasize barrier
2492 MinDate := IncDay(Now, -30); 2492 MinDate := IncDay(Now, -30);
2493 RegItemsSize := Thread.Batch.Size; 2493 RegItemsSize := Thread.Batch.Size;
2494 for HistoryItem in History do begin 2494 for HistoryItem in History do begin
2495 Inc(RegItemsSize, Length(HistoryItem.SQL)); 2495 Inc(RegItemsSize, Length(HistoryItem.SQL));
2496 DoDelete := (HistoryItem.SQL = Thread.Batch.SQL) 2496 DoDelete := (HistoryItem.SQL = Thread.Batch.SQL)
2497 or (HistoryItem.Time < MinDate) 2497 or (HistoryItem.Time < MinDate)
2498 or (RegItemsSize > SIZE_MB); 2498 or (RegItemsSize > SIZE_MB);
2499 if DoDelete then 2499 if DoDelete then
2500 MainReg.DeleteValue(IntToStr(HistoryItem.RegValue)); 2500 MainReg.DeleteValue(IntToStr(HistoryItem.RegValue));
2501 end; 2501 end;
2502 History.Free; 2502 History.Free;
2503 2503
2504 // Store history item and closing registry key to ensure writing has finished 2504 // Store history item and closing registry key to ensure writing has finished
2505 MainReg.WriteString(RegName, DateTimeToStr(Now) + DELIM + 2505 MainReg.WriteString(RegName, DateTimeToStr(Now) + DELIM +
2506 Thread.Connection.Database + DELIM + 2506 Thread.Connection.Database + DELIM +
2507 IntToStr(Thread.QueryTime+Thread.QueryNetTime) + DELIM + 2507 IntToStr(Thread.QueryTime+Thread.QueryNetTime) + DELIM +
2508 Thread.Batch.SQL); 2508 Thread.Batch.SQL);
2509 MainReg.CloseKey; 2509 MainReg.CloseKey;
2510 2510
2511 RefreshHelperNode(HELPERNODE_HISTORY); 2511 RefreshHelperNode(HELPERNODE_HISTORY);
2512 end; 2512 end;
2513 2513
2514 // Clean up 2514 // Clean up
2515 DisableProgress; 2515 DisableProgress;
2516 Tab.QueryRunning := False; 2516 Tab.QueryRunning := False;
2517 ValidateControls(Thread); 2517 ValidateControls(Thread);
2518 OperationRunning(False); 2518 OperationRunning(False);
2519 Screen.Cursor := crDefault; 2519 Screen.Cursor := crDefault;
2520 ShowStatusMsg; 2520 ShowStatusMsg;
2521 end; 2521 end;
2522 2522
2523 2523
2524 procedure TMainForm.tabsetQueryClick(Sender: TObject); 2524 procedure TMainForm.tabsetQueryClick(Sender: TObject);
2525 var 2525 var
2526 QueryTab: TQueryTab; 2526 QueryTab: TQueryTab;
2527 i: Integer; 2527 i: Integer;
2528 begin 2528 begin
2529 // Result tab clicked / changed 2529 // Result tab clicked / changed
2530 Screen.Cursor := crHourGlass; 2530 Screen.Cursor := crHourGlass;
2531 QueryTab := nil; 2531 QueryTab := nil;
2532 for i:=0 to QueryTabs.Count-1 do begin 2532 for i:=0 to QueryTabs.Count-1 do begin
2533 if QueryTabs[i].tabsetQuery = Sender then begin 2533 if QueryTabs[i].tabsetQuery = Sender then begin
2534 QueryTab := QueryTabs[i]; 2534 QueryTab := QueryTabs[i];
2535 break; 2535 break;
2536 end; 2536 end;
2537 end; 2537 end;
2538 for i:=0 to QueryTab.ResultTabs.Count-1 do 2538 for i:=0 to QueryTab.ResultTabs.Count-1 do
2539 QueryTab.ResultTabs[i].Grid.Hide; 2539 QueryTab.ResultTabs[i].Grid.Hide;
2540 if QueryTab.ActiveResultTab <> nil then begin 2540 if QueryTab.ActiveResultTab <> nil then begin
2541 QueryTab.ActiveResultTab.Grid.Show; 2541 QueryTab.ActiveResultTab.Grid.Show;
2542 // Reset filter if filter panel was disabled 2542 // Reset filter if filter panel was disabled
2543 UpdateFilterPanel(Sender); 2543 UpdateFilterPanel(Sender);
2544 end; 2544 end;
2545 // Ensure controls are in a valid state 2545 // Ensure controls are in a valid state
2546 ValidateControls(Sender); 2546 ValidateControls(Sender);
2547 Screen.Cursor := crDefault; 2547 Screen.Cursor := crDefault;
2548 ShowStatusMsg; 2548 ShowStatusMsg;
2549 end; 2549 end;
2550 2550
2551 2551
2552 procedure TMainForm.tabsetQueryGetImageIndex(Sender: TObject; TabIndex: Integer; 2552 procedure TMainForm.tabsetQueryGetImageIndex(Sender: TObject; TabIndex: Integer;
2553 var ImageIndex: Integer); 2553 var ImageIndex: Integer);
2554 begin 2554 begin
2555 // Give result tabs of editable results a table icon 2555 // Give result tabs of editable results a table icon
2556 try 2556 try
2557 ActiveQueryTab.ResultTabs[TabIndex].Results.TableName; 2557 ActiveQueryTab.ResultTabs[TabIndex].Results.TableName;
2558 ImageIndex := 14; 2558 ImageIndex := 14;
2559 except 2559 except
2560 ImageIndex := -1; 2560 ImageIndex := -1;
2561 end; 2561 end;
2562 end; 2562 end;
2563 2563
2564 2564
2565 procedure TMainForm.actExportDataExecute(Sender: TObject); 2565 procedure TMainForm.actExportDataExecute(Sender: TObject);
2566 var 2566 var
2567 ExportDialog: TfrmExportGrid; 2567 ExportDialog: TfrmExportGrid;
2568 begin 2568 begin
2569 // Save data in current dataset into various text file formats 2569 // Save data in current dataset into various text file formats
2570 ExportDialog := TfrmExportGrid.Create(Self); 2570 ExportDialog := TfrmExportGrid.Create(Self);
2571 ExportDialog.Grid := ActiveGrid; 2571 ExportDialog.Grid := ActiveGrid;
2572 ExportDialog.ShowModal; 2572 ExportDialog.ShowModal;
2573 end; 2573 end;
2574 2574
2575 2575
2576 procedure TMainForm.actDataPreviewUpdate(Sender: TObject); 2576 procedure TMainForm.actDataPreviewUpdate(Sender: TObject);
2577 var 2577 var
2578 Grid: TVirtualStringTree; 2578 Grid: TVirtualStringTree;
2579 begin 2579 begin
2580 // Enable or disable ImageView action 2580 // Enable or disable ImageView action
2581 Grid := ActiveGrid; 2581 Grid := ActiveGrid;
2582 (Sender as TAction).Enabled := (Grid <> nil) 2582 (Sender as TAction).Enabled := (Grid <> nil)
2583 and (Grid.FocusedColumn <> NoColumn) 2583 and (Grid.FocusedColumn <> NoColumn)
2584 and (GridResult(Grid).DataType(Grid.FocusedColumn).Category = dtcBinary) 2584 and (GridResult(Grid).DataType(Grid.FocusedColumn).Category = dtcBinary)
2585 end; 2585 end;
2586 2586
2587 2587
2588 procedure TMainForm.actDataPreviewExecute(Sender: TObject); 2588 procedure TMainForm.actDataPreviewExecute(Sender: TObject);
2589 var 2589 var
2590 MakeVisible: Boolean; 2590 MakeVisible: Boolean;
2591 begin 2591 begin
2592 // Show or hide preview area 2592 // Show or hide preview area
2593 actDataPreview.Checked := not actDataPreview.Checked; 2593 actDataPreview.Checked := not actDataPreview.Checked;
2594 MakeVisible := actDataPreview.Checked; 2594 MakeVisible := actDataPreview.Checked;
2595 pnlPreview.Visible := MakeVisible; 2595 pnlPreview.Visible := MakeVisible;
2596 spltPreview.Visible := MakeVisible; 2596 spltPreview.Visible := MakeVisible;
2597 if MakeVisible then 2597 if MakeVisible then
2598 UpdatePreviewPanel; 2598 UpdatePreviewPanel;
2599 end; 2599 end;
2600 2600
2601 2601
2602 procedure TMainForm.UpdatePreviewPanel; 2602 procedure TMainForm.UpdatePreviewPanel;
2603 var 2603 var
2604 Grid: TVirtualStringTree; 2604 Grid: TVirtualStringTree;
2605 Results: TDBQuery; 2605 Results: TDBQuery;
2606 RowNum: PCardinal; 2606 RowNum: PCardinal;
2607 ImgType: String; 2607 ImgType: String;
2608 Content, Header: AnsiString; 2608 Content, Header: AnsiString;
2609 ContentStream: TMemoryStream; 2609 ContentStream: TMemoryStream;
2610 StrLen: Integer; 2610 StrLen: Integer;
2611 GraphicClass: TGraphicExGraphicClass; 2611 GraphicClass: TGraphicExGraphicClass;
2612 Graphic: TGraphic; 2612 Graphic: TGraphic;
2613 AllExtensions: TStringList; 2613 AllExtensions: TStringList;
2614 i: Integer; 2614 i: Integer;
2615 begin 2615 begin
2616 // Load BLOB contents into preview area 2616 // Load BLOB contents into preview area
2617 Grid := ActiveGrid; 2617 Grid := ActiveGrid;
2618 Results := GridResult(Grid); 2618 Results := GridResult(Grid);
2619 if not Assigned(Results) then 2619 if not Assigned(Results) then
2620 Exit; 2620 Exit;
2621 Screen.Cursor := crHourGlass; 2621 Screen.Cursor := crHourGlass;
2622 try 2622 try
2623 ShowStatusMsg('Loading contents into image viewer ...'); 2623 ShowStatusMsg('Loading contents into image viewer ...');
2624 lblPreviewTitle.Caption := 'Loading ...'; 2624 lblPreviewTitle.Caption := 'Loading ...';
2625 lblPreviewTitle.Repaint; 2625 lblPreviewTitle.Repaint;
2626 imgPreview.Picture := nil; 2626 imgPreview.Picture := nil;
2627 AnyGridEnsureFullRow(Grid, Grid.FocusedNode); 2627 AnyGridEnsureFullRow(Grid, Grid.FocusedNode);
2628 RowNum := Grid.GetNodeData(Grid.FocusedNode); 2628 RowNum := Grid.GetNodeData(Grid.FocusedNode);
2629 Results.RecNo := RowNum^; 2629 Results.RecNo := RowNum^;
2630 2630
2631 Content := AnsiString(Results.Col(Grid.FocusedColumn)); 2631 Content := AnsiString(Results.Col(Grid.FocusedColumn));
2632 StrLen := Length(Content); 2632 StrLen := Length(Content);
2633 ContentStream := TMemoryStream.Create; 2633 ContentStream := TMemoryStream.Create;
2634 ContentStream.Write(Content[1], StrLen); 2634 ContentStream.Write(Content[1], StrLen);
2635 ContentStream.Position := 0; 2635 ContentStream.Position := 0;
2636 GraphicClass := FileFormatList.GraphicFromContent(ContentStream); 2636 GraphicClass := FileFormatList.GraphicFromContent(ContentStream);
2637 Graphic := nil; 2637 Graphic := nil;
2638 ContentStream.Position := 0; 2638 ContentStream.Position := 0;
2639 ImgType := 'UnknownType'; 2639 ImgType := 'UnknownType';
2640 if GraphicClass <> nil then begin 2640 if GraphicClass <> nil then begin
2641 AllExtensions := TStringList.Create; 2641 AllExtensions := TStringList.Create;
2642 FileFormatList.GetExtensionList(AllExtensions); 2642 FileFormatList.GetExtensionList(AllExtensions);
2643 for i:=0 to AllExtensions.Count-1 do begin 2643 for i:=0 to AllExtensions.Count-1 do begin
2644 if FileFormatList.GraphicFromExtension(AllExtensions[i]) = GraphicClass then begin 2644 if FileFormatList.GraphicFromExtension(AllExtensions[i]) = GraphicClass then begin
2645 ImgType := UpperCase(AllExtensions[i]); 2645 ImgType := UpperCase(AllExtensions[i]);
2646 break; 2646 break;
2647 end; 2647 end;
2648 end; 2648 end;
2649 Graphic := GraphicClass.Create; 2649 Graphic := GraphicClass.Create;
2650 end else begin 2650 end else begin
2651 Header := Copy(Content, 1, 50); 2651 Header := Copy(Content, 1, 50);
2652 if Copy(Header, 7, 4) = 'JFIF' then begin 2652 if Copy(Header, 7, 4) = 'JFIF' then begin
2653 ImgType := 'JPEG'; 2653 ImgType := 'JPEG';
2654 Graphic := TJPEGImage.Create; 2654 Graphic := TJPEGImage.Create;
2655 end else if Copy(Header, 1, 3) = 'GIF' then begin 2655 end else if Copy(Header, 1, 3) = 'GIF' then begin
2656 ImgType := 'GIF'; 2656 ImgType := 'GIF';
2657 Graphic := TGIFImage.Create; 2657 Graphic := TGIFImage.Create;
2658 end else if Copy(Header, 1, 2) = 'BM' then begin 2658 end else if Copy(Header, 1, 2) = 'BM' then begin
2659 ImgType := 'BMP'; 2659 ImgType := 'BMP';
2660 Graphic := TBitmap.Create; 2660 Graphic := TBitmap.Create;
2661 end; 2661 end;
2662 end; 2662 end;
2663 if Assigned(Graphic) then begin 2663 if Assigned(Graphic) then begin
2664 try 2664 try
2665 Graphic.LoadFromStream(ContentStream); 2665 Graphic.LoadFromStream(ContentStream);
2666 imgPreview.Picture.Graphic := Graphic; 2666 imgPreview.Picture.Graphic := Graphic;
2667 lblPreviewTitle.Caption := ImgType+': '+ 2667 lblPreviewTitle.Caption := ImgType+': '+
2668 IntToStr(Graphic.Width)+' x '+IntToStr(Graphic.Height)+' pixels, 100%, '+ 2668 IntToStr(Graphic.Width)+' x '+IntToStr(Graphic.Height)+' pixels, 100%, '+
2669 FormatByteNumber(StrLen); 2669 FormatByteNumber(StrLen);
2670 spltPreview.OnMoved(spltPreview); 2670 spltPreview.OnMoved(spltPreview);
2671 except 2671 except
2672 on E:Exception do 2672 on E:Exception do
2673 lblPreviewTitle.Caption := ImgType+': ' + E.Message + ' ('+E.ClassName+')'; 2673 lblPreviewTitle.Caption := ImgType+': ' + E.Message + ' ('+E.ClassName+')';
2674 end; 2674 end;
2675 FreeAndNil(ContentStream); 2675 FreeAndNil(ContentStream);
2676 end else 2676 end else
2677 lblPreviewTitle.Caption := 'No image detected.'; 2677 lblPreviewTitle.Caption := 'No image detected.';
2678 finally 2678 finally
2679 lblPreviewTitle.Hint := lblPreviewTitle.Caption; 2679 lblPreviewTitle.Hint := lblPreviewTitle.Caption;
2680 ShowStatusMsg; 2680 ShowStatusMsg;
2681 Screen.Cursor := crDefault; 2681 Screen.Cursor := crDefault;
2682 end; 2682 end;
2683 end; 2683 end;
2684 2684
2685 2685
2686 procedure TMainForm.spltPreviewMoved(Sender: TObject); 2686 procedure TMainForm.spltPreviewMoved(Sender: TObject);
2687 var 2687 var
2688 rx: TRegExpr; 2688 rx: TRegExpr;
2689 ZoomFactorW, ZoomFactorH: Integer; 2689 ZoomFactorW, ZoomFactorH: Integer;
2690 begin 2690 begin
2691 // Do not overscale image so it's never zoomed to more than 100% 2691 // Do not overscale image so it's never zoomed to more than 100%
2692 if (imgPreview.Picture.Graphic = nil) or (imgPreview.Picture.Graphic.Empty) then 2692 if (imgPreview.Picture.Graphic = nil) or (imgPreview.Picture.Graphic.Empty) then
2693 Exit; 2693 Exit;
2694 imgPreview.Stretch := (imgPreview.Picture.Width > imgPreview.Width) or (imgPreview.Picture.Height > imgPreview.Height); 2694 imgPreview.Stretch := (imgPreview.Picture.Width > imgPreview.Width) or (imgPreview.Picture.Height > imgPreview.Height);
2695 ZoomFactorW := Trunc(Min(imgPreview.Picture.Width, imgPreview.Width) / imgPreview.Picture.Width * 100); 2695 ZoomFactorW := Trunc(Min(imgPreview.Picture.Width, imgPreview.Width) / imgPreview.Picture.Width * 100);
2696 ZoomFactorH := Trunc(Min(imgPreview.Picture.Height, imgPreview.Height) / imgPreview.Picture.Height * 100); 2696 ZoomFactorH := Trunc(Min(imgPreview.Picture.Height, imgPreview.Height) / imgPreview.Picture.Height * 100);
2697 rx := TRegExpr.Create; 2697 rx := TRegExpr.Create;
2698 rx.Expression := '(\D)(\d+%)'; 2698 rx.Expression := '(\D)(\d+%)';
2699 lblPreviewTitle.Caption := rx.Replace(lblPreviewTitle.Caption, '${1}'+IntToStr(Min(ZoomFactorH, ZoomFactorW))+'%', true); 2699 lblPreviewTitle.Caption := rx.Replace(lblPreviewTitle.Caption, '${1}'+IntToStr(Min(ZoomFactorH, ZoomFactorW))+'%', true);
2700 lblPreviewTitle.Hint := lblPreviewTitle.Caption; 2700 lblPreviewTitle.Hint := lblPreviewTitle.Caption;
2701 rx.Free; 2701 rx.Free;
2702 end; 2702 end;
2703 2703
2704 2704
2705 procedure TMainForm.actDataSaveBlobToFileExecute(Sender: TObject); 2705 procedure TMainForm.actDataSaveBlobToFileExecute(Sender: TObject);
2706 var 2706 var
2707 Grid: TVirtualStringTree; 2707 Grid: TVirtualStringTree;
2708 Results: TDBQuery; 2708 Results: TDBQuery;
2709 RowNum: PCardinal; 2709 RowNum: PCardinal;
2710 Content: AnsiString; 2710 Content: AnsiString;
2711 FileStream: TFileStream; 2711 FileStream: TFileStream;
2712 StrLen: Integer; 2712 StrLen: Integer;
2713 Dialog: TSaveDialog; 2713 Dialog: TSaveDialog;
2714 begin 2714 begin
2715 // Save BLOB to local file 2715 // Save BLOB to local file
2716 Grid := ActiveGrid; 2716 Grid := ActiveGrid;
2717 Results := GridResult(Grid); 2717 Results := GridResult(Grid);
2718 Dialog := TSaveDialog.Create(Self); 2718 Dialog := TSaveDialog.Create(Self);
2719 Dialog.Filter := 'All files (*.*)|*.*'; 2719 Dialog.Filter := 'All files (*.*)|*.*';
2720 Dialog.FileName := Results.ColumnOrgNames[Grid.FocusedColumn]; 2720 Dialog.FileName := Results.ColumnOrgNames[Grid.FocusedColumn];
2721 if not (Results.DataType(Grid.FocusedColumn).Category in [dtcBinary, dtcSpatial]) then 2721 if not (Results.DataType(Grid.FocusedColumn).Category in [dtcBinary, dtcSpatial]) then
2722 Dialog.FileName := Dialog.FileName + '.txt'; 2722 Dialog.FileName := Dialog.FileName + '.txt';
2723 if Dialog.Execute then begin 2723 if Dialog.Execute then begin
2724 Screen.Cursor := crHourGlass; 2724 Screen.Cursor := crHourGlass;
2725 AnyGridEnsureFullRow(Grid, Grid.FocusedNode); 2725 AnyGridEnsureFullRow(Grid, Grid.FocusedNode);
2726 RowNum := Grid.GetNodeData(Grid.FocusedNode); 2726 RowNum := Grid.GetNodeData(Grid.FocusedNode);
2727 Results.RecNo := RowNum^; 2727 Results.RecNo := RowNum^;
2728 if Results.DataType(Grid.FocusedColumn).Category in [dtcBinary, dtcSpatial] then 2728 if Results.DataType(Grid.FocusedColumn).Category in [dtcBinary, dtcSpatial] then
2729 Content := AnsiString(Results.Col(Grid.FocusedColumn)) 2729 Content := AnsiString(Results.Col(Grid.FocusedColumn))
2730 else 2730 else
2731 Content := Utf8Encode(Results.Col(Grid.FocusedColumn)); 2731 Content := Utf8Encode(Results.Col(Grid.FocusedColumn));
2732 StrLen := Length(Content); 2732 StrLen := Length(Content);
2733 try 2733 try
2734 FileStream := TFileStream.Create(Dialog.FileName, fmCreate or fmOpenWrite); 2734 FileStream := TFileStream.Create(Dialog.FileName, fmCreate or fmOpenWrite);
2735 FileStream.Write(Content[1], StrLen); 2735 FileStream.Write(Content[1], StrLen);
2736 except on E:Exception do 2736 except on E:Exception do
2737 ErrorDialog(E.Message); 2737 ErrorDialog(E.Message);
2738 end; 2738 end;
2739 FreeAndNil(FileStream); 2739 FreeAndNil(FileStream);
2740 Screen.Cursor := crDefault; 2740 Screen.Cursor := crDefault;
2741 end; 2741 end;
2742 Dialog.Free; 2742 Dialog.Free;
2743 end; 2743 end;
2744 2744
2745 2745
2746 procedure TMainForm.actInsertFilesExecute(Sender: TObject); 2746 procedure TMainForm.actInsertFilesExecute(Sender: TObject);
2747 var 2747 var
2748 Dialog: TfrmInsertFiles; 2748 Dialog: TfrmInsertFiles;
2749 begin 2749 begin
2750 Dialog := TfrmInsertFiles.Create(Self); 2750 Dialog := TfrmInsertFiles.Create(Self);
2751 Dialog.ShowModal; 2751 Dialog.ShowModal;
2752 end; 2752 end;
2753 2753
2754 // Drop Table(s) 2754 // Drop Table(s)
2755 procedure TMainForm.actDropObjectsExecute(Sender: TObject); 2755 procedure TMainForm.actDropObjectsExecute(Sender: TObject);
2756 var 2756 var
2757 msg, db: String; 2757 msg, db: String;
2758 InDBTree: Boolean; 2758 InDBTree: Boolean;
2759 Act: TAction; 2759 Act: TAction;
2760 Node: PVirtualNode; 2760 Node: PVirtualNode;
2761 Obj: PDBObject; 2761 Obj: PDBObject;
2762 DBObject: TDBObject; 2762 DBObject: TDBObject;
2763 ObjectList: TDBObjectList; 2763 ObjectList: TDBObjectList;
2764 Editor: TDBObjectEditor; 2764 Editor: TDBObjectEditor;
2765 Conn: TDBConnection; 2765 Conn: TDBConnection;
2766 begin 2766 begin
2767 Conn := ActiveConnection; 2767 Conn := ActiveConnection;
2768 2768
2769 ObjectList := TDBobjectList.Create(TDBObjectDropComparer.Create, False); 2769 ObjectList := TDBobjectList.Create(TDBObjectDropComparer.Create, False);
2770 2770
2771 Act := Sender as TAction; 2771 Act := Sender as TAction;
2772 InDBTree := (Act.ActionComponent is TMenuItem) 2772 InDBTree := (Act.ActionComponent is TMenuItem)
2773 and (TPopupMenu((Act.ActionComponent as TMenuItem).GetParentMenu).PopupComponent = DBTree); 2773 and (TPopupMenu((Act.ActionComponent as TMenuItem).GetParentMenu).PopupComponent = DBTree);
2774 if InDBTree then begin 2774 if InDBTree then begin
2775 // drop table selected in tree view. 2775 // drop table selected in tree view.
2776 case ActiveDBObj.NodeType of 2776 case ActiveDBObj.NodeType of
2777 lntDb: begin 2777 lntDb: begin
2778 if MessageDialog('Drop Database "'+Conn.Database+'"?', 'WARNING: You will lose all objects in database '+Conn.Database+'!', mtConfirmation, [mbok,mbcancel]) <> mrok then 2778 if MessageDialog('Drop Database "'+Conn.Database+'"?', 'WARNING: You will lose all objects in database '+Conn.Database+'!', mtConfirmation, [mbok,mbcancel]) <> mrok then
2779 Abort; 2779 Abort;
2780 try 2780 try
2781 db := Conn.Database; 2781 db := Conn.Database;
2782 Node := FindDBNode(DBtree, Conn, db); 2782 Node := FindDBNode(DBtree, Conn, db);
2783 SetActiveDatabase('', Conn); 2783 SetActiveDatabase('', Conn);
2784 Conn.Query('DROP DATABASE ' + Conn.QuoteIdent(db)); 2784 Conn.Query('DROP DATABASE ' + Conn.QuoteIdent(db));
2785 DBtree.DeleteNode(Node); 2785 DBtree.DeleteNode(Node);
2786 Conn.ClearDbObjects(db); 2786 Conn.ClearDbObjects(db);
2787 Conn.RefreshAllDatabases; 2787 Conn.RefreshAllDatabases;
2788 InvalidateVT(ListDatabases, VTREE_NOTLOADED_PURGECACHE, False); 2788 InvalidateVT(ListDatabases, VTREE_NOTLOADED_PURGECACHE, False);
2789 except 2789 except
2790 on E:EDatabaseError do 2790 on E:EDatabaseError do
2791 ErrorDialog(E.Message); 2791 ErrorDialog(E.Message);
2792 end; 2792 end;
2793 Exit; 2793 Exit;
2794 end; 2794 end;
2795 lntTable..lntEvent: ObjectList.Add(ActiveDbObj); 2795 lntTable..lntEvent: ObjectList.Add(ActiveDbObj);
2796 end; 2796 end;
2797 end else begin 2797 end else begin
2798 // Invoked from database tab 2798 // Invoked from database tab
2799 Node := GetNextNode(ListTables, nil, True); 2799 Node := GetNextNode(ListTables, nil, True);
2800 while Assigned(Node) do begin 2800 while Assigned(Node) do begin
2801 Obj := ListTables.GetNodeData(Node); 2801 Obj := ListTables.GetNodeData(Node);
2802 ObjectList.Add(Obj^); 2802 ObjectList.Add(Obj^);
2803 Node := GetNextNode(ListTables, Node, True); 2803 Node := GetNextNode(ListTables, Node, True);
2804 end; 2804 end;
2805 end; 2805 end;
2806 2806
2807 // Fix actions temporarily enabled for popup menu. 2807 // Fix actions temporarily enabled for popup menu.
2808 ValidateControls(Sender); 2808 ValidateControls(Sender);
2809 2809
2810 // Safety stop to avoid firing DROP TABLE without tablenames 2810 // Safety stop to avoid firing DROP TABLE without tablenames
2811 if ObjectList.Count = 0 then 2811 if ObjectList.Count = 0 then
2812 Exit; 2812 Exit;
2813 2813
2814 // Ask user for confirmation to drop selected objects 2814 // Ask user for confirmation to drop selected objects
2815 ObjectList.Sort; 2815 ObjectList.Sort;
2816 msg := ''; 2816 msg := '';
2817 for DBObject in ObjectList do 2817 for DBObject in ObjectList do
2818 msg := msg + DBObject.Name + ', '; 2818 msg := msg + DBObject.Name + ', ';
2819 Delete(msg, Length(msg)-1, 2); 2819 Delete(msg, Length(msg)-1, 2);
2820 if MessageDialog('Drop ' + IntToStr(ObjectList.Count) + ' object(s) in database "'+Conn.Database+'"?', msg, mtConfirmation, [mbok,mbcancel]) = mrOk then begin 2820 if MessageDialog('Drop ' + IntToStr(ObjectList.Count) + ' object(s) in database "'+Conn.Database+'"?', msg, mtConfirmation, [mbok,mbcancel]) = mrOk then begin
2821 try 2821 try
2822 // Disable foreign key checks to avoid SQL errors 2822 // Disable foreign key checks to avoid SQL errors
2823 if Conn.ServerVersionInt >= 40014 then 2823 if Conn.ServerVersionInt >= 40014 then
2824 Conn.Query('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0'); 2824 Conn.Query('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0');
2825 // Compose and run DROP [TABLE|VIEW|...] queries 2825 // Compose and run DROP [TABLE|VIEW|...] queries
2826 Editor := ActiveObjectEditor; 2826 Editor := ActiveObjectEditor;
2827 for DBObject in ObjectList do begin 2827 for DBObject in ObjectList do begin
2828 Conn.Query('DROP '+UpperCase(DBObject.ObjType)+' '+DBObject.QuotedName); 2828 Conn.Query('DROP '+UpperCase(DBObject.ObjType)+' '+DBObject.QuotedName);
2829 if Assigned(Editor) and Editor.Modified and Editor.DBObject.IsSameAs(DBObject) then 2829 if Assigned(Editor) and Editor.Modified and Editor.DBObject.IsSameAs(DBObject) then
2830 Editor.Modified := False; 2830 Editor.Modified := False;
2831 end; 2831 end;
2832 if Conn.ServerVersionInt >= 40014 then 2832 if Conn.ServerVersionInt >= 40014 then
2833 Conn.Query('SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS'); 2833 Conn.Query('SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS');
2834 // Refresh ListTables + dbtree so the dropped tables are gone: 2834 // Refresh ListTables + dbtree so the dropped tables are gone:
2835 Conn.ClearDbObjects(ActiveDatabase); 2835 Conn.ClearDbObjects(ActiveDatabase);
2836 SetActiveDatabase(Conn.Database, Conn); 2836 SetActiveDatabase(Conn.Database, Conn);
2837 except 2837 except
2838 on E:EDatabaseError do 2838 on E:EDatabaseError do
2839 ErrorDialog(E.Message); 2839 ErrorDialog(E.Message);
2840 end; 2840 end;
2841 ObjectList.Free; 2841 ObjectList.Free;
2842 end; 2842 end;
2843 end; 2843 end;
2844 2844
2845 2845
2846 procedure TMainForm.actLaunchCommandlineExecute(Sender: TObject); 2846 procedure TMainForm.actLaunchCommandlineExecute(Sender: TObject);
2847 var 2847 var
2848 path, p, log, cmd: String; 2848 path, p, log, cmd: String;
2849 sep: Char; 2849 sep: Char;
2850 Conn: TDBConnection; 2850 Conn: TDBConnection;
2851 rx: TRegExpr; 2851 rx: TRegExpr;
2852 begin 2852 begin
2853 // Launch mysql.exe 2853 // Launch mysql.exe
2854 Conn := ActiveConnection; 2854 Conn := ActiveConnection;
2855 if Conn.Parameters.NetTypeGroup <> ngMySQL then 2855 if Conn.Parameters.NetTypeGroup <> ngMySQL then
2856 ErrorDialog('Command line only works on MySQL connections.') 2856 ErrorDialog('Command line only works on MySQL connections.')
2857 else begin 2857 else begin
2858 if FIsWine then begin 2858 if FIsWine then begin
2859 cmd := 'mysql'; 2859 cmd := 'mysql';
2860 sep := '/'; 2860 sep := '/';
2861 end else begin 2861 end else begin
2862 cmd := 'mysql.exe'; 2862 cmd := 'mysql.exe';
2863 sep := '\'; 2863 sep := '\';
2864 end; 2864 end;
2865 path := GetRegValue(REGNAME_MYSQLBINARIES, DEFAULT_MYSQLBINARIES); 2865 path := GetRegValue(REGNAME_MYSQLBINARIES, DEFAULT_MYSQLBINARIES);
2866 if (Length(path)>0) and (path[Length(path)] <> sep) then 2866 if (Length(path)>0) and (path[Length(path)] <> sep) then
2867 path := path + sep; 2867 path := path + sep;
2868 if not FileExists(path+cmd, true) then begin 2868 if not FileExists(path+cmd, true) then begin
2869 ErrorDialog('You need to tell '+APPNAME+' where your MySQL binaries reside, in Tools > Preferences > Miscellaneous.'+ 2869 ErrorDialog('You need to tell '+APPNAME+' where your MySQL binaries reside, in Tools > Preferences > Miscellaneous.'+
2870 CRLF+CRLF+'Current setting is: '+CRLF+'"'+path+'"'); 2870 CRLF+CRLF+'Current setting is: '+CRLF+'"'+path+'"');
2871 end else begin 2871 end else begin
2872 p := ''; 2872 p := '';
2873 if FIsWine then begin 2873 if FIsWine then begin
2874 p := ' -e '+path+cmd; 2874 p := ' -e '+path+cmd;
2875 path := ''; 2875 path := '';
2876 cmd := '$TERM'; 2876 cmd := '$TERM';
2877 end; 2877 end;
2878 2878
2879 case Conn.Parameters.NetType of 2879 case Conn.Parameters.NetType of
2880 ntMySQL_TCPIP: begin 2880 ntMySQL_TCPIP: begin
2881 p := p + ' --host="'+Conn.Parameters.Hostname+'" --port='+IntToStr(Conn.Parameters.Port); 2881 p := p + ' --host="'+Conn.Parameters.Hostname+'" --port='+IntToStr(Conn.Parameters.Port);
2882 if Conn.Parameters.WantSSL then 2882 if Conn.Parameters.WantSSL then
2883 p := p + ' --ssl --ssl-key="'+Conn.Parameters.SSLPrivateKey+'" --ssl-cert="'+Conn.Parameters.SSLCertificate+'" --ssl-ca="'+Conn.Parameters.SSLCACertificate+'"'; 2883 p := p + ' --ssl --ssl-key="'+Conn.Parameters.SSLPrivateKey+'" --ssl-cert="'+Conn.Parameters.SSLCertificate+'" --ssl-ca="'+Conn.Parameters.SSLCACertificate+'"';
2884 end; 2884 end;
2885 ntMySQL_NamedPipe: 2885 ntMySQL_NamedPipe:
2886 p := p + ' --protocol=socket --socket="'+Conn.Parameters.Hostname+'"'; 2886 p := p + ' --protocol=socket --socket="'+Conn.Parameters.Hostname+'"';
2887 ntMySQL_SSHtunnel: 2887 ntMySQL_SSHtunnel:
2888 p := p + ' --host="localhost" --port='+IntToStr(Conn.Parameters.SSHLocalPort); 2888 p := p + ' --host="localhost" --port='+IntToStr(Conn.Parameters.SSHLocalPort);
2889 end; 2889 end;
2890 2890
2891 p := p + ' --user="'+Conn.Parameters.Username+'"'; 2891 p := p + ' --user="'+Conn.Parameters.Username+'"';
2892 if Conn.Parameters.Password <> '' then 2892 if Conn.Parameters.Password <> '' then
2893 p := p + ' --password="'+Conn.Parameters.Password+'"'; 2893 p := p + ' --password="'+Conn.Parameters.Password+'"';
2894 if Conn.Parameters.Compressed then 2894 if Conn.Parameters.Compressed then
2895 p := p + ' --compress'; 2895 p := p + ' --compress';
2896 if ActiveDatabase <> '' then 2896 if ActiveDatabase <> '' then
2897 p := p + ' --database="' + ActiveDatabase + '"'; 2897 p := p + ' --database="' + ActiveDatabase + '"';
2898 rx := TRegExpr.Create; 2898 rx := TRegExpr.Create;
2899 rx.Expression := '(\-\-password\=")([^"]*)(")'; 2899 rx.Expression := '(\-\-password\=")([^"]*)(")';
2900 log := path + cmd + p; 2900 log := path + cmd + p;
2901 log := rx.Replace(log, '$1********$3', true); 2901 log := rx.Replace(log, '$1********$3', true);
2902 LogSQL('Launching command line: '+log, lcInfo); 2902 LogSQL('Launching command line: '+log, lcInfo);
2903 rx.Free; 2903 rx.Free;
2904 ShellExec(cmd, path, p); 2904 ShellExec(cmd, path, p);
2905 end; 2905 end;
2906 end; 2906 end;
2907 end; 2907 end;
2908 2908
2909 2909
2910 // Load SQL-file, make sure that SheetQuery is activated 2910 // Load SQL-file, make sure that SheetQuery is activated
2911 procedure TMainForm.actLoadSQLExecute(Sender: TObject); 2911 procedure TMainForm.actLoadSQLExecute(Sender: TObject);
2912 var 2912 var
2913 i: Integer; 2913 i: Integer;
2914 Dialog: TOpenTextFileDialog; 2914 Dialog: TOpenTextFileDialog;
2915 Encoding: TEncoding; 2915 Encoding: TEncoding;
2916 Tab: TQueryTab; 2916 Tab: TQueryTab;
2917 ConsiderActiveTab: Boolean; 2917 ConsiderActiveTab: Boolean;
2918 begin 2918 begin
2919 Dialog := TOpenTextFileDialog.Create(Self); 2919 Dialog := TOpenTextFileDialog.Create(Self);
2920 Dialog.Options := Dialog.Options + [ofAllowMultiSelect]; 2920 Dialog.Options := Dialog.Options + [ofAllowMultiSelect];
2921 Dialog.Filter := 'SQL-Scripts (*.sql)|*.sql|All files (*.*)|*.*'; 2921 Dialog.Filter := 'SQL-Scripts (*.sql)|*.sql|All files (*.*)|*.*';
2922 Dialog.DefaultExt := 'sql'; 2922 Dialog.DefaultExt := 'sql';
2923 Dialog.Encodings.Assign(FileEncodings); 2923 Dialog.Encodings.Assign(FileEncodings);
2924 Dialog.EncodingIndex := 0; 2924 Dialog.EncodingIndex := 0;
2925 if Dialog.Execute then begin 2925 if Dialog.Execute then begin
2926 Encoding := GetEncodingByName(Dialog.Encodings[Dialog.EncodingIndex]); 2926 Encoding := GetEncodingByName(Dialog.Encodings[Dialog.EncodingIndex]);
2927 if not RunQueryFiles(Dialog.Files, Encoding) then begin 2927 if not RunQueryFiles(Dialog.Files, Encoding) then begin
2928 ConsiderActiveTab := True; 2928 ConsiderActiveTab := True;
2929 for i:=0 to Dialog.Files.Count-1 do begin 2929 for i:=0 to Dialog.Files.Count-1 do begin
2930 Tab := ActiveOrEmptyQueryTab(ConsiderActiveTab); 2930 Tab := ActiveOrEmptyQueryTab(ConsiderActiveTab);
2931 ConsiderActiveTab := False; 2931 ConsiderActiveTab := False;
2932 Tab.LoadContents(Dialog.Files[i], True, Encoding); 2932 Tab.LoadContents(Dialog.Files[i], True, Encoding);
2933 if i = Dialog.Files.Count-1 then 2933 if i = Dialog.Files.Count-1 then
2934 SetMainTab(Tab.TabSheet); 2934 SetMainTab(Tab.TabSheet);
2935 end; 2935 end;
2936 end; 2936 end;
2937 end; 2937 end;
2938 Dialog.Free; 2938 Dialog.Free;
2939 end; 2939 end;
2940 2940
2941 2941
2942 {$WARN SYMBOL_PLATFORM OFF} 2942 {$WARN SYMBOL_PLATFORM OFF}
2943 function TMainForm.RunQueryFiles(Filenames: TStrings; Encoding: TEncoding): Boolean; 2943 function TMainForm.RunQueryFiles(Filenames: TStrings; Encoding: TEncoding): Boolean;
2944 var 2944 var
2945 i: Integer; 2945 i: Integer;
2946 Filesize, FilesizeSum: Int64; 2946 Filesize, FilesizeSum: Int64;
2947 msgtext: String; 2947 msgtext: String;
2948 AbsentFiles, PopupFileList: TStringList; 2948 AbsentFiles, PopupFileList: TStringList;
2949 DoRunFiles: Boolean; 2949 DoRunFiles: Boolean;
2950 RunFileDialog: TRunSQLFileForm; 2950 RunFileDialog: TRunSQLFileForm;
2951 Dialog: TTaskDialog; 2951 Dialog: TTaskDialog;
2952 Btn: TTaskDialogButtonItem; 2952 Btn: TTaskDialogButtonItem;
2953 DialogResult: TModalResult; 2953 DialogResult: TModalResult;
2954 const 2954 const
2955 RunFileSize = 5*SIZE_MB; 2955 RunFileSize = 5*SIZE_MB;
2956 begin 2956 begin
2957 // Ask for execution when loading big files, or return false 2957 // Ask for execution when loading big files, or return false
2958 Result := False; 2958 Result := False;
2959 2959
2960 // Remove non existant files 2960 // Remove non existant files
2961 AbsentFiles := TStringList.Create; 2961 AbsentFiles := TStringList.Create;
2962 for i:=Filenames.Count-1 downto 0 do begin 2962 for i:=Filenames.Count-1 downto 0 do begin
2963 if not FileExists(Filenames[i]) then begin 2963 if not FileExists(Filenames[i]) then begin
2964 AbsentFiles.Add(Filenames[i]); 2964 AbsentFiles.Add(Filenames[i]);
2965 Filenames.Delete(i); 2965 Filenames.Delete(i);
2966 end; 2966 end;
2967 end; 2967 end;
2968 // Check if one or more files are large 2968 // Check if one or more files are large
2969 DoRunFiles := False; 2969 DoRunFiles := False;
2970 PopupFileList := TStringList.Create; 2970 PopupFileList := TStringList.Create;
2971 FilesizeSum := 0; 2971 FilesizeSum := 0;
2972 for i:=0 to Filenames.Count-1 do begin 2972 for i:=0 to Filenames.Count-1 do begin
2973 FileSize := _GetFileSize(Filenames[i]); 2973 FileSize := _GetFileSize(Filenames[i]);
2974 Inc(FilesizeSum, Filesize); 2974 Inc(FilesizeSum, Filesize);
2975 PopupFileList.Add(ExtractFilename(Filenames[i]) + ' (' + FormatByteNumber(FileSize) + ')'); 2975 PopupFileList.Add(ExtractFilename(Filenames[i]) + ' (' + FormatByteNumber(FileSize) + ')');
2976 DoRunFiles := DoRunFiles or (FileSize > RunFileSize); 2976 DoRunFiles := DoRunFiles or (FileSize > RunFileSize);
2977 end; 2977 end;
2978 2978
2979 if DoRunFiles then begin 2979 if DoRunFiles then begin
2980 if (Win32MajorVersion >= 6) and ThemeServices.ThemesEnabled then begin 2980 if (Win32MajorVersion >= 6) and ThemeServices.ThemesEnabled then begin
2981 Dialog := TTaskDialog.Create(Self); 2981 Dialog := TTaskDialog.Create(Self);
2982 Dialog.Caption := 'Opening large files'; 2982 Dialog.Caption := 'Opening large files';
2983 Dialog.Text := 'Selected files have a size of '+FormatByteNumber(FilesizeSum, 1); 2983 Dialog.Text := 'Selected files have a size of '+FormatByteNumber(FilesizeSum, 1);
2984 Dialog.ExpandButtonCaption := 'File list'; 2984 Dialog.ExpandButtonCaption := 'File list';
2985 Dialog.ExpandedText := PopupFileList.Text; 2985 Dialog.ExpandedText := PopupFileList.Text;
2986 Dialog.Flags := [tfUseCommandLinks, tfExpandFooterArea]; 2986 Dialog.Flags := [tfUseCommandLinks, tfExpandFooterArea];
2987 Dialog.CommonButtons := []; 2987 Dialog.CommonButtons := [];
2988 Dialog.MainIcon := tdiWarning; 2988 Dialog.MainIcon := tdiWarning;
2989 Btn := TTaskDialogButtonItem(Dialog.Buttons.Add); 2989 Btn := TTaskDialogButtonItem(Dialog.Buttons.Add);
2990 Btn.Caption := 'Run file(s) directly'; 2990 Btn.Caption := 'Run file(s) directly';
2991 Btn.CommandLinkHint := '... without loading into the editor'; 2991 Btn.CommandLinkHint := '... without loading into the editor';
2992 Btn.ModalResult := mrYes; 2992 Btn.ModalResult := mrYes;
2993 Btn := TTaskDialogButtonItem(Dialog.Buttons.Add); 2993 Btn := TTaskDialogButtonItem(Dialog.Buttons.Add);
2994 Btn.Caption := 'Load file(s) into the editor'; 2994 Btn.Caption := 'Load file(s) into the editor';
2995 Btn.CommandLinkHint := 'Can cause large memory usage'; 2995 Btn.CommandLinkHint := 'Can cause large memory usage';
2996 Btn.ModalResult := mrNo; 2996 Btn.ModalResult := mrNo;
2997 Btn := TTaskDialogButtonItem(Dialog.Buttons.Add); 2997 Btn := TTaskDialogButtonItem(Dialog.Buttons.Add);
2998 Btn.Caption := 'Cancel'; 2998 Btn.Caption := 'Cancel';
2999 Btn.ModalResult := mrCancel; 2999 Btn.ModalResult := mrCancel;
3000 Dialog.Execute; 3000 Dialog.Execute;
3001 DialogResult := Dialog.ModalResult; 3001 DialogResult := Dialog.ModalResult;
3002 Dialog.Free; 3002 Dialog.Free;
3003 end else begin 3003 end else begin
3004 msgtext := 'One or more of the selected files are larger than '+FormatByteNumber(RunFileSize, 0)+':' + CRLF + 3004 msgtext := 'One or more of the selected files are larger than '+FormatByteNumber(RunFileSize, 0)+':' + CRLF +
3005 ImplodeStr(CRLF, PopupFileList) + CRLF + CRLF + 3005 ImplodeStr(CRLF, PopupFileList) + CRLF + CRLF +
3006 'Just run these files to avoid loading them into the query-editor (= memory)?' + CRLF + CRLF + 3006 'Just run these files to avoid loading them into the query-editor (= memory)?' + CRLF + CRLF +
3007 'Press' + CRLF + 3007 'Press' + CRLF +
3008 ' [Yes] to run file(s) without loading it into the editor' + CRLF + 3008 ' [Yes] to run file(s) without loading it into the editor' + CRLF +
3009 ' [No] to load file(s) into the query editor' + CRLF + 3009 ' [No] to load file(s) into the query editor' + CRLF +
3010 ' [Cancel] to cancel file opening.'; 3010 ' [Cancel] to cancel file opening.';
3011 DialogResult := MessageDialog('Execute query file(s)?', msgtext, mtWarning, [mbYes, mbNo, mbCancel]); 3011 DialogResult := MessageDialog('Execute query file(s)?', msgtext, mtWarning, [mbYes, mbNo, mbCancel]);
3012 end; 3012 end;
3013 3013
3014 case DialogResult of 3014 case DialogResult of
3015 mrYes: begin 3015 mrYes: begin
3016 Result := True; 3016 Result := True;
3017 for i:=0 to Filenames.Count-1 do begin 3017 for i:=0 to Filenames.Count-1 do begin
3018 RunFileDialog := TRunSQLFileForm.Create(Self); 3018 RunFileDialog := TRunSQLFileForm.Create(Self);
3019 RunFileDialog.SQLFileName := Filenames[i]; 3019 RunFileDialog.SQLFileName := Filenames[i];
3020 RunFileDialog.FileEncoding := Encoding; 3020 RunFileDialog.FileEncoding := Encoding;
3021 RunFileDialog.ShowModal; 3021 RunFileDialog.ShowModal;
3022 RunFileDialog.Free; 3022 RunFileDialog.Free;
3023 // Add filename to history menu 3023 // Add filename to history menu
3024 if Pos(MainForm.FDirnameSnippets, Filenames[i]) = 0 then 3024 if Pos(MainForm.FDirnameSnippets, Filenames[i]) = 0 then
3025 MainForm.AddOrRemoveFromQueryLoadHistory(Filenames[i], True, True); 3025 MainForm.AddOrRemoveFromQueryLoadHistory(Filenames[i], True, True);
3026 end; 3026 end;
3027 end; 3027 end;
3028 mrNo: Result := False; 3028 mrNo: Result := False;
3029 mrCancel: Result := True; 3029 mrCancel: Result := True;
3030 end; 3030 end;
3031 end; 3031 end;
3032 3032
3033 if AbsentFiles.Count > 0 then 3033 if AbsentFiles.Count > 0 then
3034 ErrorDialog('Could not load file(s):', AbsentFiles.Text); 3034 ErrorDialog('Could not load file(s):', AbsentFiles.Text);
3035 AbsentFiles.Free; 3035 AbsentFiles.Free;
3036 PopupFileList.Free; 3036 PopupFileList.Free;
3037 end; 3037 end;
3038 {$WARN SYMBOL_PLATFORM ON} 3038 {$WARN SYMBOL_PLATFORM ON}
3039 3039
3040 3040
3041 procedure TMainForm.SessionConnect(Sender: TObject); 3041 procedure TMainForm.SessionConnect(Sender: TObject);
3042 var 3042 var
3043 Session: String; 3043 Session: String;
3044 Connection: TDBConnection; 3044 Connection: TDBConnection;
3045 Params: TConnectionParameters; 3045 Params: TConnectionParameters;
3046 Node, SessionNode: PVirtualNode; 3046 Node, SessionNode: PVirtualNode;
3047 DBObj: PDBObject; 3047 DBObj: PDBObject;
3048 i: Integer; 3048 i: Integer;
3049 begin 3049 begin
3050 // Click on quick-session menu item: 3050 // Click on quick-session menu item:
3051 Session := (Sender as TMenuItem).Caption; 3051 Session := (Sender as TMenuItem).Caption;
3052 Node := nil; 3052 Node := nil;
3053 // Probably wanted session was clicked before: navigate to last node 3053 // Probably wanted session was clicked before: navigate to last node
3054 for i:=High(FTreeClickHistory) downto Low(FTreeClickHistory) do begin 3054 for i:=High(FTreeClickHistory) downto Low(FTreeClickHistory) do begin
3055 if FTreeClickHistory[i] <> nil then begin 3055 if FTreeClickHistory[i] <> nil then begin
3056 DBObj := DBtree.GetNodeData(FTreeClickHistory[i]); 3056 DBObj := DBtree.GetNodeData(FTreeClickHistory[i]);
3057 if DBObj.Connection.Parameters.SessionName = Session then begin 3057 if DBObj.Connection.Parameters.SessionName = Session then begin
3058 Node := FTreeClickHistory[i]; 3058 Node := FTreeClickHistory[i];
3059 break; 3059 break;
3060 end; 3060 end;
3061 end; 3061 end;
3062 end; 3062 end;
3063 if not Assigned(Node) then begin 3063 if not Assigned(Node) then begin
3064 // Wanted session was not clicked yet but probably connected: navigate to root node 3064 // Wanted session was not clicked yet but probably connected: navigate to root node
3065 SessionNode := DBtree.GetFirstChild(nil); 3065 SessionNode := DBtree.GetFirstChild(nil);
3066 while Assigned(SessionNode) do begin 3066 while Assigned(SessionNode) do begin
3067 DBObj := DBtree.GetNodeData(SessionNode); 3067 DBObj := DBtree.GetNodeData(SessionNode);
3068 if DBObj.Connection.Parameters.SessionName = Session then begin 3068 if DBObj.Connection.Parameters.SessionName = Session then begin
3069 Node := SessionNode; 3069 Node := SessionNode;
3070 end; 3070 end;
3071 SessionNode := DBtree.GetNextSibling(SessionNode); 3071 SessionNode := DBtree.GetNextSibling(SessionNode);
3072 end; 3072 end;
3073 end; 3073 end;
3074 // Finally we have a node if session is already connected 3074 // Finally we have a node if session is already connected
3075 if Assigned(Node) then 3075 if Assigned(Node) then
3076 SelectNode(DBtree, Node) 3076 SelectNode(DBtree, Node)
3077 else begin 3077 else begin
3078 Params := TConnectionParameters.ReadFromRegistry(Session); 3078 Params := TConnectionParameters.ReadFromRegistry(Session);
3079 InitConnection(Params, True, Connection); 3079 InitConnection(Params, True, Connection);
3080 end; 3080 end;
3081 end; 3081 end;
3082 3082
3083 3083
3084 {** 3084 {**
3085 Receive connection parameters and create a connection tree node 3085 Receive connection parameters and create a connection tree node
3086 Paremeters are either sent by connection-form or by commandline. 3086 Paremeters are either sent by connection-form or by commandline.
3087 } 3087 }
3088 function TMainform.InitConnection(Params: TConnectionParameters; ActivateMe: Boolean; var Connection: TDBConnection): Boolean; 3088 function TMainform.InitConnection(Params: TConnectionParameters; ActivateMe: Boolean; var Connection: TDBConnection): Boolean;
3089 var 3089 var
3090 SessionExists, RestoreLastActiveDatabase: Boolean; 3090 SessionExists, RestoreLastActiveDatabase: Boolean;
3091 StartupScript, LastActiveDatabase: String; 3091 StartupScript, LastActiveDatabase: String;
3092 StartupBatch: TSQLBatch; 3092 StartupBatch: TSQLBatch;
3093 Query: TSQLSentence; 3093 Query: TSQLSentence;
3094 SessionNode, DBNode: PVirtualNode; 3094 SessionNode, DBNode: PVirtualNode;
3095 begin 3095 begin
3096 Connection := Params.CreateConnection(Self); 3096 Connection := Params.CreateConnection(Self);
3097 Connection.OnLog := LogSQL; 3097 Connection.OnLog := LogSQL;
3098 Connection.OnConnected := ConnectionReady; 3098 Connection.OnConnected := ConnectionReady;
3099 Connection.OnDBObjectsCleared := DBObjectsCleared; 3099 Connection.OnDBObjectsCleared := DBObjectsCleared;
3100 Connection.OnDatabaseChanged := DatabaseChanged; 3100 Connection.OnDatabaseChanged := DatabaseChanged;
3101 Connection.ObjectNamesInSelectedDB := SynSQLSyn1.TableNames; 3101 Connection.ObjectNamesInSelectedDB := SynSQLSyn1.TableNames;
3102 try 3102 try
3103 Connection.Active := True; 3103 Connection.Active := True;
3104 except 3104 except
3105 on E:EDatabaseError do 3105 on E:EDatabaseError do
3106 ErrorDialog(E.Message); 3106 ErrorDialog(E.Message);
3107 end; 3107 end;
3108 3108
3109 // attempt to establish connection 3109 // attempt to establish connection
3110 SessionExists := MainReg.KeyExists(REGPATH + REGKEY_SESSIONS + Params.SessionName); 3110 SessionExists := MainReg.KeyExists(REGPATH + REGKEY_SESSIONS + Params.SessionName);
3111 if not Connection.Active then begin 3111 if not Connection.Active then begin
3112 // attempt failed 3112 // attempt failed
3113 if SessionExists then begin 3113 if SessionExists then begin
3114 // Save "refused" counter 3114 // Save "refused" counter
3115 OpenRegistry(Params.SessionName); 3115 OpenRegistry(Params.SessionName);
3116 MainReg.WriteInteger(REGNAME_REFUSEDCOUNT, GetRegValue(REGNAME_REFUSEDCOUNT, 0, Params.SessionName)+1); 3116 MainReg.WriteInteger(REGNAME_REFUSEDCOUNT, GetRegValue(REGNAME_REFUSEDCOUNT, 0, Params.SessionName)+1);
3117 end; 3117 end;
3118 Result := False; 3118 Result := False;
3119 FreeAndNil(Connection); 3119 FreeAndNil(Connection);
3120 end else begin 3120 end else begin
3121 // We have a connection 3121 // We have a connection
3122 Result := True; 3122 Result := True;
3123 FConnections.Add(Connection); 3123 FConnections.Add(Connection);
3124 3124
3125 if SessionExists then begin 3125 if SessionExists then begin
3126 // Save "connected" counter 3126 // Save "connected" counter
3127 OpenRegistry(Params.SessionName); 3127 OpenRegistry(Params.SessionName);
3128 MainReg.WriteInteger(REGNAME_CONNECTCOUNT, GetRegValue(REGNAME_CONNECTCOUNT, 0, Params.SessionName)+1); 3128 MainReg.WriteInteger(REGNAME_CONNECTCOUNT, GetRegValue(REGNAME_CONNECTCOUNT, 0, Params.SessionName)+1);
3129 // Save server version 3129 // Save server version
3130 Mainreg.WriteInteger(REGNAME_SERVERVERSION, Connection.ServerVersionInt); 3130 Mainreg.WriteInteger(REGNAME_SERVERVERSION, Connection.ServerVersionInt);
3131 Mainreg.WriteString(REGNAME_LASTCONNECT, DateTimeToStr(Now)); 3131 Mainreg.WriteString(REGNAME_LASTCONNECT, DateTimeToStr(Now));
3132 end; 3132 end;
3133 3133
3134 if ActivateMe then begin 3134 if ActivateMe then begin
3135 // Set focus on last uses db. If not wanted or db is gone, go to root node at least 3135 // Set focus on last uses db. If not wanted or db is gone, go to root node at least
3136 RestoreLastActiveDatabase := GetRegValue(REGNAME_RESTORELASTUSEDDB, DEFAULT_RESTORELASTUSEDDB); 3136 RestoreLastActiveDatabase := GetRegValue(REGNAME_RESTORELASTUSEDDB, DEFAULT_RESTORELASTUSEDDB);
3137 LastActiveDatabase := GetRegValue(REGNAME_LASTUSEDDB, '', Params.SessionName); 3137 LastActiveDatabase := GetRegValue(REGNAME_LASTUSEDDB, '', Params.SessionName);
3138 if RestoreLastActiveDatabase and (Connection.AllDatabases.IndexOf(LastActiveDatabase) >- 1) then begin 3138 if RestoreLastActiveDatabase and (Connection.AllDatabases.IndexOf(LastActiveDatabase) >- 1) then begin
3139 SetActiveDatabase(LastActiveDatabase, Connection); 3139 SetActiveDatabase(LastActiveDatabase, Connection);
3140 DBNode := FindDBNode(DBtree, Connection, LastActiveDatabase); 3140 DBNode := FindDBNode(DBtree, Connection, LastActiveDatabase);
3141 if Assigned(DBNode) then 3141 if Assigned(DBNode) then
3142 DBtree.Expanded[DBNode] := True; 3142 DBtree.Expanded[DBNode] := True;
3143 end else begin 3143 end else begin
3144 SessionNode := GetRootNode(DBtree, Connection); 3144 SessionNode := GetRootNode(DBtree, Connection);
3145 SelectNode(DBtree, SessionNode); 3145 SelectNode(DBtree, SessionNode);
3146 DBtree.Expanded[SessionNode] := True; 3146 DBtree.Expanded[SessionNode] := True;
3147 end; 3147 end;
3148 end; 3148 end;
3149 3149
3150 // Process startup script 3150 // Process startup script
3151 StartupScript := Trim(Connection.Parameters.StartupScriptFilename); 3151 StartupScript := Trim(Connection.Parameters.StartupScriptFilename);
3152 if StartupScript <> '' then begin 3152 if StartupScript <> '' then begin
3153 if not FileExists(StartupScript) then 3153 if not FileExists(StartupScript) then
3154 ErrorDialog('Startup script file not found: '+StartupScript) 3154 ErrorDialog('Startup script file not found: '+StartupScript)
3155 else begin 3155 else begin
3156 StartupBatch := TSQLBatch.Create; 3156 StartupBatch := TSQLBatch.Create;
3157 StartupBatch.SQL := ReadTextfile(StartupScript, nil); 3157 StartupBatch.SQL := ReadTextfile(StartupScript, nil);
3158 for Query in StartupBatch do try 3158 for Query in StartupBatch do try
3159 Connection.Query(Query.SQL); 3159 Connection.Query(Query.SQL);
3160 except 3160 except
3161 // Suppress popup, errors get logged into SQL log 3161 // Suppress popup, errors get logged into SQL log
3162 end; 3162 end;
3163 StartupBatch.Free; 3163 StartupBatch.Free;
3164 end; 3164 end;
3165 end; 3165 end;
3166 3166
3167 if Params.WantSSL and not Connection.IsSSL then begin 3167 if Params.WantSSL and not Connection.IsSSL then begin
3168 MessageDialog('SSL not used.', 3168 MessageDialog('SSL not used.',
3169 'Your SSL settings were not accepted by the server, or the server does not support any SSL configuration.', 3169 'Your SSL settings were not accepted by the server, or the server does not support any SSL configuration.',
3170 mtWarning, 3170 mtWarning,
3171 [mbOK] 3171 [mbOK]
3172 ); 3172 );
3173 end; 3173 end;
3174 3174
3175 end; 3175 end;
3176 ShowStatusMsg; 3176 ShowStatusMsg;
3177 end; 3177 end;
3178 3178
3179 3179
3180 procedure TMainForm.actDataDeleteExecute(Sender: TObject); 3180 procedure TMainForm.actDataDeleteExecute(Sender: TObject);
3181 var 3181 var
3182 Grid: TVirtualStringTree; 3182 Grid: TVirtualStringTree;
3183 Node, FocusAfterDelete: PVirtualNode; 3183 Node, FocusAfterDelete: PVirtualNode;
3184 RowNum: PCardinal; 3184 RowNum: PCardinal;
3185 Results: TDBQuery; 3185 Results: TDBQuery;
3186 Nodes: TNodeArray; 3186 Nodes: TNodeArray;
3187 i: Integer; 3187 i: Integer;
3188 begin 3188 begin
3189 // Delete row(s) 3189 // Delete row(s)
3190 Grid := ActiveGrid; 3190 Grid := ActiveGrid;
3191 Results := GridResult(Grid); 3191 Results := GridResult(Grid);
3192 if Grid.SelectedCount = 0 then 3192 if Grid.SelectedCount = 0 then
3193 ErrorDialog('No rows selected', 'Please select one or more rows to delete them.') 3193 ErrorDialog('No rows selected', 'Please select one or more rows to delete them.')
3194 else try 3194 else try
3195 Results.CheckEditable; 3195 Results.CheckEditable;
3196 if MessageDialog('Delete '+IntToStr(Grid.SelectedCount)+' row(s)?', 3196 if MessageDialog('Delete '+IntToStr(Grid.SelectedCount)+' row(s)?',
3197 mtConfirmation, [mbOK, mbCancel]) = mrOK then begin 3197 mtConfirmation, [mbOK, mbCancel]) = mrOK then begin
3198 FocusAfterDelete := nil; 3198 FocusAfterDelete := nil;
3199 EnableProgress(Grid.SelectedCount); 3199 EnableProgress(Grid.SelectedCount);
3200 Node := GetNextNode(Grid, nil, True); 3200 Node := GetNextNode(Grid, nil, True);
3201 while Assigned(Node) do begin 3201 while Assigned(Node) do begin
3202 RowNum := Grid.GetNodeData(Node); 3202 RowNum := Grid.GetNodeData(Node);
3203 ShowStatusMsg('Deleting row #'+FormatNumber(ProgressBarStatus.Position+1)+' of '+FormatNumber(ProgressBarStatus.Max)+' ...'); 3203 ShowStatusMsg('Deleting row #'+FormatNumber(ProgressBarStatus.Position+1)+' of '+FormatNumber(ProgressBarStatus.Max)+' ...');
3204 Results.RecNo := RowNum^; 3204 Results.RecNo := RowNum^;
3205 Results.DeleteRow; 3205 Results.DeleteRow;
3206 ProgressStep; 3206 ProgressStep;
3207 SetLength(Nodes, Length(Nodes)+1); 3207 SetLength(Nodes, Length(Nodes)+1);
3208 Nodes[Length(Nodes)-1] := Node; 3208 Nodes[Length(Nodes)-1] := Node;
3209 FocusAfterDelete := Node; 3209 FocusAfterDelete := Node;
3210 Node := GetNextNode(Grid, Node, True); 3210 Node := GetNextNode(Grid, Node, True);
3211 end; 3211 end;
3212 ShowStatusMsg('Clean up ...'); 3212 ShowStatusMsg('Clean up ...');
3213 if Assigned(FocusAfterDelete) then 3213 if Assigned(FocusAfterDelete) then
3214 FocusAfterDelete := Grid.GetNext(FocusAfterDelete); 3214 FocusAfterDelete := Grid.GetNext(FocusAfterDelete);
3215 // Remove nodes and select some nearby node 3215 // Remove nodes and select some nearby node
3216 Grid.BeginUpdate; 3216 Grid.BeginUpdate;
3217 for i:=Low(Nodes) to High(Nodes) do 3217 for i:=Low(Nodes) to High(Nodes) do
3218 Grid.DeleteNode(Nodes[i]); 3218 Grid.DeleteNode(Nodes[i]);
3219 Grid.EndUpdate; 3219 Grid.EndUpdate;
3220 if not Assigned(FocusAfterDelete) then 3220 if not Assigned(FocusAfterDelete) then
3221 FocusAfterDelete := Grid.GetLast; 3221 FocusAfterDelete := Grid.GetLast;
3222 if Assigned(FocusAfterDelete) then 3222 if Assigned(FocusAfterDelete) then
3223 SelectNode(Grid, FocusAfterDelete); 3223 SelectNode(Grid, FocusAfterDelete);
3224 DisplayRowCountStats(Grid); 3224 DisplayRowCountStats(Grid);
3225 ValidateControls(Sender); 3225 ValidateControls(Sender);
3226 end; 3226 end;
3227 except on E:EDatabaseError do begin 3227 except on E:EDatabaseError do begin
3228 SetProgressState(pbsError); 3228 SetProgressState(pbsError);
3229 ErrorDialog('Grid editing error', E.Message); 3229 ErrorDialog('Grid editing error', E.Message);
3230 end; 3230 end;
3231 end; 3231 end;
3232 DisableProgress; 3232 DisableProgress;
3233 ShowStatusMsg(); 3233 ShowStatusMsg();
3234 end; 3234 end;
3235 3235
3236 3236
3237 procedure TMainForm.actUpdateCheckExecute(Sender: TObject); 3237 procedure TMainForm.actUpdateCheckExecute(Sender: TObject);
3238 var 3238 var
3239 frm : TfrmUpdateCheck; 3239 frm : TfrmUpdateCheck;
3240 begin 3240 begin
3241 frm := TfrmUpdateCheck.Create(Self); 3241 frm := TfrmUpdateCheck.Create(Self);
3242 frm.ShowModal; 3242 frm.ShowModal;
3243 FreeAndNil(frm); 3243 FreeAndNil(frm);
3244 end; 3244 end;
3245 3245
3246 3246
3247 procedure TMainForm.actCreateDBObjectExecute(Sender: TObject); 3247 procedure TMainForm.actCreateDBObjectExecute(Sender: TObject);
3248 var 3248 var
3249 Obj: TDBObject; 3249 Obj: TDBObject;
3250 a: TAction; 3250 a: TAction;
3251 begin 3251 begin
3252 // Create a new table, view, etc. 3252 // Create a new table, view, etc.
3253 tabEditor.TabVisible := True; 3253 tabEditor.TabVisible := True;
3254 SetMainTab(tabEditor); 3254 SetMainTab(tabEditor);
3255 a := Sender as TAction; 3255 a := Sender as TAction;
3256 Obj := TDBObject.Create(ActiveConnection); 3256 Obj := TDBObject.Create(ActiveConnection);
3257 Obj.Database := ActiveDatabase; 3257 Obj.Database := ActiveDatabase;
3258 if a = actCreateTable then Obj.NodeType := lntTable 3258 if a = actCreateTable then Obj.NodeType := lntTable
3259 else if a = actCreateView then Obj.NodeType := lntView 3259 else if a = actCreateView then Obj.NodeType := lntView
3260 else if a = actCreateRoutine then Obj.NodeType := lntProcedure 3260 else if a = actCreateRoutine then Obj.NodeType := lntProcedure
3261 else if a = actCreateTrigger then Obj.NodeType := lntTrigger 3261 else if a = actCreateTrigger then Obj.NodeType := lntTrigger
3262 else if a = actCreateEvent then Obj.NodeType := lntEvent; 3262 else if a = actCreateEvent then Obj.NodeType := lntEvent;
3263 PlaceObjectEditor(Obj); 3263 PlaceObjectEditor(Obj);
3264 end; 3264 end;
3265 3265
3266 3266
3267 procedure TMainForm.actEmptyTablesExecute(Sender: TObject); 3267 procedure TMainForm.actEmptyTablesExecute(Sender: TObject);
3268 var 3268 var
3269 Node: PVirtualNode; 3269 Node: PVirtualNode;
3270 Obj: PDBObject; 3270 Obj: PDBObject;
3271 TableOrView: TDBObject; 3271 TableOrView: TDBObject;
3272 Objects: TDBObjectList; 3272 Objects: TDBObjectList;
3273 Names: String; 3273 Names: String;
3274 begin 3274 begin
3275 // Add selected items/tables to helper list 3275 // Add selected items/tables to helper list
3276 Objects := TDBObjectList.Create(False); 3276 Objects := TDBObjectList.Create(False);
3277 if ListTables.Focused then begin 3277 if ListTables.Focused then begin
3278 Node := GetNextNode(ListTables, nil, True); 3278 Node := GetNextNode(ListTables, nil, True);
3279 while Assigned(Node) do begin 3279 while Assigned(Node) do begin
3280 Obj := ListTables.GetNodeData(Node); 3280 Obj := ListTables.GetNodeData(Node);
3281 if Obj.NodeType in [lntTable, lntView] then begin 3281 if Obj.NodeType in [lntTable, lntView] then begin
3282 Objects.Add(Obj^); 3282 Objects.Add(Obj^);
3283 Names := Names + Obj.Name + ', '; 3283 Names := Names + Obj.Name + ', ';
3284 end; 3284 end;
3285 Node := GetNextNode(ListTables, Node, True); 3285 Node := GetNextNode(ListTables, Node, True);
3286 end; 3286 end;
3287 Delete(Names, Length(Names)-1, 2); 3287 Delete(Names, Length(Names)-1, 2);
3288 end else if DBTree.Focused then begin 3288 end else if DBTree.Focused then begin
3289 Objects.Add(ActiveDbObj); 3289 Objects.Add(ActiveDbObj);
3290 Names := ActiveDbObj.Name; 3290 Names := ActiveDbObj.Name;
3291 end; 3291 end;
3292 if Objects.Count = 0 then 3292 if Objects.Count = 0 then
3293 ErrorDialog('No table(s) selected.') 3293 ErrorDialog('No table(s) selected.')
3294 else begin 3294 else begin
3295 if MessageDialog('Empty '+IntToStr(Objects.count)+' table(s) and/or view(s) ?', Names, 3295 if MessageDialog('Empty '+IntToStr(Objects.count)+' table(s) and/or view(s) ?', Names,
3296 mtConfirmation, [mbOk, mbCancel]) = mrOk then begin 3296 mtConfirmation, [mbOk, mbCancel]) = mrOk then begin
3297 Screen.Cursor := crHourglass; 3297 Screen.Cursor := crHourglass;
3298 EnableProgress(Objects.Count); 3298 EnableProgress(Objects.Count);
3299 try 3299 try
3300 for TableOrView in Objects do begin 3300 for TableOrView in Objects do begin
3301 case TableOrView.Connection.Parameters.NetTypeGroup of 3301 TableOrView.Connection.Query(TableOrView.Connection.GetSQLSpecifity(spEmptyTable) + TableOrView.QuotedName);
3302 ngMySQL: TableOrView.Connection.Query('TRUNCATE ' + TableOrView.QuotedName);
3303 ngMSSQL: TableOrView.Connection.Query('DELETE FROM ' + TableOrView.QuotedName);
3304 end;
3305 ProgressStep; 3302 ProgressStep;
3306 end; 3303 end;
3307 actRefresh.Execute; 3304 actRefresh.Execute;
3308 except 3305 except
3309 on E:EDatabaseError do begin 3306 on E:EDatabaseError do begin
3310 SetProgressState(pbsError); 3307 SetProgressState(pbsError);
3311 ErrorDialog(E.Message); 3308 ErrorDialog(E.Message);
3312 end; 3309 end;
3313 end; 3310 end;
3314 Objects.Free; 3311 Objects.Free;
3315 DisableProgress; 3312 DisableProgress;
3316 Screen.Cursor := crDefault; 3313 Screen.Cursor := crDefault;
3317 end; 3314 end;
3318 end; 3315 end;
3319 end; 3316 end;
3320 3317
3321 3318
3322 procedure TMainForm.actBatchInOneGoExecute(Sender: TObject); 3319 procedure TMainForm.actBatchInOneGoExecute(Sender: TObject);
3323 begin 3320 begin
3324 // 3321 //
3325 end; 3322 end;
3326 3323
3327 procedure TMainForm.actRunRoutinesExecute(Sender: TObject); 3324 procedure TMainForm.actRunRoutinesExecute(Sender: TObject);
3328 var 3325 var
3329 Tab: TQueryTab; 3326 Tab: TQueryTab;
3330 Query, ParamValues, ParamValue, DummyStr: String; 3327 Query, ParamValues, ParamValue, DummyStr: String;
3331 Params: TStringList; 3328 Params: TStringList;
3332 DummyBool: Boolean; 3329 DummyBool: Boolean;
3333 pObj: PDBObject; 3330 pObj: PDBObject;
3334 Obj: TDBObject; 3331 Obj: TDBObject;
3335 Objects: TDBObjectList; 3332 Objects: TDBObjectList;
3336 Node: PVirtualNode; 3333 Node: PVirtualNode;
3337 Parameters: TRoutineParamList; 3334 Parameters: TRoutineParamList;
3338 Param: TRoutineParam; 3335 Param: TRoutineParam;
3339 begin 3336 begin
3340 // Run stored function(s) or procedure(s) 3337 // Run stored function(s) or procedure(s)
3341 Objects := TDBObjectList.Create(False); 3338 Objects := TDBObjectList.Create(False);
3342 if ListTables.Focused then begin 3339 if ListTables.Focused then begin
3343 Node := GetNextNode(ListTables, nil, True); 3340 Node := GetNextNode(ListTables, nil, True);
3344 while Assigned(Node) do begin 3341 while Assigned(Node) do begin
3345 pObj := ListTables.GetNodeData(Node); 3342 pObj := ListTables.GetNodeData(Node);
3346 if pObj.NodeType in [lntProcedure, lntFunction] then 3343 if pObj.NodeType in [lntProcedure, lntFunction] then
3347 Objects.Add(pObj^); 3344 Objects.Add(pObj^);
3348 Node := GetNextNode(ListTables, Node, True); 3345 Node := GetNextNode(ListTables, Node, True);
3349 end; 3346 end;
3350 end else 3347 end else
3351 Objects.Add(ActiveDbObj); 3348 Objects.Add(ActiveDbObj);
3352 3349
3353 if Objects.Count = 0 then 3350 if Objects.Count = 0 then
3354 ErrorDialog('No stored procedure selected.', 'Please select one or more stored function(s) or routine(s).'); 3351 ErrorDialog('No stored procedure selected.', 'Please select one or more stored function(s) or routine(s).');
3355 3352
3356 for Obj in Objects do begin 3353 for Obj in Objects do begin
3357 actNewQueryTab.Execute; 3354 actNewQueryTab.Execute;
3358 Tab := QueryTabs[MainForm.QueryTabs.Count-1]; 3355 Tab := QueryTabs[MainForm.QueryTabs.Count-1];
3359 case Obj.Connection.Parameters.NetTypeGroup of 3356 case Obj.Connection.Parameters.NetTypeGroup of
3360 ngMySQL: 3357 ngMySQL:
3361 case Obj.NodeType of 3358 case Obj.NodeType of
3362 lntProcedure: Query := 'CALL '; 3359 lntProcedure: Query := 'CALL ';
3363 lntFunction: Query := 'SELECT '; 3360 lntFunction: Query := 'SELECT ';
3364 end; 3361 end;
3365 ngMSSQL: 3362 ngMSSQL:
3366 Query := 'EXEC '; 3363 Query := 'EXEC ';
3367 end; 3364 end;
3368 Parameters := TRoutineParamList.Create; 3365 Parameters := TRoutineParamList.Create;
3369 Obj.Connection.ParseRoutineStructure(Obj.CreateCode, Parameters, DummyBool, DummyStr, DummyStr, DummyStr, DummyStr, DummyStr, DummyStr); 3366 Obj.Connection.ParseRoutineStructure(Obj.CreateCode, Parameters, DummyBool, DummyStr, DummyStr, DummyStr, DummyStr, DummyStr, DummyStr);
3370 Query := Query + Obj.QuotedName; 3367 Query := Query + Obj.QuotedName;
3371 Params := TStringList.Create; 3368 Params := TStringList.Create;
3372 for Param in Parameters do begin 3369 for Param in Parameters do begin
3373 ParamValue := InputBox(Obj.Name, 'Parameter "'+Param.Name+'" ('+Param.Datatype+')', ''); 3370 ParamValue := InputBox(Obj.Name, 'Parameter "'+Param.Name+'" ('+Param.Datatype+')', '');
3374 ParamValue := Obj.Connection.EscapeString(ParamValue); 3371 ParamValue := Obj.Connection.EscapeString(ParamValue);
3375 Params.Add(ParamValue); 3372 Params.Add(ParamValue);
3376 end; 3373 end;
3377 Parameters.Free; 3374 Parameters.Free;
3378 ParamValues := ''; 3375 ParamValues := '';
3379 case Obj.Connection.Parameters.NetTypeGroup of 3376 case Obj.Connection.Parameters.NetTypeGroup of
3380 ngMySQL: 3377 ngMySQL:
3381 ParamValues := '(' + ImplodeStr(', ', Params) + ')'; 3378 ParamValues := '(' + ImplodeStr(', ', Params) + ')';
3382 ngMSSQL: 3379 ngMSSQL:
3383 ParamValues := ' ' + ImplodeStr(' ', Params); 3380 ParamValues := ' ' + ImplodeStr(' ', Params);
3384 end; 3381 end;
3385 Query := Query + ParamValues; 3382 Query := Query + ParamValues;
3386 Tab.Memo.Text := Query; 3383 Tab.Memo.Text := Query;
3387 actExecuteQueryExecute(Sender); 3384 actExecuteQueryExecute(Sender);
3388 end; 3385 end;
3389 end; 3386 end;
3390 3387
3391 3388
3392 procedure TMainForm.actNewWindowExecute(Sender: TObject); 3389 procedure TMainForm.actNewWindowExecute(Sender: TObject);
3393 begin 3390 begin
3394 ShellExec( ExtractFileName(paramstr(0)), ExtractFilePath(paramstr(0)) ); 3391 ShellExec( ExtractFileName(paramstr(0)), ExtractFilePath(paramstr(0)) );
3395 end; 3392 end;
3396 3393
3397 3394
3398 procedure TMainForm.actQueryFindReplaceExecute(Sender: TObject); 3395 procedure TMainForm.actQueryFindReplaceExecute(Sender: TObject);
3399 var 3396 var
3400 DlgResult: TModalResult; 3397 DlgResult: TModalResult;
3401 Memo: TSynMemo; 3398 Memo: TSynMemo;
3402 begin 3399 begin
3403 // Display search + replace dialog 3400 // Display search + replace dialog
3404 Memo := ActiveSynMemo; 3401 Memo := ActiveSynMemo;
3405 if Memo = nil then 3402 if Memo = nil then
3406 MessageBeep(MB_ICONASTERISK) 3403 MessageBeep(MB_ICONASTERISK)
3407 else begin 3404 else begin
3408 if not Assigned(FSearchReplaceDialog) then 3405 if not Assigned(FSearchReplaceDialog) then
3409 FSearchReplaceDialog := TfrmSearchReplace.Create(Self); 3406 FSearchReplaceDialog := TfrmSearchReplace.Create(Self);
3410 FSearchReplaceDialog.Editor := Memo; 3407 FSearchReplaceDialog.Editor := Memo;
3411 FSearchReplaceDialog.chkReplace.Checked := Sender = actQueryReplace; 3408 FSearchReplaceDialog.chkReplace.Checked := Sender = actQueryReplace;
3412 DlgResult := FSearchReplaceDialog.ShowModal; 3409 DlgResult := FSearchReplaceDialog.ShowModal;
3413 case DlgResult of 3410 case DlgResult of
3414 mrOK, mrAll: begin 3411 mrOK, mrAll: begin
3415 DoSearchReplace; 3412 DoSearchReplace;
3416 FSearchReplaceExecuted := True; // Helper for later F3 hits 3413 FSearchReplaceExecuted := True; // Helper for later F3 hits
3417 end; 3414 end;
3418 mrCancel: Exit; 3415 mrCancel: Exit;
3419 end; 3416 end;
3420 end; 3417 end;
3421 end; 3418 end;
3422 3419
3423 3420
3424 procedure TMainForm.actQueryFindAgainExecute(Sender: TObject); 3421 procedure TMainForm.actQueryFindAgainExecute(Sender: TObject);
3425 begin 3422 begin
3426 // F3 - search or replace again, using previous settings 3423 // F3 - search or replace again, using previous settings
3427 if not FSearchReplaceExecuted then 3424 if not FSearchReplaceExecuted then
3428 actQueryFindReplaceExecute(Sender) 3425 actQueryFindReplaceExecute(Sender)
3429 else begin 3426 else begin
3430 FSearchReplaceDialog.Editor := ActiveSynMemo; 3427 FSearchReplaceDialog.Editor := ActiveSynMemo;
3431 if FSearchReplaceDialog.Editor = nil then 3428 if FSearchReplaceDialog.Editor = nil then
3432 MessageBeep(MB_ICONASTERISK) 3429 MessageBeep(MB_ICONASTERISK)
3433 else 3430 else
3434 DoSearchReplace; 3431 DoSearchReplace;
3435 end; 3432 end;
3436 end; 3433 end;
3437 3434
3438 3435
3439 procedure TMainForm.DoSearchReplace; 3436 procedure TMainForm.DoSearchReplace;
3440 var 3437 var
3441 Occurences: Integer; 3438 Occurences: Integer;
3442 OldCaretXY: TBufferCoord; 3439 OldCaretXY: TBufferCoord;
3443 Replacement: String; 3440 Replacement: String;
3444 begin 3441 begin
3445 if FSearchReplaceDialog.chkRegularExpression.Checked then 3442 if FSearchReplaceDialog.chkRegularExpression.Checked then
3446 FSearchReplaceDialog.Editor.SearchEngine := SynEditRegexSearch1 3443 FSearchReplaceDialog.Editor.SearchEngine := SynEditRegexSearch1
3447 else 3444 else
3448 FSearchReplaceDialog.Editor.SearchEngine := SynEditSearch1; 3445 FSearchReplaceDialog.Editor.SearchEngine := SynEditSearch1;
3449 3446
3450 OldCaretXY := FSearchReplaceDialog.Editor.CaretXY; 3447 OldCaretXY := FSearchReplaceDialog.Editor.CaretXY;
3451 Replacement := FSearchReplaceDialog.comboReplace.Text; 3448 Replacement := FSearchReplaceDialog.comboReplace.Text;
3452 Replacement := StringReplace(Replacement, '\n', CRLF, [rfReplaceAll]); 3449 Replacement := StringReplace(Replacement, '\n', CRLF, [rfReplaceAll]);
3453 Replacement := StringReplace(Replacement, '\t', #9, [rfReplaceAll]); 3450 Replacement := StringReplace(Replacement, '\t', #9, [rfReplaceAll]);
3454 3451
3455 FSearchReplaceDialog.Editor.BeginUpdate; 3452 FSearchReplaceDialog.Editor.BeginUpdate;
3456 3453
3457 ShowStatusMsg('Searching ...'); 3454 ShowStatusMsg('Searching ...');
3458 Occurences := FSearchReplaceDialog.Editor.SearchReplace( 3455 Occurences := FSearchReplaceDialog.Editor.SearchReplace(
3459 FSearchReplaceDialog.comboSearch.Text, 3456 FSearchReplaceDialog.comboSearch.Text,
3460 Replacement, 3457 Replacement,
3461 FSearchReplaceDialog.Options 3458 FSearchReplaceDialog.Options
3462 ); 3459 );
3463 3460
3464 FSearchReplaceDialog.Editor.EndUpdate; 3461 FSearchReplaceDialog.Editor.EndUpdate;
3465 ShowStatusMsg; 3462 ShowStatusMsg;
3466 3463
3467 if ssoReplaceAll in FSearchReplaceDialog.Options then 3464 if ssoReplaceAll in FSearchReplaceDialog.Options then
3468 ShowStatusMsg('Text "'+FSearchReplaceDialog.comboSearch.Text+'" '+FormatNumber(Occurences)+' times replaced.', 0) 3465 ShowStatusMsg('Text "'+FSearchReplaceDialog.comboSearch.Text+'" '+FormatNumber(Occurences)+' times replaced.', 0)
3469 else begin 3466 else begin
3470 if (OldCaretXY.Char = FSearchReplaceDialog.Editor.CaretXY.Char) and 3467 if (OldCaretXY.Char = FSearchReplaceDialog.Editor.CaretXY.Char) and
3471 (OldCaretXY.Line = FSearchReplaceDialog.Editor.CaretXY.Line) then 3468 (OldCaretXY.Line = FSearchReplaceDialog.Editor.CaretXY.Line) then
3472 MessageDialog('Text "'+FSearchReplaceDialog.comboSearch.Text+'" not found.', mtInformation, [mbOk]); 3469 MessageDialog('Text "'+FSearchReplaceDialog.comboSearch.Text+'" not found.', mtInformation, [mbOk]);
3473 end; 3470 end;
3474 end; 3471 end;
3475 3472
3476 3473
3477 procedure TMainForm.SynMemoQueryReplaceText(Sender: TObject; const ASearch, 3474 procedure TMainForm.SynMemoQueryReplaceText(Sender: TObject; const ASearch,
3478 AReplace: string; Line, Column: Integer; var Action: TSynReplaceAction); 3475 AReplace: string; Line, Column: Integer; var Action: TSynReplaceAction);
3479 begin 3476 begin
3480 // Fires when "Replace all" in search dialog was pressed with activated "Prompt on replace" 3477 // Fires when "Replace all" in search dialog was pressed with activated "Prompt on replace"
3481 case MessageDialog('Replace this occurrence of "'+sstr(ASearch, 100)+'"?', mtConfirmation, [mbYes, mbYesToAll, mbNo, mbCancel]) of 3478 case MessageDialog('Replace this occurrence of "'+sstr(ASearch, 100)+'"?', mtConfirmation, [mbYes, mbYesToAll, mbNo, mbCancel]) of
3482 mrYes: Action := raReplace; 3479 mrYes: Action := raReplace;
3483 mrYesToAll: Action := raReplaceAll; 3480 mrYesToAll: Action := raReplaceAll;
3484 mrNo: Action := raSkip; 3481 mrNo: Action := raSkip;
3485 mrCancel: Action := raCancel; 3482 mrCancel: Action := raCancel;
3486 end; 3483 end;
3487 end; 3484 end;
3488 3485
3489 3486
3490 procedure TMainForm.actRefreshExecute(Sender: TObject); 3487 procedure TMainForm.actRefreshExecute(Sender: TObject);
3491 var 3488 var
3492 tab1, tab2: TTabSheet; 3489 tab1, tab2: TTabSheet;
3493 List: TVirtualStringTree; 3490 List: TVirtualStringTree;
3494 OldDbObject: TDBObject; 3491 OldDbObject: TDBObject;
3495 begin 3492 begin
3496 // Refresh 3493 // Refresh
3497 // Force data tab update when appropriate. 3494 // Force data tab update when appropriate.
3498 tab1 := PageControlMain.ActivePage; 3495 tab1 := PageControlMain.ActivePage;
3499 if ActiveControl = DBtree then 3496 if ActiveControl = DBtree then
3500 RefreshTree 3497 RefreshTree
3501 else if tab1 = tabHost then begin 3498 else if tab1 = tabHost then begin
3502 tab2 := PageControlHost.ActivePage; 3499 tab2 := PageControlHost.ActivePage;
3503 if tab2 = tabDatabases then 3500 if tab2 = tabDatabases then
3504 List := ListDatabases 3501 List := ListDatabases
3505 else if tab2 = tabVariables then 3502 else if tab2 = tabVariables then
3506 List := ListVariables 3503 List := ListVariables
3507 else if tab2 = tabStatus then 3504 else if tab2 = tabStatus then
3508 List := ListStatus 3505 List := ListStatus
3509 else if tab2 = tabProcessList then 3506 else if tab2 = tabProcessList then
3510 List := ListProcesses 3507 List := ListProcesses
3511 else 3508 else
3512 List := ListCommandStats; 3509 List := ListCommandStats;
3513 InvalidateVT(List, VTREE_NOTLOADED_PURGECACHE, True); 3510 InvalidateVT(List, VTREE_NOTLOADED_PURGECACHE, True);
3514 end else if tab1 = tabDatabase then begin 3511 end else if tab1 = tabDatabase then begin
3515 OldDbObject := TDBObject.Create(FActiveDbObj.Connection); 3512 OldDbObject := TDBObject.Create(FActiveDbObj.Connection);
3516 OldDbObject.Assign(FActiveDbObj); 3513 OldDbObject.Assign(FActiveDbObj);
3517 RefreshTree(OldDbObject); 3514 RefreshTree(OldDbObject);
3518 end else if tab1 = tabData then 3515 end else if tab1 = tabData then
3519 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False); 3516 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False);
3520 end; 3517 end;
3521 3518
3522 3519
3523 procedure TMainForm.actSQLhelpExecute(Sender: TObject); 3520 procedure TMainForm.actSQLhelpExecute(Sender: TObject);
3524 var 3521 var
3525 keyword: String; 3522 keyword: String;
3526 Tree: TVirtualStringTree; 3523 Tree: TVirtualStringTree;
3527 begin 3524 begin
3528 // Call SQL Help from various places 3525 // Call SQL Help from various places
3529 keyword := ''; 3526 keyword := '';
3530 3527
3531 // Query-Tab 3528 // Query-Tab
3532 if ActiveControl is TSynMemo then 3529 if ActiveControl is TSynMemo then
3533 keyword := TSynMemo(ActiveControl).WordAtCursor 3530 keyword := TSynMemo(ActiveControl).WordAtCursor
3534 3531
3535 // Data-Tab 3532 // Data-Tab
3536 else if (PageControlMain.ActivePage = tabData) 3533 else if (PageControlMain.ActivePage = tabData)
3537 and Assigned(DataGrid.FocusedNode) then begin 3534 and Assigned(DataGrid.FocusedNode) then begin
3538 keyword := SelectedTableColumns[DataGrid.FocusedColumn].DataType.Name; 3535 keyword := SelectedTableColumns[DataGrid.FocusedColumn].DataType.Name;
3539 3536
3540 end else if ActiveControl = ActiveQueryHelpers then begin 3537 end else if ActiveControl = ActiveQueryHelpers then begin
3541 // Makes only sense if one of the nodes "SQL fn" or "SQL kw" was selected 3538 // Makes only sense if one of the nodes "SQL fn" or "SQL kw" was selected
3542 Tree := ActiveQueryHelpers; 3539 Tree := ActiveQueryHelpers;
3543 if Assigned(Tree.FocusedNode) 3540 if Assigned(Tree.FocusedNode)
3544 and (Tree.GetNodeLevel(Tree.FocusedNode)=1) 3541 and (Tree.GetNodeLevel(Tree.FocusedNode)=1)
3545 and (Tree.FocusedNode.Parent.Index in [HELPERNODE_FUNCTIONS, HELPERNODE_KEYWORDS]) then 3542 and (Tree.FocusedNode.Parent.Index in [HELPERNODE_FUNCTIONS, HELPERNODE_KEYWORDS]) then
3546 keyword := Tree.Text[Tree.FocusedNode, 0]; 3543 keyword := Tree.Text[Tree.FocusedNode, 0];
3547 end; 3544 end;
3548 3545
3549 // Clean existing paranthesis, fx: char(64) 3546 // Clean existing paranthesis, fx: char(64)
3550 if Pos( '(', keyword ) > 0 then 3547 if Pos( '(', keyword ) > 0 then
3551 keyword := Copy( keyword, 1, Pos( '(', keyword )-1 ); 3548 keyword := Copy( keyword, 1, Pos( '(', keyword )-1 );
3552 3549
3553 // Show the window 3550 // Show the window
3554 CallSQLHelpWithKeyword( keyword ); 3551 CallSQLHelpWithKeyword( keyword );
3555 end; 3552 end;
3556 3553
3557 3554
3558 procedure TMainForm.actSynchronizeDatabaseExecute(Sender: TObject); 3555 procedure TMainForm.actSynchronizeDatabaseExecute(Sender: TObject);
3559 var 3556 var
3560 SyncForm: TfrmSyncDB; 3557 SyncForm: TfrmSyncDB;
3561 begin 3558 begin
3562 SyncForm := TfrmSyncDB.Create(Self); 3559 SyncForm := TfrmSyncDB.Create(Self);
3563 SyncForm.ShowModal; 3560 SyncForm.ShowModal;
3564 end; 3561 end;
3565 3562
3566 3563
3567 {*** 3564 {***
3568 Show SQL Help window directly using a keyword 3565 Show SQL Help window directly using a keyword
3569 @param String SQL-keyword 3566 @param String SQL-keyword
3570 @see FieldeditForm.btnDatatypeHelp 3567 @see FieldeditForm.btnDatatypeHelp
3571 } 3568 }
3572 procedure TMainform.CallSQLHelpWithKeyword( keyword: String ); 3569 procedure TMainform.CallSQLHelpWithKeyword( keyword: String );
3573 var 3570 var
3574 Dialog: TfrmSQLhelp; 3571 Dialog: TfrmSQLhelp;
3575 begin 3572 begin
3576 if FActiveDbObj.Connection.ServerVersionInt >= 40100 then begin 3573 if FActiveDbObj.Connection.ServerVersionInt >= 40100 then begin
3577 Dialog := TfrmSQLhelp.Create(Self); 3574 Dialog := TfrmSQLhelp.Create(Self);
3578 Dialog.Show; 3575 Dialog.Show;
3579 Dialog.Keyword := keyword; 3576 Dialog.Keyword := keyword;
3580 end else 3577 end else
3581 ErrorDialog('SQL help not available.', 'HELP <keyword> required MySQL 4.1 or newer.'); 3578 ErrorDialog('SQL help not available.', 'HELP <keyword> required MySQL 4.1 or newer.');
3582 end; 3579 end;
3583 3580
3584 3581
3585 procedure TMainForm.actSaveSQLAsExecute(Sender: TObject); 3582 procedure TMainForm.actSaveSQLAsExecute(Sender: TObject);
3586 var 3583 var
3587 i: Integer; 3584 i: Integer;
3588 CanSave: TModalResult; 3585 CanSave: TModalResult;
3589 begin 3586 begin
3590 // Save SQL 3587 // Save SQL
3591 CanSave := mrNo; 3588 CanSave := mrNo;
3592 while (CanSave = mrNo) and SaveDialogSQLFile.Execute do begin 3589 while (CanSave = mrNo) and SaveDialogSQLFile.Execute do begin
3593 // Save complete content or just the selected text, 3590 // Save complete content or just the selected text,
3594 // depending on the tag of calling control 3591 // depending on the tag of calling control
3595 CanSave := mrYes; 3592 CanSave := mrYes;
3596 for i:=0 to QueryTabs.Count-1 do begin 3593 for i:=0 to QueryTabs.Count-1 do begin
3597 if QueryTabs[i].MemoFilename = SaveDialogSQLFile.FileName then begin 3594 if QueryTabs[i].MemoFilename = SaveDialogSQLFile.FileName then begin
3598 CanSave := MessageDialog('Overwrite "'+SaveDialogSQLFile.FileName+'"?', 'This file is already open in query tab #'+IntToStr(QueryTabs[i].Number)+'.', 3595 CanSave := MessageDialog('Overwrite "'+SaveDialogSQLFile.FileName+'"?', 'This file is already open in query tab #'+IntToStr(QueryTabs[i].Number)+'.',
3599 mtWarning, [mbYes, mbNo, mbCancel]); 3596 mtWarning, [mbYes, mbNo, mbCancel]);
3600 break; 3597 break;
3601 end; 3598 end;
3602 end; 3599 end;
3603 end; 3600 end;
3604 if CanSave = mrYes then begin 3601 if CanSave = mrYes then begin
3605 ActiveQueryTab.SaveContents(SaveDialogSQLFile.FileName, (Sender as TAction).Tag = 1); 3602 ActiveQueryTab.SaveContents(SaveDialogSQLFile.FileName, (Sender as TAction).Tag = 1);
3606 for i:=0 to QueryTabs.Count-1 do begin 3603 for i:=0 to QueryTabs.Count-1 do begin
3607 if QueryTabs[i] = ActiveQueryTab then 3604 if QueryTabs[i] = ActiveQueryTab then
3608 continue; 3605 continue;
3609 if QueryTabs[i].MemoFilename = SaveDialogSQLFile.FileName then 3606 if QueryTabs[i].MemoFilename = SaveDialogSQLFile.FileName then
3610 QueryTabs[i].Memo.Modified := True; 3607 QueryTabs[i].Memo.Modified := True;
3611 end; 3608 end;
3612 ValidateQueryControls(Sender); 3609 ValidateQueryControls(Sender);
3613 end; 3610 end;
3614 end; 3611 end;
3615 3612
3616 3613
3617 procedure TMainForm.actSaveSQLExecute(Sender: TObject); 3614 procedure TMainForm.actSaveSQLExecute(Sender: TObject);
3618 var 3615 var
3619 i: Integer; 3616 i: Integer;
3620 begin 3617 begin
3621 if ActiveQueryTab.MemoFilename <> '' then begin 3618 if ActiveQueryTab.MemoFilename <> '' then begin
3622 ActiveQueryTab.SaveContents(ActiveQueryTab.MemoFilename, False); 3619 ActiveQueryTab.SaveContents(ActiveQueryTab.MemoFilename, False);
3623 for i:=0 to QueryTabs.Count-1 do begin 3620 for i:=0 to QueryTabs.Count-1 do begin
3624 if QueryTabs[i] = ActiveQueryTab then 3621 if QueryTabs[i] = ActiveQueryTab then
3625 continue; 3622 continue;
3626 if QueryTabs[i].MemoFilename = ActiveQueryTab.MemoFilename then 3623 if QueryTabs[i].MemoFilename = ActiveQueryTab.MemoFilename then
3627 QueryTabs[i].Memo.Modified := True; 3624 QueryTabs[i].Memo.Modified := True;
3628 end; 3625 end;
3629 ValidateQueryControls(Sender); 3626 ValidateQueryControls(Sender);
3630 end else 3627 end else
3631 actSaveSQLAsExecute(Sender); 3628 actSaveSQLAsExecute(Sender);
3632 end; 3629 end;
3633 3630
3634 3631
3635 procedure TMainForm.actSaveSQLSnippetExecute(Sender: TObject); 3632 procedure TMainForm.actSaveSQLSnippetExecute(Sender: TObject);
3636 var 3633 var
3637 snippetname : String; 3634 snippetname : String;
3638 Text, LB: String; 3635 Text, LB: String;
3639 begin 3636 begin
3640 // Save snippet 3637 // Save snippet
3641 if InputQuery( 'Save snippet', 'Snippet name:', snippetname) then 3638 if InputQuery( 'Save snippet', 'Snippet name:', snippetname) then
3642 begin 3639 begin
3643 if Copy( snippetname, Length(snippetname)-4, 4 ) <> '.sql' then 3640 if Copy( snippetname, Length(snippetname)-4, 4 ) <> '.sql' then
3644 snippetname := snippetname + '.sql'; 3641 snippetname := snippetname + '.sql';
3645 // cleanup snippetname from special characters 3642 // cleanup snippetname from special characters
3646 snippetname := FDirnameSnippets + goodfilename(snippetname); 3643 snippetname := FDirnameSnippets + goodfilename(snippetname);
3647 if FileExists( snippetname ) then 3644 if FileExists( snippetname ) then
3648 begin 3645 begin
3649 if MessageDialog('Overwrite existing snippet '+snippetname+'?', mtConfirmation, [mbOK, mbCancel]) <> mrOK then 3646 if MessageDialog('Overwrite existing snippet '+snippetname+'?', mtConfirmation, [mbOK, mbCancel]) <> mrOK then
3650 exit; 3647 exit;
3651 end; 3648 end;
3652 Screen.Cursor := crHourglass; 3649 Screen.Cursor := crHourglass;
3653 // Save complete content or just the selected text, 3650 // Save complete content or just the selected text,
3654 // depending on the tag of calling control 3651 // depending on the tag of calling control
3655 case (Sender as TComponent).Tag of 3652 case (Sender as TComponent).Tag of
3656 0: Text := ActiveQueryMemo.Text; 3653 0: Text := ActiveQueryMemo.Text;
3657 1: Text := ActiveQueryMemo.SelText; 3654 1: Text := ActiveQueryMemo.SelText;
3658 end; 3655 end;
3659 LB := ''; 3656 LB := '';
3660 case ActiveQueryTab.MemoLineBreaks of 3657 case ActiveQueryTab.MemoLineBreaks of
3661 lbsUnix: LB := LB_UNIX; 3658 lbsUnix: LB := LB_UNIX;
3662 lbsMac: LB := LB_MAC; 3659 lbsMac: LB := LB_MAC;
3663 lbsWide: LB := LB_WIDE; 3660 lbsWide: LB := LB_WIDE;
3664 end; 3661 end;
3665 if LB <> '' then 3662 if LB <> '' then
3666 Text := StringReplace(Text, CRLF, LB, [rfReplaceAll]); 3663 Text := StringReplace(Text, CRLF, LB, [rfReplaceAll]);
3667 if not DirectoryExists(FDirnameSnippets) then 3664 if not DirectoryExists(FDirnameSnippets) then
3668 ForceDirectories(FDirnameSnippets); 3665 ForceDirectories(FDirnameSnippets);
3669 SaveUnicodeFile( snippetname, Text ); 3666 SaveUnicodeFile( snippetname, Text );
3670 FillPopupQueryLoad; 3667 FillPopupQueryLoad;
3671 SetSnippetFilenames; 3668 SetSnippetFilenames;
3672 Screen.Cursor := crDefault; 3669 Screen.Cursor := crDefault;
3673 end; 3670 end;
3674 end; 3671 end;
3675 3672
3676 3673
3677 procedure TMainForm.actQueryStopOnErrorsExecute(Sender: TObject); 3674 procedure TMainForm.actQueryStopOnErrorsExecute(Sender: TObject);
3678 begin 3675 begin
3679 // Weird fix: dummy routine to avoid the sending action getting disabled 3676 // Weird fix: dummy routine to avoid the sending action getting disabled
3680 end; 3677 end;
3681 3678
3682 3679
3683 procedure TMainForm.actQueryWordWrapExecute(Sender: TObject); 3680 procedure TMainForm.actQueryWordWrapExecute(Sender: TObject);
3684 begin 3681 begin
3685 // SetupSynEditors applies all customizations to any SynEditor 3682 // SetupSynEditors applies all customizations to any SynEditor
3686 SetupSynEditors; 3683 SetupSynEditors;
3687 end; 3684 end;
3688 3685
3689 3686
3690 procedure TMainform.FillPopupQueryLoad; 3687 procedure TMainform.FillPopupQueryLoad;
3691 var 3688 var
3692 i, j: Integer; 3689 i, j: Integer;
3693 menuitem, snippetsfolder: TMenuItem; 3690 menuitem, snippetsfolder: TMenuItem;
3694 sqlFilename: String; 3691 sqlFilename: String;
3695 begin 3692 begin
3696 // Fill the popupQueryLoad menu 3693 // Fill the popupQueryLoad menu
3697 popupQueryLoad.Items.Clear; 3694 popupQueryLoad.Items.Clear;
3698 3695
3699 // Snippets 3696 // Snippets
3700 SetSnippetFilenames; 3697 SetSnippetFilenames;
3701 snippetsfolder := TMenuItem.Create( popupQueryLoad ); 3698 snippetsfolder := TMenuItem.Create( popupQueryLoad );
3702 snippetsfolder.Caption := 'Snippets'; 3699 snippetsfolder.Caption := 'Snippets';
3703 popupQueryLoad.Items.Add(snippetsfolder); 3700 popupQueryLoad.Items.Add(snippetsfolder);
3704 for i:=0 to FSnippetFilenames.Count-1 do begin 3701 for i:=0 to FSnippetFilenames.Count-1 do begin
3705 menuitem := TMenuItem.Create( snippetsfolder ); 3702 menuitem := TMenuItem.Create( snippetsfolder );
3706 menuitem.Caption := FSnippetFilenames[i]; 3703 menuitem.Caption := FSnippetFilenames[i];
3707 menuitem.OnClick := popupQueryLoadClick; 3704 menuitem.OnClick := popupQueryLoadClick;
3708 snippetsfolder.Add(menuitem); 3705 snippetsfolder.Add(menuitem);
3709 end; 3706 end;
3710 3707
3711 // Separator 3708 // Separator
3712 menuitem := TMenuItem.Create( popupQueryLoad ); 3709 menuitem := TMenuItem.Create( popupQueryLoad );
3713 menuitem.Caption := '-'; 3710 menuitem.Caption := '-';
3714 popupQueryLoad.Items.Add(menuitem); 3711 popupQueryLoad.Items.Add(menuitem);
3715 3712
3716 // Recent files 3713 // Recent files
3717 j := 0; 3714 j := 0;
3718 for i:=0 to 19 do begin 3715 for i:=0 to 19 do begin
3719 sqlFilename := GetRegValue( 'SQLFile'+IntToStr(i), '' ); 3716 sqlFilename := GetRegValue( 'SQLFile'+IntToStr(i), '' );
3720 if sqlFilename = '' then 3717 if sqlFilename = '' then
3721 continue; 3718 continue;
3722 inc(j); 3719 inc(j);
3723 menuitem := TMenuItem.Create( popupQueryLoad ); 3720 menuitem := TMenuItem.Create( popupQueryLoad );
3724 menuitem.Caption := IntToStr(j) + ' ' + sqlFilename; 3721 menuitem.Caption := IntToStr(j) + ' ' + sqlFilename;
3725 menuitem.OnClick := popupQueryLoadClick; 3722 menuitem.OnClick := popupQueryLoadClick;
3726 popupQueryLoad.Items.Add(menuitem); 3723 popupQueryLoad.Items.Add(menuitem);
3727 end; 3724 end;
3728 3725
3729 // Separator + "Remove absent files" 3726 // Separator + "Remove absent files"
3730 menuitem := TMenuItem.Create( popupQueryLoad ); 3727 menuitem := TMenuItem.Create( popupQueryLoad );
3731 menuitem.Caption := '-'; 3728 menuitem.Caption := '-';
3732 popupQueryLoad.Items.Add(menuitem); 3729 popupQueryLoad.Items.Add(menuitem);
3733 3730
3734 menuitem := TMenuItem.Create( popupQueryLoad ); 3731 menuitem := TMenuItem.Create( popupQueryLoad );
3735 menuitem.Caption := 'Remove absent files'; 3732 menuitem.Caption := 'Remove absent files';
3736 menuitem.OnClick := PopupQueryLoadRemoveAbsentFiles; 3733 menuitem.OnClick := PopupQueryLoadRemoveAbsentFiles;
3737 popupQueryLoad.Items.Add(menuitem); 3734 popupQueryLoad.Items.Add(menuitem);
3738 3735
3739 menuitem := TMenuItem.Create( popupQueryLoad ); 3736 menuitem := TMenuItem.Create( popupQueryLoad );
3740 menuitem.Caption := 'Clear file list'; 3737 menuitem.Caption := 'Clear file list';
3741 menuitem.OnClick := PopupQueryLoadRemoveAllFiles; 3738 menuitem.OnClick := PopupQueryLoadRemoveAllFiles;
3742 popupQueryLoad.Items.Add(menuitem); 3739 popupQueryLoad.Items.Add(menuitem);
3743 3740
3744 end; 3741 end;
3745 3742
3746 3743
3747 procedure TMainform.PopupQueryLoadRemoveAbsentFiles(Sender: TObject); 3744 procedure TMainform.PopupQueryLoadRemoveAbsentFiles(Sender: TObject);
3748 begin 3745 begin
3749 AddOrRemoveFromQueryLoadHistory('', False, True); 3746 AddOrRemoveFromQueryLoadHistory('', False, True);
3750 FillPopupQueryLoad; 3747 FillPopupQueryLoad;
3751 end; 3748 end;
3752 3749
3753 3750
3754 procedure TMainform.PopupQueryLoadRemoveAllFiles(Sender: TObject); 3751 procedure TMainform.PopupQueryLoadRemoveAllFiles(Sender: TObject);
3755 var 3752 var
3756 Values: TStringList; 3753 Values: TStringList;
3757 i: Integer; 3754 i: Integer;
3758 begin 3755 begin
3759 Values := TStringList.Create; 3756 Values := TStringList.Create;
3760 OpenRegistry; 3757 OpenRegistry;
3761 MainReg.GetValueNames(Values); 3758 MainReg.GetValueNames(Values);
3762 for i:=0 to Values.Count-1 do begin 3759 for i:=0 to Values.Count-1 do begin
3763 if Pos('SQLFile', Values[i]) = 1 then 3760 if Pos('SQLFile', Values[i]) = 1 then
3764 MainReg.DeleteValue(Values[i]); 3761 MainReg.DeleteValue(Values[i]);
3765 end; 3762 end;
3766 FillPopupQueryLoad; 3763 FillPopupQueryLoad;
3767 end; 3764 end;
3768 3765
3769 3766
3770 procedure TMainform.popupQueryLoadClick(Sender: TObject); 3767 procedure TMainform.popupQueryLoadClick(Sender: TObject);
3771 var 3768 var
3772 Filename: String; 3769 Filename: String;
3773 FileList: TStringList; 3770 FileList: TStringList;
3774 p: Integer; 3771 p: Integer;
3775 Tab: TQueryTab; 3772 Tab: TQueryTab;
3776 begin 3773 begin
3777 // Click on the popupQueryLoad 3774 // Click on the popupQueryLoad
3778 Filename := (Sender as TMenuItem).Caption; 3775 Filename := (Sender as TMenuItem).Caption;
3779 Filename := StripHotkey(Filename); 3776 Filename := StripHotkey(Filename);
3780 if Pos('\', Filename) = 0 then // assuming we load a snippet 3777 if Pos('\', Filename) = 0 then // assuming we load a snippet
3781 Filename := FDirnameSnippets + Filename + '.sql' 3778 Filename := FDirnameSnippets + Filename + '.sql'
3782 else begin // assuming we load a file from the recent-list 3779 else begin // assuming we load a file from the recent-list
3783 p := Pos(' ', Filename) + 1; 3780 p := Pos(' ', Filename) + 1;
3784 filename := Copy(Filename, p, Length(Filename)); 3781 filename := Copy(Filename, p, Length(Filename));
3785 end; 3782 end;
3786 FileList := TStringList.Create; 3783 FileList := TStringList.Create;
3787 FileList.Add(Filename); 3784 FileList.Add(Filename);
3788 if not RunQueryFiles(FileList, nil) then begin 3785 if not RunQueryFiles(FileList, nil) then begin
3789 Tab := ActiveOrEmptyQueryTab(True); 3786 Tab := ActiveOrEmptyQueryTab(True);
3790 Tab.LoadContents(Filename, True, nil); 3787 Tab.LoadContents(Filename, True, nil);
3791 SetMainTab(Tab.TabSheet); 3788 SetMainTab(Tab.TabSheet);
3792 end; 3789 end;
3793 FileList.Free; 3790 FileList.Free;
3794 end; 3791 end;
3795 3792
3796 3793
3797 procedure TMainform.AddOrRemoveFromQueryLoadHistory(Filename: String; AddIt: Boolean; CheckIfFileExists: Boolean); 3794 procedure TMainform.AddOrRemoveFromQueryLoadHistory(Filename: String; AddIt: Boolean; CheckIfFileExists: Boolean);
3798 var 3795 var
3799 i : Integer; 3796 i : Integer;
3800 Values, newfilelist : TStringList; 3797 Values, newfilelist : TStringList;
3801 savedfilename : String; 3798 savedfilename : String;
3802 begin 3799 begin
3803 // Add or remove filename to/from history, avoiding duplicates 3800 // Add or remove filename to/from history, avoiding duplicates
3804 3801
3805 newfilelist := TStringList.create; 3802 newfilelist := TStringList.create;
3806 Values := TStringList.create; 3803 Values := TStringList.create;
3807 OpenRegistry; 3804 OpenRegistry;
3808 MainReg.GetValueNames( Values ); 3805 MainReg.GetValueNames( Values );
3809 3806
3810 // Add new filename 3807 // Add new filename
3811 if AddIt then 3808 if AddIt then
3812 newfilelist.Add( filename ); 3809 newfilelist.Add( filename );
3813 3810
3814 // Add all other filenames 3811 // Add all other filenames
3815 for i:=0 to Values.Count-1 do begin 3812 for i:=0 to Values.Count-1 do begin
3816 if Pos( 'SQLFile', Values[i] ) <> 1 then 3813 if Pos( 'SQLFile', Values[i] ) <> 1 then
3817 continue; 3814 continue;
3818 savedfilename := GetRegValue( Values[i], '' ); 3815 savedfilename := GetRegValue( Values[i], '' );
3819 MainReg.DeleteValue( Values[i] ); 3816 MainReg.DeleteValue( Values[i] );
3820 if CheckIfFileExists and (not FileExists( savedfilename )) then 3817 if CheckIfFileExists and (not FileExists( savedfilename )) then
3821 continue; 3818 continue;
3822 if (savedfilename <> filename) and (newfilelist.IndexOf(savedfilename)=-1) then 3819 if (savedfilename <> filename) and (newfilelist.IndexOf(savedfilename)=-1) then
3823 newfilelist.add( savedfilename ); 3820 newfilelist.add( savedfilename );
3824 end; 3821 end;
3825 3822
3826 // Save new list 3823 // Save new list
3827 for i := 0 to newfilelist.Count-1 do begin 3824 for i := 0 to newfilelist.Count-1 do begin
3828 if i >= 20 then 3825 if i >= 20 then
3829 break; 3826 break;
3830 MainReg.WriteString( 'SQLFile'+IntToStr(i), newfilelist[i] ); 3827 MainReg.WriteString( 'SQLFile'+IntToStr(i), newfilelist[i] );
3831 end; 3828 end;
3832 end; 3829 end;
3833 3830
3834 3831
3835 {** 3832 {**
3836 Change default delimiter for SQL execution 3833 Change default delimiter for SQL execution
3837 } 3834 }
3838 procedure TMainForm.actSetDelimiterExecute(Sender: TObject); 3835 procedure TMainForm.actSetDelimiterExecute(Sender: TObject);
3839 var 3836 var
3840 newVal: String; 3837 newVal: String;
3841 ok: Boolean; 3838 ok: Boolean;
3842 begin 3839 begin
3843 // Use a while loop to redisplay the input dialog after setting an invalid value 3840 // Use a while loop to redisplay the input dialog after setting an invalid value
3844 ok := False; 3841 ok := False;
3845 while not ok do begin 3842 while not ok do begin
3846 newVal := delimiter; 3843 newVal := delimiter;
3847 if InputQuery('Set delimiter', 'SQL statement delimiter (default is ";"):', newVal) then try 3844 if InputQuery('Set delimiter', 'SQL statement delimiter (default is ";"):', newVal) then try
3848 // Set new value 3845 // Set new value
3849 Delimiter := newVal; 3846 Delimiter := newVal;
3850 ok := True; 3847 ok := True;
3851 except on E:Exception do 3848 except on E:Exception do
3852 ErrorDialog(E.Message); 3849 ErrorDialog(E.Message);
3853 end else // Cancel clicked 3850 end else // Cancel clicked
3854 ok := True; 3851 ok := True;
3855 end; 3852 end;
3856 end; 3853 end;
3857 3854
3858 3855
3859 {** 3856 {**
3860 Sets the Delimiter property plus updates the hint on actSetDelimiter 3857 Sets the Delimiter property plus updates the hint on actSetDelimiter
3861 } 3858 }
3862 procedure TMainForm.SetDelimiter(Value: String); 3859 procedure TMainForm.SetDelimiter(Value: String);
3863 var 3860 var
3864 rx: TRegExpr; 3861 rx: TRegExpr;
3865 Msg: String; 3862 Msg: String;
3866 begin 3863 begin
3867 Value := Trim(Value); 3864 Value := Trim(Value);
3868 Msg := ''; 3865 Msg := '';
3869 if Value = '' then 3866 if Value = '' then
3870 Msg := 'Empty value.' 3867 Msg := 'Empty value.'
3871 else begin 3868 else begin
3872 rx := TRegExpr.Create; 3869 rx := TRegExpr.Create;
3873 rx.Expression := '(/\*|--|#|\''|\"|`)'; 3870 rx.Expression := '(/\*|--|#|\''|\"|`)';
3874 if rx.Exec(Value) then 3871 if rx.Exec(Value) then
3875 Msg := 'Start-of-comment tokens or string literal markers are not allowed.' 3872 Msg := 'Start-of-comment tokens or string literal markers are not allowed.'
3876 end; 3873 end;
3877 if Msg <> '' then begin 3874 if Msg <> '' then begin
3878 Msg := 'Error setting delimiter to "'+Value+'": '+Msg; 3875 Msg := 'Error setting delimiter to "'+Value+'": '+Msg;
3879 LogSQL(Msg, lcError); 3876 LogSQL(Msg, lcError);
3880 ErrorDialog(Msg); 3877 ErrorDialog(Msg);
3881 end else begin 3878 end else begin
3882 FDelimiter := Value; 3879 FDelimiter := Value;
3883 LogSQL('Delimiter changed to '+FDelimiter, lcInfo); 3880 LogSQL('Delimiter changed to '+FDelimiter, lcInfo);
3884 actSetDelimiter.Hint := actSetDelimiter.Caption + ' (current value: '+Delimiter+')'; 3881 actSetDelimiter.Hint := actSetDelimiter.Caption + ' (current value: '+Delimiter+')';
3885 end; 3882 end;
3886 end; 3883 end;
3887 3884
3888 3885
3889 procedure TMainForm.actApplyFilterExecute(Sender: TObject); 3886 procedure TMainForm.actApplyFilterExecute(Sender: TObject);
3890 var 3887 var
3891 i, nr: Integer; 3888 i, nr: Integer;
3892 OldNumbers, Filters: TStringList; 3889 OldNumbers, Filters: TStringList;
3893 val: String; 3890 val: String;
3894 begin 3891 begin
3895 // If filter box is empty but filter generator box not, most users expect 3892 // If filter box is empty but filter generator box not, most users expect
3896 // the filter to be auto generated on button click 3893 // the filter to be auto generated on button click
3897 if (SynMemoFilter.GetTextLen = 0) and (editFilterSearch.Text <> '') then 3894 if (SynMemoFilter.GetTextLen = 0) and (editFilterSearch.Text <> '') then
3898 editFilterSearchChange(editFilterSearch); 3895 editFilterSearchChange(editFilterSearch);
3899 3896
3900 if SynMemoFilter.GetTextLen > 0 then begin 3897 if SynMemoFilter.GetTextLen > 0 then begin
3901 // Recreate recent filters list 3898 // Recreate recent filters list
3902 Filters := TStringList.Create; 3899 Filters := TStringList.Create;
3903 OldNumbers := TStringList.Create; 3900 OldNumbers := TStringList.Create;
3904 Filters.Add(Trim(SynMemoFilter.Text)); 3901 Filters.Add(Trim(SynMemoFilter.Text));
3905 MainReg.OpenKey(GetRegKeyTable+'\'+REGNAME_FILTERS, True); 3902 MainReg.OpenKey(GetRegKeyTable+'\'+REGNAME_FILTERS, True);
3906 MainReg.GetValueNames(OldNumbers); 3903 MainReg.GetValueNames(OldNumbers);
3907 OldNumbers.CustomSort(StringListCompareAnythingAsc); 3904 OldNumbers.CustomSort(StringListCompareAnythingAsc);
3908 // Add old filters 3905 // Add old filters
3909 for i := 0 to OldNumbers.Count - 1 do begin 3906 for i := 0 to OldNumbers.Count - 1 do begin
3910 nr := MakeInt(OldNumbers[i]); 3907 nr := MakeInt(OldNumbers[i]);
3911 if nr = 0 then continue; // Not a valid entry, ignore that 3908 if nr = 0 then continue; // Not a valid entry, ignore that
3912 val := MainReg.ReadString(OldNumbers[i]); 3909 val := MainReg.ReadString(OldNumbers[i]);
3913 if Filters.IndexOf(val) = -1 then 3910 if Filters.IndexOf(val) = -1 then
3914 Filters.Add(val); 3911 Filters.Add(val);
3915 MainReg.DeleteValue(OldNumbers[i]); 3912 MainReg.DeleteValue(OldNumbers[i]);
3916 end; 3913 end;
3917 for i := 1 to Filters.Count do begin 3914 for i := 1 to Filters.Count do begin
3918 MainReg.WriteString(IntToStr(i), Filters[i-1]); 3915 MainReg.WriteString(IntToStr(i), Filters[i-1]);
3919 // Avoid too much registry spam with mega old filters 3916 // Avoid too much registry spam with mega old filters
3920 if i = 20 then break; 3917 if i = 20 then break;
3921 end; 3918 end;
3922 FreeAndNil(OldNumbers); 3919 FreeAndNil(OldNumbers);
3923 FreeAndNil(Filters); 3920 FreeAndNil(Filters);
3924 end; 3921 end;
3925 // Keep current column widths on "Quick filter" clicks, don't keep them on "Apply filter" clicks 3922 // Keep current column widths on "Quick filter" clicks, don't keep them on "Apply filter" clicks
3926 if (Sender is TMenuItem) and ((Sender as TMenuItem).GetParentMenu = popupDataGrid) then begin 3923 if (Sender is TMenuItem) and ((Sender as TMenuItem).GetParentMenu = popupDataGrid) then begin
3927 FDataGridColumnWidthsCustomized := True; 3924 FDataGridColumnWidthsCustomized := True;
3928 end else 3925 end else
3929 FDataGridColumnWidthsCustomized := False; 3926 FDataGridColumnWidthsCustomized := False;
3930 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False); 3927 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False);
3931 end; 3928 end;
3932 3929
3933 3930
3934 procedure TMainForm.actDataFirstExecute(Sender: TObject); 3931 procedure TMainForm.actDataFirstExecute(Sender: TObject);
3935 var 3932 var
3936 Node: PVirtualNode; 3933 Node: PVirtualNode;
3937 begin 3934 begin
3938 Node := GetNextNode(ActiveGrid, nil); 3935 Node := GetNextNode(ActiveGrid, nil);
3939 if Assigned(Node) then 3936 if Assigned(Node) then
3940 SelectNode(ActiveGrid, Node); 3937 SelectNode(ActiveGrid, Node);
3941 end; 3938 end;
3942 3939
3943 3940
3944 procedure TMainForm.actDataInsertExecute(Sender: TObject); 3941 procedure TMainForm.actDataInsertExecute(Sender: TObject);
3945 var 3942 var
3946 DupeNode, NewNode: PVirtualNode; 3943 DupeNode, NewNode: PVirtualNode;
3947 Grid: TVirtualStringTree; 3944 Grid: TVirtualStringTree;
3948 Results: TDBQuery; 3945 Results: TDBQuery;
3949 RowNum: Cardinal; 3946 RowNum: Cardinal;
3950 DupeNum: PCardinal; 3947 DupeNum: PCardinal;
3951 i: Integer; 3948 i: Integer;
3952 Value: String; 3949 Value: String;
3953 IsNull, AllowNewNode: Boolean; 3950 IsNull, AllowNewNode: Boolean;
3954 begin 3951 begin
3955 Grid := ActiveGrid; 3952 Grid := ActiveGrid;
3956 Results := GridResult(Grid); 3953 Results := GridResult(Grid);
3957 // Pre-test if changing node focus is allowed, in cases where current row modifications throw some SQL error when posting 3954 // Pre-test if changing node focus is allowed, in cases where current row modifications throw some SQL error when posting
3958 AllowNewNode := False; 3955 AllowNewNode := False;
3959 Grid.OnFocusChanging(Grid, Grid.FocusedNode, nil, Grid.FocusedColumn, Grid.FocusedColumn, AllowNewNode); 3956 Grid.OnFocusChanging(Grid, Grid.FocusedNode, nil, Grid.FocusedColumn, Grid.FocusedColumn, AllowNewNode);
3960 if not AllowNewNode then 3957 if not AllowNewNode then
3961 exit; 3958 exit;
3962 try 3959 try
3963 Results.CheckEditable; 3960 Results.CheckEditable;
3964 DupeNode := nil; 3961 DupeNode := nil;
3965 if Sender = actDataDuplicateRow then 3962 if Sender = actDataDuplicateRow then
3966 DupeNode := Grid.FocusedNode; 3963 DupeNode := Grid.FocusedNode;
3967 RowNum := Results.InsertRow; 3964 RowNum := Results.InsertRow;
3968 NewNode := Grid.InsertNode(Grid.FocusedNode, amInsertAfter, PCardinal(RowNum)); 3965 NewNode := Grid.InsertNode(Grid.FocusedNode, amInsertAfter, PCardinal(RowNum));
3969 SelectNode(Grid, NewNode); 3966 SelectNode(Grid, NewNode);
3970 if Assigned(DupeNode) then begin 3967 if Assigned(DupeNode) then begin
3971 // Copy values from source row, ensure we have whole cell data 3968 // Copy values from source row, ensure we have whole cell data
3972 DupeNum := Grid.GetNodeData(DupeNode); 3969 DupeNum := Grid.GetNodeData(DupeNode);
3973 AnyGridEnsureFullRow(Grid, DupeNode); 3970 AnyGridEnsureFullRow(Grid, DupeNode);
3974 for i:=0 to Grid.Header.Columns.Count-1 do begin 3971 for i:=0 to Grid.Header.Columns.Count-1 do begin
3975 if not (coVisible in Grid.Header.Columns[i].Options) then 3972 if not (coVisible in Grid.Header.Columns[i].Options) then
3976 continue; // Ignore invisible key column 3973 continue; // Ignore invisible key column
3977 if Results.ColIsPrimaryKeyPart(i) then 3974 if Results.ColIsPrimaryKeyPart(i) then
3978 continue; // Empty value for primary key column 3975 continue; // Empty value for primary key column
3979 Results.RecNo := DupeNum^; 3976 Results.RecNo := DupeNum^;
3980 Value := Results.Col(i); 3977 Value := Results.Col(i);
3981 IsNull := Results.IsNull(i); 3978 IsNull := Results.IsNull(i);
3982 Results.RecNo := RowNum; 3979 Results.RecNo := RowNum;
3983 Results.SetCol(i, Value, IsNull); 3980 Results.SetCol(i, Value, IsNull);
3984 end; 3981 end;
3985 end; 3982 end;
3986 except on E:EDatabaseError do 3983 except on E:EDatabaseError do
3987 ErrorDialog('Grid editing error', E.Message); 3984 ErrorDialog('Grid editing error', E.Message);
3988 end; 3985 end;
3989 end; 3986 end;
3990 3987
3991 3988
3992 procedure TMainForm.actDataLastExecute(Sender: TObject); 3989 procedure TMainForm.actDataLastExecute(Sender: TObject);
3993 var 3990 var
3994 Node: PVirtualNode; 3991 Node: PVirtualNode;
3995 Grid: TVirtualStringTree; 3992 Grid: TVirtualStringTree;
3996 begin 3993 begin
3997 Grid := ActiveGrid; 3994 Grid := ActiveGrid;
3998 // Be sure to have all rows 3995 // Be sure to have all rows
3999 if (Grid = DataGrid) and (DatagridWantedRowCount < prefGridRowcountMax) then 3996 if (Grid = DataGrid) and (DatagridWantedRowCount < prefGridRowcountMax) then
4000 actDataShowAll.Execute; 3997 actDataShowAll.Execute;
4001 Node := Grid.GetLast; 3998 Node := Grid.GetLast;
4002 if Assigned(Node) then 3999 if Assigned(Node) then
4003 SelectNode(Grid, Node); 4000 SelectNode(Grid, Node);
4004 end; 4001 end;
4005 4002
4006 procedure TMainForm.actDataPostChangesExecute(Sender: TObject); 4003 procedure TMainForm.actDataPostChangesExecute(Sender: TObject);
4007 var 4004 var
4008 Grid: TVirtualStringTree; 4005 Grid: TVirtualStringTree;
4009 Results: TDBQuery; 4006 Results: TDBQuery;
4010 begin 4007 begin
4011 if Sender is TVirtualStringTree then 4008 if Sender is TVirtualStringTree then
4012 Grid := Sender as TVirtualStringTree 4009 Grid := Sender as TVirtualStringTree
4013 else 4010 else
4014 Grid := ActiveGrid; 4011 Grid := ActiveGrid;
4015 Results := GridResult(Grid); 4012 Results := GridResult(Grid);
4016 Results.SaveModifications; 4013 Results.SaveModifications;
4017 // Node needs a repaint to remove red triangles 4014 // Node needs a repaint to remove red triangles
4018 if Assigned(Grid.FocusedNode) then 4015 if Assigned(Grid.FocusedNode) then
4019 Grid.InvalidateNode(Grid.FocusedNode); 4016 Grid.InvalidateNode(Grid.FocusedNode);
4020 DisplayRowCountStats(Grid); 4017 DisplayRowCountStats(Grid);
4021 end; 4018 end;
4022 4019
4023 procedure TMainForm.actRemoveFilterExecute(Sender: TObject); 4020 procedure TMainForm.actRemoveFilterExecute(Sender: TObject);
4024 begin 4021 begin
4025 actClearFilterEditor.Execute; 4022 actClearFilterEditor.Execute;
4026 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False); 4023 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False);
4027 end; 4024 end;
4028 4025
4029 4026
4030 procedure TMainForm.actDataCancelChangesExecute(Sender: TObject); 4027 procedure TMainForm.actDataCancelChangesExecute(Sender: TObject);
4031 var 4028 var
4032 Grid: TVirtualStringTree; 4029 Grid: TVirtualStringTree;
4033 Results: TDBQuery; 4030 Results: TDBQuery;
4034 RowNum: PCardinal; 4031 RowNum: PCardinal;
4035 Node, FocNode: PVirtualNode; 4032 Node, FocNode: PVirtualNode;
4036 begin 4033 begin
4037 // Cancel INSERT or UPDATE mode 4034 // Cancel INSERT or UPDATE mode
4038 Grid := ActiveGrid; 4035 Grid := ActiveGrid;
4039 Node := Grid.FocusedNode; 4036 Node := Grid.FocusedNode;
4040 if Assigned(Node) then begin 4037 if Assigned(Node) then begin
4041 Results := GridResult(Grid); 4038 Results := GridResult(Grid);
4042 RowNum := Grid.GetNodeData(Node); 4039 RowNum := Grid.GetNodeData(Node);
4043 Results.RecNo := RowNum^; 4040 Results.RecNo := RowNum^;
4044 Results.DiscardModifications; 4041 Results.DiscardModifications;
4045 if Results.Inserted then begin 4042 if Results.Inserted then begin
4046 FocNode := Grid.GetPreviousSibling(Node); 4043 FocNode := Grid.GetPreviousSibling(Node);
4047 Grid.DeleteNode(Node); 4044 Grid.DeleteNode(Node);
4048 SelectNode(Grid, FocNode); 4045 SelectNode(Grid, FocNode);
4049 end else 4046 end else
4050 Grid.InvalidateNode(Node); 4047 Grid.InvalidateNode(Node);
4051 ValidateControls(Sender); 4048 ValidateControls(Sender);
4052 end; 4049 end;
4053 end; 4050 end;
4054 4051
4055 4052
4056 procedure TMainForm.actSelectTreeBackgroundExecute(Sender: TObject); 4053 procedure TMainForm.actSelectTreeBackgroundExecute(Sender: TObject);
4057 var 4054 var
4058 cs: TColorSelect; 4055 cs: TColorSelect;
4059 SessionNames: TStringList; 4056 SessionNames: TStringList;
4060 i: Integer; 4057 i: Integer;
4061 Col: TColor; 4058 Col: TColor;
4062 ColString: String; 4059 ColString: String;
4063 CharPostfix: Char; 4060 CharPostfix: Char;
4064 4061
4065 function ValueExists(Value: String): Boolean; 4062 function ValueExists(Value: String): Boolean;
4066 var 4063 var
4067 j: Integer; 4064 j: Integer;
4068 begin 4065 begin
4069 // Value exists in string list? 4066 // Value exists in string list?
4070 Result := False; 4067 Result := False;
4071 for j:=0 to cs.Dialog.CustomColors.Count-1 do begin 4068 for j:=0 to cs.Dialog.CustomColors.Count-1 do begin
4072 if cs.Dialog.CustomColors.ValueFromIndex[j] = Value then begin 4069 if cs.Dialog.CustomColors.ValueFromIndex[j] = Value then begin
4073 Result := True; 4070 Result := True;
4074 break; 4071 break;
4075 end; 4072 end;
4076 end; 4073 end;
4077 end; 4074 end;
4078 4075
4079 begin 4076 begin
4080 // Select database tree background color 4077 // Select database tree background color
4081 cs := TColorSelect.Create(Self); 4078 cs := TColorSelect.Create(Self);
4082 cs.Dialog.Color := DBtree.Color; 4079 cs.Dialog.Color := DBtree.Color;
4083 // Add custom colors from all sessions 4080 // Add custom colors from all sessions
4084 SessionNames := TStringList.Create; 4081 SessionNames := TStringList.Create;
4085 MainReg.OpenKey(RegPath + REGKEY_SESSIONS, True); 4082 MainReg.OpenKey(RegPath + REGKEY_SESSIONS, True);
4086 MainReg.GetKeyNames(SessionNames); 4083 MainReg.GetKeyNames(SessionNames);
4087 CharPostfix := 'A'; 4084 CharPostfix := 'A';
4088 for i:=0 to SessionNames.Count-1 do begin 4085 for i:=0 to SessionNames.Count-1 do begin
4089 Col := GetRegValue(REGNAME_TREEBACKGROUND, clDefault, SessionNames[i]); 4086 Col := GetRegValue(REGNAME_TREEBACKGROUND, clDefault, SessionNames[i]);
4090 if Col <> clDefault then begin 4087 if Col <> clDefault then begin
4091 ColString := IntToHex(ColorToRgb(Col), 6); 4088 ColString := IntToHex(ColorToRgb(Col), 6);
4092 if not ValueExists(ColString) then begin 4089 if not ValueExists(ColString) then begin
4093 cs.Dialog.CustomColors.Add('Color'+CharPostfix+'='+ColString); 4090 cs.Dialog.CustomColors.Add('Color'+CharPostfix+'='+ColString);
4094 if cs.Dialog.CustomColors.Count >= MaxCustomColors then 4091 if cs.Dialog.CustomColors.Count >= MaxCustomColors then
4095 break; 4092 break;
4096 CharPostfix := Chr(Ord(CharPostfix)+1); 4093 CharPostfix := Chr(Ord(CharPostfix)+1);
4097 end; 4094 end;
4098 end; 4095 end;
4099 end; 4096 end;
4100 if cs.Execute then begin 4097 if cs.Execute then begin
4101 DBtree.Color := cs.Dialog.Color; 4098 DBtree.Color := cs.Dialog.Color;
4102 OpenRegistry(ActiveConnection.Parameters.SessionName); 4099 OpenRegistry(ActiveConnection.Parameters.SessionName);
4103 MainReg.WriteInteger(REGNAME_TREEBACKGROUND, cs.Dialog.Color); 4100 MainReg.WriteInteger(REGNAME_TREEBACKGROUND, cs.Dialog.Color);
4104 end; 4101 end;
4105 end; 4102 end;
4106 4103
4107 4104
4108 {** 4105 {**
4109 Add a SQL-command or comment to SynMemoSQLLog 4106 Add a SQL-command or comment to SynMemoSQLLog
4110 } 4107 }
4111 procedure TMainForm.LogSQL(Msg: String; Category: TDBLogCategory=lcInfo; Connection: TDBConnection=nil); 4108 procedure TMainForm.LogSQL(Msg: String; Category: TDBLogCategory=lcInfo; Connection: TDBConnection=nil);
4112 var 4109 var
4113 snip, IsSQL: Boolean; 4110 snip, IsSQL: Boolean;
4114 Len, i: Integer; 4111 Len, i: Integer;
4115 Sess: String; 4112 Sess: String;
4116 begin 4113 begin
4117 if csDestroying in ComponentState then 4114 if csDestroying in ComponentState then
4118 Exit; 4115 Exit;
4119 4116
4120 // Log only wanted events 4117 // Log only wanted events
4121 case Category of 4118 case Category of
4122 lcError: if not prefLogErrors then Exit; 4119 lcError: if not prefLogErrors then Exit;
4123 lcUserFiredSQL: if not prefLogUserSQL then Exit; 4120 lcUserFiredSQL: if not prefLogUserSQL then Exit;
4124 lcSQL: if not prefLogSQL then Exit; 4121 lcSQL: if not prefLogSQL then Exit;
4125 lcInfo: if not prefLogInfos then Exit; 4122 lcInfo: if not prefLogInfos then Exit;
4126 lcDebug: if not prefLogDebug then Exit; 4123 lcDebug: if not prefLogDebug then Exit;
4127 end; 4124 end;
4128 4125
4129 // Shorten very long messages 4126 // Shorten very long messages
4130 Len := Length(Msg); 4127 Len := Length(Msg);
4131 snip := (prefLogSqlWidth > 0) and (Len > prefLogSqlWidth); 4128 snip := (prefLogSqlWidth > 0) and (Len > prefLogSqlWidth);
4132 IsSQL := Category in [lcSQL, lcUserFiredSQL]; 4129 IsSQL := Category in [lcSQL, lcUserFiredSQL];
4133 if snip then begin 4130 if snip then begin
4134 Msg := 4131 Msg :=
4135 Copy(Msg, 0, prefLogSqlWidth) + 4132 Copy(Msg, 0, prefLogSqlWidth) +
4136 '/* large SQL query ('+FormatByteNumber(Len)+'), snipped at ' + 4133 '/* large SQL query ('+FormatByteNumber(Len)+'), snipped at ' +
4137 FormatNumber(prefLogSqlWidth) + 4134 FormatNumber(prefLogSqlWidth) +
4138 ' characters */'; 4135 ' characters */';
4139 end else if (not snip) and IsSQL then 4136 end else if (not snip) and IsSQL then
4140 Msg := Msg + Delimiter; 4137 Msg := Msg + Delimiter;
4141 if not IsSQL then 4138 if not IsSQL then
4142 Msg := '/* ' + Msg + ' */'; 4139 Msg := '/* ' + Msg + ' */';
4143 4140
4144 SynMemoSQLLog.Lines.Add(Msg); 4141 SynMemoSQLLog.Lines.Add(Msg);
4145 4142
4146 // Delete first line(s) in SQL log and adjust LineNumberStart in gutter 4143 // Delete first line(s) in SQL log and adjust LineNumberStart in gutter
4147 i := 0; 4144 i := 0;
4148 while SynMemoSQLLog.Lines.Count > prefLogsqlnum do begin 4145 while SynMemoSQLLog.Lines.Count > prefLogsqlnum do begin
4149 SynMemoSQLLog.Lines.Delete(0); 4146 SynMemoSQLLog.Lines.Delete(0);
4150 Inc(i); 4147 Inc(i);
4151 end; 4148 end;
4152 // Increase first displayed number in gutter so it doesn't lie about the log entries 4149 // Increase first displayed number in gutter so it doesn't lie about the log entries
4153 if i > 0 then 4150 if i > 0 then
4154 SynMemoSQLLog.Gutter.LineNumberStart := SynMemoSQLLog.Gutter.LineNumberStart + i; 4151 SynMemoSQLLog.Gutter.LineNumberStart := SynMemoSQLLog.Gutter.LineNumberStart + i;
4155 4152
4156 // Scroll to last line and repaint 4153 // Scroll to last line and repaint
4157 SynMemoSQLLog.GotoLineAndCenter(SynMemoSQLLog.Lines.Count); 4154 SynMemoSQLLog.GotoLineAndCenter(SynMemoSQLLog.Lines.Count);
4158 SynMemoSQLLog.Repaint; 4155 SynMemoSQLLog.Repaint;
4159 4156
4160 // Log to file? 4157 // Log to file?
4161 if prefLogToFile then 4158 if prefLogToFile then
4162 try 4159 try
4163 Sess := ''; 4160 Sess := '';
4164 if Assigned(Connection) then 4161 if Assigned(Connection) then
4165 Sess := Connection.Parameters.SessionName; 4162 Sess := Connection.Parameters.SessionName;
4166 WriteLn(FFileHandleSessionLog, Format('/* %s [%s] */ %s', [DateTimeToStr(Now), Sess, msg])); 4163 WriteLn(FFileHandleSessionLog, Format('/* %s [%s] */ %s', [DateTimeToStr(Now), Sess, msg]));
4167 except 4164 except
4168 on E:Exception do begin 4165 on E:Exception do begin
4169 DeactivateFileLogging; 4166 DeactivateFileLogging;
4170 ErrorDialog('Error writing to session log file.', FFileNameSessionLog+CRLF+CRLF+E.Message+CRLF+CRLF+'Logging is disabled now.'); 4167 ErrorDialog('Error writing to session log file.', FFileNameSessionLog+CRLF+CRLF+E.Message+CRLF+CRLF+'Logging is disabled now.');
4171 end; 4168 end;
4172 end; 4169 end;
4173 end; 4170 end;
4174 4171
4175 4172
4176 procedure TMainForm.actDataShowNextExecute(Sender: TObject); 4173 procedure TMainForm.actDataShowNextExecute(Sender: TObject);
4177 var 4174 var
4178 OldRowCount: Int64; 4175 OldRowCount: Int64;
4179 begin 4176 begin
4180 // Show next X rows in datagrid 4177 // Show next X rows in datagrid
4181 OldRowCount := DatagridWantedRowCount; 4178 OldRowCount := DatagridWantedRowCount;
4182 Inc(DatagridWantedRowCount, prefGridRowcountStep); 4179 Inc(DatagridWantedRowCount, prefGridRowcountStep);
4183 DataGridWantedRowCount := Min(DataGridWantedRowCount, prefGridRowcountMax); 4180 DataGridWantedRowCount := Min(DataGridWantedRowCount, prefGridRowcountMax);
4184 InvalidateVT(DataGrid, VTREE_NOTLOADED, True); 4181 InvalidateVT(DataGrid, VTREE_NOTLOADED, True);
4185 SelectNode(DataGrid, OldRowCount); 4182 SelectNode(DataGrid, OldRowCount);
4186 end; 4183 end;
4187 4184
4188 4185
4189 procedure TMainForm.actDataShowAllExecute(Sender: TObject); 4186 procedure TMainForm.actDataShowAllExecute(Sender: TObject);
4190 begin 4187 begin
4191 // Remove LIMIT clause 4188 // Remove LIMIT clause
4192 DatagridWantedRowCount := prefGridRowcountMax; 4189 DatagridWantedRowCount := prefGridRowcountMax;
4193 InvalidateVT(DataGrid, VTREE_NOTLOADED, True); 4190 InvalidateVT(DataGrid, VTREE_NOTLOADED, True);
4194 end; 4191 end;
4195 4192
4196 4193
4197 function TMainForm.AnyGridEnsureFullRow(Grid: TVirtualStringTree; Node: PVirtualNode): Boolean; 4194 function TMainForm.AnyGridEnsureFullRow(Grid: TVirtualStringTree; Node: PVirtualNode): Boolean;
4198 var 4195 var
4199 RowNum: PCardinal; 4196 RowNum: PCardinal;
4200 Data: TDBQuery; 4197 Data: TDBQuery;
4201 begin 4198 begin
4202 // Load remaining data on a partially loaded row in data grid 4199 // Load remaining data on a partially loaded row in data grid
4203 Result := True; 4200 Result := True;
4204 if (Grid = DataGrid) and Assigned(Node) then begin 4201 if (Grid = DataGrid) and Assigned(Node) then begin
4205 RowNum := Grid.GetNodeData(Node); 4202 RowNum := Grid.GetNodeData(Node);
4206 Data := GridResult(Grid); 4203 Data := GridResult(Grid);
4207 Data.RecNo := RowNum^; 4204 Data.RecNo := RowNum^;
4208 Result := Data.EnsureFullRow; 4205 Result := Data.EnsureFullRow;
4209 end; 4206 end;
4210 end; 4207 end;
4211 4208
4212 4209
4213 procedure TMainForm.DataGridEnsureFullRows(Grid: TVirtualStringTree; SelectedOnly: Boolean); 4210 procedure TMainForm.DataGridEnsureFullRows(Grid: TVirtualStringTree; SelectedOnly: Boolean);
4214 var 4211 var
4215 Node: PVirtualNode; 4212 Node: PVirtualNode;
4216 Results: TDBQuery; 4213 Results: TDBQuery;
4217 RowNum: PCardinal; 4214 RowNum: PCardinal;
4218 begin 4215 begin
4219 // Load remaining data of all grid rows 4216 // Load remaining data of all grid rows
4220 Results := GridResult(Grid); 4217 Results := GridResult(Grid);
4221 Node := GetNextNode(Grid, nil, SelectedOnly); 4218 Node := GetNextNode(Grid, nil, SelectedOnly);
4222 while Assigned(Node) do begin 4219 while Assigned(Node) do begin
4223 RowNum := Grid.GetNodeData(Node); 4220 RowNum := Grid.GetNodeData(Node);
4224 Results.RecNo := RowNum^; 4221 Results.RecNo := RowNum^;
4225 if not Results.HasFullData then begin 4222 if not Results.HasFullData then begin
4226 DataGridFullRowMode := True; 4223 DataGridFullRowMode := True;
4227 InvalidateVT(Grid, VTREE_NOTLOADED_PURGECACHE, True); 4224 InvalidateVT(Grid, VTREE_NOTLOADED_PURGECACHE, True);
4228 break; 4225 break;
4229 end; 4226 end;
4230 Node := GetNextNode(Grid, Node, SelectedOnly); 4227 Node := GetNextNode(Grid, Node, SelectedOnly);
4231 end; 4228 end;
4232 end; 4229 end;
4233 4230
4234 4231
4235 procedure TMainForm.DataGridBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas); 4232 procedure TMainForm.DataGridBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
4236 var 4233 var
4237 vt: TVirtualStringTree; 4234 vt: TVirtualStringTree;
4238 Select: String; 4235 Select: String;
4239 RefreshingData, IsKeyColumn: Boolean; 4236 RefreshingData, IsKeyColumn: Boolean;
4240 i, Offset, ColLen, ColWidth, VisibleColumns: Integer; 4237 i, Offset, ColLen, ColWidth, VisibleColumns: Integer;
4241 KeyCols, ColWidths, WantedColumnOrgnames: TStringList; 4238 KeyCols, ColWidths, WantedColumnOrgnames: TStringList;
4242 WantedColumns: TTableColumnList; 4239 WantedColumns: TTableColumnList;
4243 c: TTableColumn; 4240 c: TTableColumn;
4244 OldScrollOffset: TPoint; 4241 OldScrollOffset: TPoint;
4245 DBObj: TDBObject; 4242 DBObj: TDBObject;
4246 4243
4247 procedure InitColumn(idx: Integer; TblCol: TTableColumn); 4244 procedure InitColumn(idx: Integer; TblCol: TTableColumn);
4248 var 4245 var
4249 k: Integer; 4246 k: Integer;
4250 Col: TVirtualTreeColumn; 4247 Col: TVirtualTreeColumn;
4251 begin 4248 begin
4252 col := vt.Header.Columns.Add; 4249 col := vt.Header.Columns.Add;
4253 col.Text := TblCol.Name; 4250 col.Text := TblCol.Name;
4254 col.Hint := TblCol.Comment; 4251 col.Hint := TblCol.Comment;
4255 col.Options := col.Options + [coSmartResize]; 4252 col.Options := col.Options + [coSmartResize];
4256 if DatagridHiddenColumns.IndexOf(TblCol.Name) > -1 then 4253 if DatagridHiddenColumns.IndexOf(TblCol.Name) > -1 then
4257 col.Options := col.Options - [coVisible]; 4254 col.Options := col.Options - [coVisible];
4258 // Sorting color and title image 4255 // Sorting color and title image
4259 for k:=0 to Length(DataGridSortColumns)-1 do begin 4256 for k:=0 to Length(DataGridSortColumns)-1 do begin
4260 if DataGridSortColumns[k].ColumnName = TblCol.Name then begin 4257 if DataGridSortColumns[k].ColumnName = TblCol.Name then begin
4261 col.Color := ColorAdjustBrightness(col.Color, COLORSHIFT_SORTCOLUMNS); 4258 col.Color := ColorAdjustBrightness(col.Color, COLORSHIFT_SORTCOLUMNS);
4262 case DataGridSortColumns[k].SortDirection of 4259 case DataGridSortColumns[k].SortDirection of
4263 ORDER_ASC: col.ImageIndex := 109; 4260 ORDER_ASC: col.ImageIndex := 109;
4264 ORDER_DESC: col.ImageIndex := 110; 4261 ORDER_DESC: col.ImageIndex := 110;
4265 end; 4262 end;
4266 end; 4263 end;
4267 end; 4264 end;
4268 if col.ImageIndex = -1 then begin 4265 if col.ImageIndex = -1 then begin
4269 for k:=0 to SelectedTableKeys.Count-1 do begin 4266 for k:=0 to SelectedTableKeys.Count-1 do begin
4270 if SelectedTableKeys[k].Columns.IndexOf(TblCol.Name) > -1 then begin 4267 if SelectedTableKeys[k].Columns.IndexOf(TblCol.Name) > -1 then begin
4271 col.ImageIndex := GetIndexIcon(SelectedTableKeys[k].IndexType); 4268 col.ImageIndex := GetIndexIcon(SelectedTableKeys[k].IndexType);
4272 break; 4269 break;
4273 end; 4270 end;
4274 end; 4271 end;
4275 end; 4272 end;
4276 4273
4277 // Data type 4274 // Data type
4278 col.Alignment := taLeftJustify; 4275 col.Alignment := taLeftJustify;
4279 if DataGridResult.DataType(idx).Category in [dtcInteger, dtcReal] then 4276 if DataGridResult.DataType(idx).Category in [dtcInteger, dtcReal] then
4280 col.Alignment := taRightJustify; 4277 col.Alignment := taRightJustify;
4281 end; 4278 end;
4282 4279
4283 begin 4280 begin
4284 // Load data into data tab grid 4281 // Load data into data tab grid
4285 vt := Sender as TVirtualStringTree; 4282 vt := Sender as TVirtualStringTree;
4286 if vt.Tag = VTREE_LOADED then 4283 if vt.Tag = VTREE_LOADED then
4287 Exit; 4284 Exit;
4288 DBObj := ActiveDbObj; 4285 DBObj := ActiveDbObj;
4289 if DBObj = nil then 4286 if DBObj = nil then
4290 Exit; 4287 Exit;
4291 Screen.Cursor := crHourglass; 4288 Screen.Cursor := crHourglass;
4292 DBObj.Connection.Ping(True); 4289 DBObj.Connection.Ping(True);
4293 4290
4294 // No data for routines 4291 // No data for routines
4295 if SelectedTableColumns.Count = 0 then begin 4292 if SelectedTableColumns.Count = 0 then begin
4296 vt.Enabled := False; 4293 vt.Enabled := False;
4297 pnlDataTop.Enabled := False; 4294 pnlDataTop.Enabled := False;
4298 pnlFilter.Enabled := False; 4295 pnlFilter.Enabled := False;
4299 lblSorryNoData.Parent := DataGrid; 4296 lblSorryNoData.Parent := DataGrid;
4300 end else begin 4297 end else begin
4301 vt.Enabled := True; 4298 vt.Enabled := True;
4302 pnlDataTop.Enabled := True; 4299 pnlDataTop.Enabled := True;
4303 pnlFilter.Enabled := True; 4300 pnlFilter.Enabled := True;
4304 lblSorryNoData.Parent := tabData; 4301 lblSorryNoData.Parent := tabData;
4305 4302
4306 // Indicates whether the current table data is just refreshed or if we're in another table 4303 // Indicates whether the current table data is just refreshed or if we're in another table
4307 RefreshingData := (ActiveDatabase = DataGridDB) and (DBObj.Name = DataGridTable); 4304 RefreshingData := (ActiveDatabase = DataGridDB) and (DBObj.Name = DataGridTable);
4308 4305
4309 // Load last view settings 4306 // Load last view settings
4310 HandleDataGridAttributes(RefreshingData); 4307 HandleDataGridAttributes(RefreshingData);
4311 OldScrollOffset := DataGrid.OffsetXY; 4308 OldScrollOffset := DataGrid.OffsetXY;
4312 4309
4313 // Remember old column widths if customized 4310 // Remember old column widths if customized
4314 ColWidths := TStringList.Create; 4311 ColWidths := TStringList.Create;