Display a SQL dynamic preview for the CREATE DATABASE statement using a SynMemo.

This commit is contained in:
Ansgar Becker
2007-09-18 22:44:17 +00:00
parent 5d00783b02
commit 04e272e2c6
2 changed files with 78 additions and 11 deletions

View File

@@ -3,7 +3,7 @@ object CreateDatabaseForm: TCreateDatabaseForm
Top = 0
BorderStyle = bsDialog
Caption = 'Create database ...'
ClientHeight = 135
ClientHeight = 218
ClientWidth = 317
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
@@ -18,7 +18,7 @@ object CreateDatabaseForm: TCreateDatabaseForm
OnShow = FormShow
DesignSize = (
317
135)
218)
PixelsPerInch = 96
TextHeight = 13
object lblDBName: TLabel
@@ -45,6 +45,14 @@ object CreateDatabaseForm: TCreateDatabaseForm
Caption = 'C&ollation:'
FocusControl = comboCollation
end
object lblPreview: TLabel
Left = 8
Top = 138
Width = 178
Height = 13
Anchors = [akLeft, akRight, akBottom]
Caption = 'SQL &preview for CREATE DATABASE:'
end
object editDBName: TEdit
Left = 88
Top = 16
@@ -100,5 +108,29 @@ object CreateDatabaseForm: TCreateDatabaseForm
ItemHeight = 13
Sorted = True
TabOrder = 2
OnChange = Modified
end
object SynMemoPreview: TSynMemo
Left = 8
Top = 154
Width = 301
Height = 56
SingleLineMode = False
Anchors = [akLeft, akRight, akBottom]
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
TabOrder = 5
Gutter.Font.Charset = DEFAULT_CHARSET
Gutter.Font.Color = clWindowText
Gutter.Font.Height = -11
Gutter.Font.Name = 'Courier New'
Gutter.Font.Style = []
Gutter.Visible = False
ReadOnly = True
ScrollBars = ssNone
WordWrap = True
end
end

View File

@@ -4,7 +4,7 @@ interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, db, Registry;
Dialogs, StdCtrls, db, Registry, SynEdit, SynMemo;
type
TCreateDatabaseForm = class(TForm)
@@ -16,12 +16,16 @@ type
btnCancel: TButton;
lblCollation: TLabel;
comboCollation: TComboBox;
lblPreview: TLabel;
SynMemoPreview: TSynMemo;
procedure btnOKClick(Sender: TObject);
procedure comboCharsetChange(Sender: TObject);
procedure Modified(Sender: TObject);
procedure editDBNameChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
function GetCreateStatement: String;
private
{ Private declarations }
listCharsets : TStringList;
@@ -63,6 +67,10 @@ begin
end;
comboCollation.Enabled := dsCollations <> nil;
// Setup SynMemoPreview
SynMemoPreview.Highlighter := Mainform.Childwin.SynSQLSyn1;
SynMemoPreview.Font := Mainform.Childwin.SynMemoQuery.Font;
end;
@@ -119,6 +127,8 @@ begin
comboCharsetChange( Sender );
end;
// Invoke SQL preview
Modified(Sender);
end;
@@ -158,6 +168,9 @@ begin
comboCollation.ItemIndex := 0;
comboCollation.Items.EndUpdate;
// Invoke SQL preview
Modified(Sender);
end;
@@ -177,6 +190,9 @@ begin
editDBName.Color := clYellow;
btnOK.Enabled := False;
end;
// Invoke SQL preview
Modified(Sender);
end;
@@ -189,14 +205,7 @@ var
begin
if modifyDB = '' then
begin
sql := 'CREATE DATABASE ' + Mainform.Childwin.mask( editDBName.Text );
if comboCharset.Enabled and (comboCharset.Text <> '') then
begin
sql := sql + ' /*!40100 CHARACTER SET ' + comboCharset.Text;
if comboCollation.Enabled and (comboCollation.Text <> '') then
sql := sql + ' COLLATE ' + comboCollation.Text;
sql := sql + ' */';
end;
sql := GetCreateStatement;
Try
Mainform.Childwin.ExecUpdateQuery( sql );
// Close form
@@ -234,6 +243,32 @@ begin
end;
{**
Called on each change
}
procedure TCreateDatabaseForm.Modified(Sender: TObject);
begin
SynMemoPreview.Clear;
SynMemoPreview.Text := GetCreateStatement;
end;
{**
Generate CREATE DATABASE statement, used for preview and execution
}
function TCreateDatabaseForm.GetCreateStatement: String;
begin
Result := 'CREATE DATABASE ' + Mainform.Childwin.mask( editDBName.Text );
if comboCharset.Enabled and (comboCharset.Text <> '') then
begin
Result := Result + ' /*!40100 CHARACTER SET ' + comboCharset.Text;
if comboCollation.Enabled and (comboCollation.Text <> '') then
Result := Result + ' COLLATE ' + comboCollation.Text;
Result := Result + ' */';
end;
end;
{**
Form gets closed: Reset potential modifyDB-value.
}