diff --git a/tools/lazdatadesktop/conneditor.pp b/tools/lazdatadesktop/conneditor.pp index 8649a93b62..8baa9ea1f9 100644 --- a/tools/lazdatadesktop/conneditor.pp +++ b/tools/lazdatadesktop/conneditor.pp @@ -73,7 +73,9 @@ Type Procedure Connect(Connectstring : String); Procedure DisConnect; Function CanCreateCode : Boolean; + Function CanCreateSQL : Boolean; Procedure CreateCode; + Procedure CreateSQL; Property Engine : TFPDDEngine Read FEngine Write SetEngine; Property ObjectType : TObjectType Read GetCurrentObjectType; Property Description : String Read FDescription Write SetDescription; @@ -103,7 +105,7 @@ Const implementation -uses typinfo, datapanel; +uses typinfo, datapanel, frmgeneratesql; { TConnectionEditor } @@ -239,6 +241,50 @@ begin end; end; +function TConnectionEditor.CanCreateSQL: Boolean; +begin + Result:=(ObjectType in [otTable,otFields,otField,otTableData,otIndexDefs]); +end; + +procedure TConnectionEditor.CreateSQL; + +Var + N,PN,PPN : TTreeNode; + TN : String; + TS : TDDTableDefs; + L : TStringList; +begin + N:=FTV.Selected; + If N=Nil then + exit; + If Assigned(N.Parent) then + begin + PN:=N.Parent; + If Assigned(PN) then + PPN:=PN.Parent; + end; + Case ObjectType of + otTable : TN:=N.Text; + otFields, + otTableData, + otIndexDefs : TN:=PN.Text; + otField : TN:=PPN.Text; + end; + TS:=TDDTableDefs.Create(TDDTableDef); + try + L:=TStringList.Create; + try + L.Add(TN); + FEngine.ImportTables(TS,L,True); + finally + L.Free; + end; + TGenerateSQLForm.GenerateSQLDialog(TS,TN,False); + finally + TS.Free; + end; +end; + procedure TConnectionEditor.CreateCode; Var diff --git a/tools/lazdatadesktop/frmgeneratesql.lfm b/tools/lazdatadesktop/frmgeneratesql.lfm index a852f0b994..e229445f70 100644 --- a/tools/lazdatadesktop/frmgeneratesql.lfm +++ b/tools/lazdatadesktop/frmgeneratesql.lfm @@ -8,7 +8,7 @@ object GenerateSQLForm: TGenerateSQLForm ClientHeight = 395 ClientWidth = 812 OnCreate = FormCreate - LCLVersion = '0.9.29' + LCLVersion = '1.1' object PCSQL: TPageControl Left = 0 Height = 359 @@ -25,17 +25,17 @@ object GenerateSQLForm: TGenerateSQLForm ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.ControlsPerLine = 3 - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 804 OnResize = TSResize object POptions: TPanel Left = 0 - Height = 333 + Height = 325 Top = 0 Width = 254 Align = alLeft BevelOuter = bvNone - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 254 Constraints.MinWidth = 180 TabOrder = 0 @@ -76,11 +76,11 @@ object GenerateSQLForm: TGenerateSQLForm end object CBTables: TComboBox Left = 4 - Height = 21 + Height = 24 Top = 26 Width = 238 Anchors = [akTop, akLeft, akRight] - ItemHeight = 13 + ItemHeight = 0 OnChange = CBTablesChange Sorted = True Style = csDropDownList @@ -89,7 +89,7 @@ object GenerateSQLForm: TGenerateSQLForm object BGenerate: TButton Left = 4 Height = 25 - Top = 304 + Top = 296 Width = 238 Anchors = [akLeft, akRight, akBottom] BorderSpacing.InnerBorder = 4 @@ -100,7 +100,7 @@ object GenerateSQLForm: TGenerateSQLForm end object SEindent: TTISpinEdit Left = 204 - Height = 21 + Height = 18 Top = 202 Width = 34 Anchors = [akTop, akRight] @@ -109,7 +109,7 @@ object GenerateSQLForm: TGenerateSQLForm end object SELineLength: TTISpinEdit Left = 205 - Height = 21 + Height = 18 Top = 231 Width = 34 Anchors = [akTop, akRight] @@ -135,9 +135,9 @@ object GenerateSQLForm: TGenerateSQLForm end object CBIgnoreSelection: TCheckBox Left = 6 - Height = 17 + Height = 26 Top = 257 - Width = 159 + Width = 170 Caption = 'Create full table creation SQL' TabOrder = 5 end @@ -147,12 +147,12 @@ object GenerateSQLForm: TGenerateSQLForm AnchorSideLeft.Side = asrBottom AnchorSideRight.Control = PSelectFields Left = 254 - Height = 333 + Height = 325 Top = 0 Width = 262 Align = alClient BevelOuter = bvNone - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 262 TabOrder = 1 object LLBKeyFields: TLabel @@ -169,24 +169,26 @@ object GenerateSQLForm: TGenerateSQLForm end object LBKeyFields: TListBox Left = 2 - Height = 288 + Height = 280 Top = 34 Width = 256 Anchors = [akTop, akLeft, akRight, akBottom] ItemHeight = 0 MultiSelect = True + ScrollWidth = 252 Sorted = True TabOrder = 0 + TopIndex = -1 end end object PSelectFields: TPanel Left = 516 - Height = 333 + Height = 325 Top = 0 Width = 288 Align = alRight BevelOuter = bvNone - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 288 TabOrder = 2 object Label2: TLabel @@ -203,20 +205,22 @@ object GenerateSQLForm: TGenerateSQLForm end object LBFields: TListBox Left = 12 - Height = 288 + Height = 280 Top = 34 Width = 266 Anchors = [akTop, akLeft, akRight, akBottom] ItemHeight = 0 MultiSelect = True + ScrollWidth = 262 Sorted = True TabOrder = 0 + TopIndex = -1 end end end object TSSelect: TTabSheet Caption = '&Select' - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 804 object MSelect: TMemo Left = 8 @@ -233,7 +237,7 @@ object GenerateSQLForm: TGenerateSQLForm end object TSInsert: TTabSheet Caption = '&Insert' - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 804 object MInsert: TMemo Left = 8 @@ -250,7 +254,7 @@ object GenerateSQLForm: TGenerateSQLForm end object TSUpdate: TTabSheet Caption = '&Update' - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 804 object MUpdate: TMemo Left = 8 @@ -267,7 +271,7 @@ object GenerateSQLForm: TGenerateSQLForm end object TSDelete: TTabSheet Caption = '&Delete' - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 804 object MDelete: TMemo Left = 8 @@ -284,7 +288,7 @@ object GenerateSQLForm: TGenerateSQLForm end object TSCreate: TTabSheet Caption = 'Create table' - ClientHeight = 333 + ClientHeight = 325 ClientWidth = 804 object MCreate: TMemo Left = 8 diff --git a/tools/lazdatadesktop/frmgeneratesql.pp b/tools/lazdatadesktop/frmgeneratesql.pp index f0f7bdaa5e..dd1489b327 100644 --- a/tools/lazdatadesktop/frmgeneratesql.pp +++ b/tools/lazdatadesktop/frmgeneratesql.pp @@ -72,9 +72,11 @@ type FTableDefs : TDDTableDefs; FGenerator : TFPDDSQLEngine; FSQLGenerated : Boolean; + function GetAS: Boolean; function GetSQLStatement(Index: integer): TStrings; function GetTableDef: TDDTableDef; function GetTableName: String; + procedure SetAS(AValue: Boolean); procedure SetTableDefs(const AValue: TDDTableDefs); procedure SetTableName(const AValue: String); Procedure SetFieldLists(TD : TDDTableDef); @@ -84,6 +86,7 @@ type Procedure RefreshTableList; Procedure GenerateSQL; Procedure ClearSQL; + Class Function GenerateSQLDialog(TDS : TDDTableDefs; TN : String; AllowChangeTable : Boolean = True) : Boolean; Property TableDefs : TDDTableDefs Read FTableDefs Write SetTableDefs; Property TableName : String Read GetTableName Write SetTableName; Property SelectSQL : TStrings Index 0 Read GetSQLStatement; @@ -92,13 +95,29 @@ type Property DeleteSQL : TStrings Index 3 Read GetSQLStatement; Property CreateSQL : TStrings Index 4 Read GetSQLStatement; Property TableDef : TDDTableDef Read GetTableDef; + Property AllowSelectTable : Boolean Read GetAS Write SetAS; end; var GenerateSQLForm: TGenerateSQLForm; + implementation +Class Function TGenerateSQLFOrm.GenerateSQLDialog(TDS : TDDTableDefs; TN : String; AllowChangeTable : Boolean = True) : Boolean; + +begin + With TGenerateSQLFOrm.Create(Application) do + try + TableDefs:=TDS; + TableName:=TN; + AllowSelectTable:=AllowChangeTable; + Result:=ShowModal=mroK; + Finally + Free; + end; +end; + {$R *.lfm} { TGenerateSQLForm } @@ -127,6 +146,11 @@ begin Result:=CBTables.Text; end; +procedure TGenerateSQLForm.SetAS(AValue: Boolean); +begin + CBTables.Enabled:=AValue; +end; + function TGenerateSQLForm.GetSQLStatement(Index: integer): TStrings; begin Case Index of @@ -138,6 +162,11 @@ begin end; end; +function TGenerateSQLForm.GetAS: Boolean; +begin + Result:=CBTables.Enabled; +end; + function TGenerateSQLForm.GetTableDef: TDDTableDef; begin With CBTables do diff --git a/tools/lazdatadesktop/frmmain.lfm b/tools/lazdatadesktop/frmmain.lfm index 8cfb13a8ab..5618d6b73e 100644 --- a/tools/lazdatadesktop/frmmain.lfm +++ b/tools/lazdatadesktop/frmmain.lfm @@ -5,7 +5,7 @@ object MainForm: TMainForm Width = 666 ActiveControl = PCDD Caption = 'Lazarus Database Desktop' - ClientHeight = 453 + ClientHeight = 464 ClientWidth = 666 Menu = MainMenu1 OnClose = FormClose @@ -110,7 +110,7 @@ object MainForm: TMainForm end object PCDD: TPageControl Left = 0 - Height = 407 + Height = 418 Top = 26 Width = 666 ActivePage = TSRecent @@ -119,13 +119,13 @@ object MainForm: TMainForm TabOrder = 1 object TSRecent: TTabSheet Caption = 'Dictionaries' - ClientHeight = 374 - ClientWidth = 662 + ClientHeight = 384 + ClientWidth = 658 object LVDicts: TListView Left = 0 - Height = 374 + Height = 384 Top = 0 - Width = 662 + Width = 658 Align = alClient Columns = < item @@ -138,7 +138,7 @@ object MainForm: TMainForm end item Caption = 'Last used on' - Width = 487 + Width = 617 end> PopupMenu = PMDataDict ReadOnly = True @@ -152,8 +152,8 @@ object MainForm: TMainForm end object TSConnections: TTabSheet Caption = 'Connections' - ClientHeight = 374 - ClientWidth = 662 + ClientHeight = 384 + ClientWidth = 658 object LVConnections: TListView Left = 0 Height = 374 @@ -191,7 +191,7 @@ object MainForm: TMainForm object PStatus: TPanel Left = 0 Height = 20 - Top = 433 + Top = 444 Width = 666 Align = alBottom BevelOuter = bvNone @@ -910,7 +910,7 @@ object MainForm: TMainForm Hint = 'Generate SQL statements for the current table' ImageIndex = 7 OnExecute = AGenerateSQLExecute - OnUpdate = HaveTables + OnUpdate = AllowSQL ShortCut = 16455 end object ASaveAs: TAction diff --git a/tools/lazdatadesktop/frmmain.pp b/tools/lazdatadesktop/frmmain.pp index 5540872b42..b3139519d0 100644 --- a/tools/lazdatadesktop/frmmain.pp +++ b/tools/lazdatadesktop/frmmain.pp @@ -159,6 +159,7 @@ type procedure ADeleteRecentDataDictExecute(Sender: TObject); procedure AExitExecute(Sender: TObject); procedure AGenerateSQLExecute(Sender: TObject); + procedure AllowSQL(Sender: TObject); procedure ANewConnectionExecute(Sender: TObject); procedure ANewExecute(Sender: TObject); procedure ANewFieldExecute(Sender: TObject); @@ -263,6 +264,8 @@ uses fpddmysql40, // MySQL 4.0 fpddmysql41, // MySQL 4.1 fpddmysql50, // MySQL 5.0 + fpddmysql51, // MySQL 5.1 + fpddmysql55, // MySQL 5.5 fpddoracle, // Oracle fpddpq, // PostgreSQL {$endif} @@ -472,6 +475,8 @@ begin RegisterMySQL40DDEngine; RegisterMySQL41DDEngine; RegisterMySQL50DDEngine; + RegisterMySQL51DDEngine; + RegisterMySQL55DDEngine; RegisterOracleDDEngine; RegisterPostgreSQLDDengine; {$endif} @@ -499,6 +504,8 @@ begin MaybeRegisterConnectionStringCallback('TSQLDBMySql40DDEngine',@GetSQLConnectionDlg); MaybeRegisterConnectionStringCallback('TSQLDBMySql41DDEngine',@GetSQLConnectionDlg); MaybeRegisterConnectionStringCallback('TSQLDBMySql5DDEngine',@GetSQLConnectionDlg); + MaybeRegisterConnectionStringCallback('TSQLDBMySql51DDEngine',@GetSQLConnectionDlg); + MaybeRegisterConnectionStringCallback('TSQLDBMySql55DDEngine',@GetSQLConnectionDlg); MaybeRegisterConnectionStringCallback('TSQLDBODBCDDEngine',@GetSQLConnectionDlg); MaybeRegisterConnectionStringCallback('TSQLDBPOSTGRESQLDDEngine',@GetSQLConnectionDlg); MaybeRegisterConnectionStringCallback('TSQLDBFBDDEngine',@GetSQLConnectionDlg); @@ -787,6 +794,18 @@ begin ShowGenerateSQL; end; +procedure TMainForm.AllowSQL(Sender: TObject); + +Var + B : Boolean; + +begin + B:=Assigned(CurrentEditor) and (CurrentEditor.DataDictionary.Tables.Count>0); + If not B then + B:=Assigned(CurrentConnection) and CurrentConnection.CanCreateSQL; + (Sender as TAction).Enabled:=B; +end; + procedure TMainForm.ANewConnectionExecute(Sender: TObject); begin NewConnection; @@ -1209,16 +1228,18 @@ end; procedure TMainForm.ShowGenerateSQL; +Var + TN : String; + begin - With TGenerateSQLFOrm.Create(Self) do - try - TableDefs:=CurrentEditor.DataDictionary.Tables; - If CurrentEditor.CurrentTable<>Nil then - TableName:=CurrentEditor.CurrentTable.TableName; - ShowModal; - Finally - Free; - end; + if Assigned(CurrentConnection) then + CurrentConnection.CreateSQL + else + begin + If CurrentEditor.CurrentTable<>Nil then + TN:=CurrentEditor.CurrentTable.TableName; + TGenerateSQLForm.GenerateSQLDialog(CurrentEditor.DataDictionary.Tables,TN,True); + end end; procedure TMainForm.DeleteCurrentObject; diff --git a/tools/lazdatadesktop/lazdatadesktop.lpi b/tools/lazdatadesktop/lazdatadesktop.lpi index b4937b28b1..e630ab77b7 100644 --- a/tools/lazdatadesktop/lazdatadesktop.lpi +++ b/tools/lazdatadesktop/lazdatadesktop.lpi @@ -1,7 +1,7 @@ - + @@ -9,16 +9,15 @@ - <UseXPManifest Value="True"/> </General> <i18n> <OutDir Value="languages"/> </i18n> - <VersionInfo> - <StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion="0.0.0.0"/> - </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="default" Default="True"/> + </BuildModes> <PublishOptions> <Version Value="2"/> <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> @@ -64,6 +63,7 @@ <Filename Value="frmmain.pp"/> <IsPartOfProject Value="True"/> <ComponentName Value="MainForm"/> + <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> <UnitName Value="frmmain"/> </Unit1> @@ -76,6 +76,7 @@ <Filename Value="frmimportdd.pp"/> <IsPartOfProject Value="True"/> <ComponentName Value="ImportDDform"/> + <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> <UnitName Value="frmimportdd"/> </Unit3> @@ -83,6 +84,7 @@ <Filename Value="frmgeneratesql.pp"/> <IsPartOfProject Value="True"/> <ComponentName Value="GenerateSQLForm"/> + <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> <UnitName Value="frmgeneratesql"/> </Unit4> @@ -132,7 +134,7 @@ </Units> </ProjectOptions> <CompilerOptions> - <Version Value="9"/> + <Version Value="11"/> <Target> <Filename Value="lazdatadesktop"/> </Target>