From: Steven M. <sr...@us...> - 2005-08-26 07:16:04
|
Update of /cvsroot/instantobjects/Source/Brokers/BDE In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26345/Brokers/BDE Modified Files: InstantBDE.pas InstantBDEConnectionDefEdit.dfm InstantBDEConnectionDefEdit.pas Log Message: Added BDE catalog and updated BDE broker. Still not a SQL broker so no external Part(s), etc allowed. Only tested with Paradox database type. Index: InstantBDEConnectionDefEdit.dfm =================================================================== RCS file: /cvsroot/instantobjects/Source/Brokers/BDE/InstantBDEConnectionDefEdit.dfm,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** InstantBDEConnectionDefEdit.dfm 24 Jul 2005 16:34:49 -0000 1.4 --- InstantBDEConnectionDefEdit.dfm 26 Aug 2005 07:15:53 -0000 1.5 *************** *** 1,8 **** object InstantBDEConnectionDefEditForm: TInstantBDEConnectionDefEditForm ! Left = 207 ! Top = 248 BorderStyle = bsDialog Caption = 'BDE Connection' ! ClientHeight = 351 ClientWidth = 392 Color = clBtnFace --- 1,8 ---- object InstantBDEConnectionDefEditForm: TInstantBDEConnectionDefEditForm ! Left = 89 ! Top = 439 BorderStyle = bsDialog Caption = 'BDE Connection' ! ClientHeight = 369 ClientWidth = 392 Color = clBtnFace *************** *** 19,23 **** object BottomBevel: TBevel Left = 0 ! Top = 314 Width = 392 Height = 2 --- 19,23 ---- object BottomBevel: TBevel Left = 0 ! Top = 332 Width = 392 Height = 2 *************** *** 29,33 **** Top = 0 Width = 392 ! Height = 314 Align = alClient BevelOuter = bvNone --- 29,33 ---- Top = 0 Width = 392 ! Height = 332 Align = alClient BevelOuter = bvNone *************** *** 42,46 **** end object DriverLabel: TLabel ! Left = 163 Top = 12 Width = 28 --- 42,46 ---- end object DriverLabel: TLabel ! Left = 164 Top = 12 Width = 28 *************** *** 51,55 **** object ParametersLabel: TLabel Left = 12 ! Top = 56 Width = 53 Height = 13 --- 51,55 ---- object ParametersLabel: TLabel Left = 12 ! Top = 60 Width = 53 Height = 13 *************** *** 58,63 **** end object StreamFormatLabel: TLabel ! Left = 172 ! Top = 288 Width = 53 Height = 13 --- 58,63 ---- end object StreamFormatLabel: TLabel ! Left = 12 ! Top = 285 Width = 53 Height = 13 *************** *** 65,68 **** --- 65,84 ---- FocusControl = StreamFormatComboBox end + object Label1: TLabel + Left = 148 + Top = 285 + Width = 62 + Height = 13 + Caption = 'Id Data Type' + FocusControl = IdDataTypeComboBox + end + object Label2: TLabel + Left = 287 + Top = 285 + Width = 32 + Height = 13 + Caption = 'Id Size' + FocusControl = IdDataTypeComboBox + end object AliasComboBox: TComboBox Left = 12 *************** *** 78,84 **** end object DriverComboBox: TComboBox ! Left = 163 Top = 28 ! Width = 222 Height = 21 Style = csDropDownList --- 94,100 ---- end object DriverComboBox: TComboBox ! Left = 164 Top = 28 ! Width = 213 Height = 21 Style = csDropDownList *************** *** 91,95 **** object ParametersEdit: TMemo Left = 12 ! Top = 72 Width = 365 Height = 201 --- 107,111 ---- object ParametersEdit: TMemo Left = 12 ! Top = 76 Width = 365 Height = 201 *************** *** 100,106 **** end object StreamFormatComboBox: TComboBox ! Left = 232 ! Top = 284 ! Width = 145 Height = 21 Style = csDropDownList --- 116,122 ---- end object StreamFormatComboBox: TComboBox ! Left = 12 ! Top = 301 ! Width = 120 Height = 21 Style = csDropDownList *************** *** 112,126 **** end object LoginPromptCheckBox: TCheckBox ! Left = 16 ! Top = 286 ! Width = 142 Height = 17 Caption = '&Login Prompt' TabOrder = 3 end end object BottomPanel: TPanel Left = 0 ! Top = 316 Width = 392 Height = 35 --- 128,158 ---- end object LoginPromptCheckBox: TCheckBox ! Left = 272 ! Top = 54 ! Width = 105 Height = 17 Caption = '&Login Prompt' TabOrder = 3 end + object IdDataTypeComboBox: TComboBox + Left = 148 + Top = 301 + Width = 120 + Height = 21 + Style = csDropDownList + ItemHeight = 13 + TabOrder = 5 + end + object IdSizeEdit: TEdit + Left = 287 + Top = 301 + Width = 90 + Height = 21 + TabOrder = 6 + end end object BottomPanel: TPanel Left = 0 ! Top = 334 Width = 392 Height = 35 Index: InstantBDEConnectionDefEdit.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Brokers/BDE/InstantBDEConnectionDefEdit.pas,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InstantBDEConnectionDefEdit.pas 24 Jul 2005 16:34:49 -0000 1.3 --- InstantBDEConnectionDefEdit.pas 26 Aug 2005 07:15:53 -0000 1.4 *************** *** 25,29 **** * * Contributor(s): ! * Carlo Barazzetta, Nando Dessena * * ***** END LICENSE BLOCK ***** *) --- 25,29 ---- * * Contributor(s): ! * Carlo Barazzetta, Nando Dessena, Steven Mitchell * * ***** END LICENSE BLOCK ***** *) *************** *** 55,58 **** --- 55,62 ---- StreamFormatComboBox: TComboBox; LoginPromptCheckBox: TCheckBox; + IdDataTypeComboBox: TComboBox; + IdSizeEdit: TEdit; + Label1: TLabel; + Label2: TLabel; procedure AliasComboBoxChange(Sender: TObject); procedure DriverComboBoxChange(Sender: TObject); *************** *** 77,81 **** uses ! DbTables, InstantPersistence, InstantClasses; const --- 81,85 ---- uses ! DbTables, InstantPersistence, InstantClasses, InstantConsts; const *************** *** 125,129 **** ItemIndex := 0; end; ! AssignInstantStreamFormat(StreamFormatComboBox.Items); //CB end; --- 129,137 ---- ItemIndex := 0; end; ! AssignInstantStreamFormat(StreamFormatComboBox.Items); ! AssignInstantDataTypeStrings(IdDataTypeComboBox.Items); ! IdDataTypeComboBox.ItemIndex := Ord(dtString); ! IdSizeEdit.Text := IntToStr(InstantDefaultFieldSize); ! UpdateControls; end; *************** *** 203,211 **** else AliasName := Alias; ! //CB BlobStreamFormat := TInstantStreamFormat(StreamFormatComboBox.ItemIndex); LoginPrompt := LoginPromptCheckBox.Checked; - Parameters := ParametersEdit.Text; end; end; --- 211,220 ---- else AliasName := Alias; ! BlobStreamFormat := TInstantStreamFormat(StreamFormatComboBox.ItemIndex); LoginPrompt := LoginPromptCheckBox.Checked; Parameters := ParametersEdit.Text; + IdDataType := TInstantDataType(IdDataTypeComboBox.ItemIndex); + IdSize := StrToInt(IdSizeEdit.Text); end; end; Index: InstantBDE.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Brokers/BDE/InstantBDE.pas,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** InstantBDE.pas 24 Jul 2005 16:34:49 -0000 1.4 --- InstantBDE.pas 26 Aug 2005 07:15:53 -0000 1.5 *************** *** 25,29 **** * * Contributor(s): ! * Carlo Barazzetta, Nando Dessena * * ***** END LICENSE BLOCK ***** *) --- 25,29 ---- * * Contributor(s): ! * Carlo Barazzetta, Nando Dessena, Steven Mitchell * * ***** END LICENSE BLOCK ***** *) *************** *** 34,38 **** {$IFDEF D6+} ! {$WARN SYMBOL_PLATFORM OFF} {$ENDIF} --- 34,38 ---- {$IFDEF D6+} ! {$WARN SYMBOL_PLATFORM OFF} {$ENDIF} *************** *** 40,44 **** uses ! Classes, Db, DBTables, SysUtils, InstantPersistence, InstantCommand; type --- 40,45 ---- uses ! Classes, Db, DBTables, SysUtils, InstantPersistence, InstantCommand, ! InstantConsts; type *************** *** 75,78 **** --- 76,80 ---- function GetDatabaseName: string; override; function GetDBMSName: string; override; + function GetDDLTransactionSupported: Boolean; override; procedure InternalBuildDatabase(Scheme: TInstantScheme); override; procedure InternalCommitTransaction; override; *************** *** 87,97 **** end; ! TInstantBDEBroker = class(TInstantRelationalBroker) private function GetConnector: TInstantBDEConnector; protected function CreateResolver(const TableName: string): TInstantResolver; override; function InternalCreateQuery: TInstantQuery; override; public property Connector: TInstantBDEConnector read GetConnector; end; --- 89,103 ---- end; ! TInstantBDEBroker = class(TInstantNavigationalBroker) private function GetConnector: TInstantBDEConnector; protected + function CreateCatalog(const AScheme: TInstantScheme): TInstantCatalog; + override; function CreateResolver(const TableName: string): TInstantResolver; override; function InternalCreateQuery: TInstantQuery; override; public + function CreateDBBuildCommand(const CommandType: TInstantDBBuildCommandType): + TInstantDBBuildCommand; override; property Connector: TInstantBDEConnector read GetConnector; end; *************** *** 128,132 **** end; ! TInstantBDEQuery = class(TInstantRelationalQuery) private FQuery: TQuery; --- 134,138 ---- end; ! TInstantBDEQuery = class(TInstantNavigationalQuery) private FQuery: TQuery; *************** *** 147,155 **** end; procedure Register; implementation uses ! Bde, InstantConsts, InstantBDEConnectionDefEdit, Controls; procedure Register; --- 153,221 ---- end; + // Base class for all steps that work by executing one or more commands + // (that is, a script) each. + TInstantDBBuildBDECommand = class(TInstantDBBuildCommand) + private + function GetConnector: TInstantBDEConnector; + function GetBroker: TInstantBDEBroker; + protected + // Returns The number of statements that compound this script. The + // predefined implementation returns 1. + function GetCommandCount: Integer; virtual; + // Returns the nth command that is part of this script. Valid values + // are in the range 0 to Pred(GetCommandCount). The default + // implementation, which should always be called through inherited at the + // beginning of the overridden version, just returns '', or raises an + // exception if Index is not in the allowed range. + function GetCommand(const Index: Integer): string; virtual; + public + property Connector: TInstantBDEConnector read GetConnector; + property Broker: TInstantBDEBroker read GetBroker; + end; + + TInstantDBBuildBDEAddTableCommand = class(TInstantDBBuildBDECommand) + private + function GetTableMetadata: TInstantTableMetadata; + protected + procedure InternalExecute; override; + public + property TableMetadata: TInstantTableMetadata read GetTableMetadata; + end; + + TInstantDBBuildBDEDropTableCommand = class(TInstantDBBuildBDECommand) + private + function GetTableMetadata: TInstantTableMetadata; + protected + procedure InternalExecute; override; + public + property TableMetadata: TInstantTableMetadata read GetTableMetadata; + end; + + TInstantDBBuildBDEAddIndexCommand = class(TInstantDBBuildBDECommand) + private + function GetIndexMetadata: TInstantIndexMetadata; + protected + procedure InternalExecute; override; + public + property IndexMetadata: TInstantIndexMetadata read GetIndexMetadata; + end; + + TInstantDBBuildBDEDropIndexCommand = class(TInstantDBBuildBDECommand) + private + function GetIndexMetadata: TInstantIndexMetadata; + protected + procedure InternalExecute; override; + public + property IndexMetadata: TInstantIndexMetadata read GetIndexMetadata; + end; + procedure Register; implementation uses ! Bde, Controls, InstantBDEConnectionDefEdit, InstantBDECatalog; ! ! resourcestring ! SCommandIndexOutOfBounds = 'Command index out of bounds.'; procedure Register; *************** *** 282,285 **** --- 348,356 ---- end; + function TInstantBDEConnector.GetDDLTransactionSupported: Boolean; + begin + Result := False; + end; + function TInstantBDEConnector.GetDriverType: TInstantBDEDriverType; begin *************** *** 373,376 **** --- 444,468 ---- end; + function TInstantBDEBroker.CreateCatalog(const AScheme: TInstantScheme): + TInstantCatalog; + begin + Result := TInstantBDECatalog.Create(AScheme, Self); + end; + + function TInstantBDEBroker.CreateDBBuildCommand(const CommandType: + TInstantDBBuildCommandType): TInstantDBBuildCommand; + begin + if CommandType = ctAddTable then + Result := TInstantDBBuildBDEAddTableCommand.Create(CommandType, Connector) + else if CommandType = ctDropTable then + Result := TInstantDBBuildBDEDropTableCommand.Create(CommandType, Connector) + else if CommandType = ctAddIndex then + Result := TInstantDBBuildBDEAddIndexCommand.Create(CommandType, Connector) + else if CommandType = ctDropIndex then + Result := TInstantDBBuildBDEDropIndexCommand.Create(CommandType, Connector) + else + Result := inherited CreateDBBuildCommand(CommandType); + end; + { TInstantBDEBroker } *************** *** 604,607 **** --- 696,864 ---- end; + { TInstantDBBuildSQLCommand } + + function TInstantDBBuildBDECommand.GetBroker: TInstantBDEBroker; + begin + Result := Connector.Broker as TInstantBDEBroker; + end; + + function TInstantDBBuildBDECommand.GetConnector: TInstantBDEConnector; + begin + Result := inherited Connector as TInstantBDEConnector; + end; + + function TInstantDBBuildBDECommand.GetCommand(const Index: Integer): string; + begin + if (Index < 0) or (Index >= GetCommandCount) then + raise EInstantDBBuildError.CreateFmt(SCommandIndexOutOfBounds, + [Index]); + Result := ''; + end; + + function TInstantDBBuildBDECommand.GetCommandCount: Integer; + begin + Result := 1; + end; + + function TInstantDBBuildBDEAddTableCommand.GetTableMetadata: + TInstantTableMetadata; + begin + Result := NewMetadata as TInstantTableMetadata; + end; + + procedure TInstantDBBuildBDEAddTableCommand.InternalExecute; + const + FieldTypes: array[TInstantDataType] of TFieldType = + (ftInteger, ftFloat, ftCurrency, ftBoolean, ftString, ftMemo, ftDateTime, ftBlob); + var + I: Integer; + Table: TTable; + IndexName: string; + begin + Table := TTable.Create(nil); + try + Table.TableName := TableMetadata.Name; + Table.DatabaseName := Connector.Connection.DatabaseName; + with TableMetadata do + begin + for I := 0 to Pred(FieldMetadatas.Count) do + with FieldMetadatas[I] do + if FieldTypes[DataType] in [ftString, ftMemo, ftBlob] then + Table.FieldDefs.Add(Name, FieldTypes[DataType], Size, + foRequired in Options) + else + Table.FieldDefs.Add(Name, FieldTypes[DataType], 0, + foRequired in Options); + + Table.IndexDefs.Clear; + for I := 0 to Pred(IndexMetadatas.Count) do + // Only add the primary index here + if ixPrimary in IndexMetadatas[I].Options then + begin + IndexName := IndexMetadatas[I].Name; + if IndexName = '' then + IndexName := Table.TableName + '_' + 'ID'; + with Table.IndexDefs.AddIndexDef do + begin + Name := IndexName; + Fields := IndexMetadatas[I].Fields; + Options := IndexMetadatas[I].Options; + end; + end; + end; + Table.CreateTable; + finally + Table.Free; + end; + end; + + function TInstantDBBuildBDEDropTableCommand.GetTableMetadata: + TInstantTableMetadata; + begin + Result := OldMetadata as TInstantTableMetadata; + end; + + procedure TInstantDBBuildBDEDropTableCommand.InternalExecute; + var + Table: TTable; + begin + Table := TTable.Create(nil); + try + Table.TableName := TableMetadata.Name; + Table.DatabaseName := Connector.Connection.DatabaseName; + Table.Close; + Table.DeleteTable; + finally + Table.Free; + end; + end; + + { TInstantDBBuildAddIndexSQLCommand } + + function TInstantDBBuildBDEAddIndexCommand.GetIndexMetadata: + TInstantIndexMetadata; + begin + Result := NewMetadata as TInstantIndexMetadata; + end; + + procedure TInstantDBBuildBDEAddIndexCommand.InternalExecute; + var + Table: TTable; + begin + Table := TTable.Create(nil); + try + Table.TableName := IndexMetadata.TableMetadata.Name; + Table.DatabaseName := Connector.Connection.DatabaseName; + with IndexMetadata do + begin + if not (ixPrimary in Options) then + begin + if (Connector.DriverType = dtStandard) and (Pos(';', Fields) = 0) then + // Name of a non-composite index must the be field name for Paradox. + Name := Fields; + Table.AddIndex(Name, Fields, Options); + end; + end; + finally + Table.Free; + end; + end; + + { TInstantDBBuildAddIndexSQLCommand } + + function TInstantDBBuildBDEDropIndexCommand.GetIndexMetadata: + TInstantIndexMetadata; + begin + Result := OldMetadata as TInstantIndexMetadata; + end; + + procedure TInstantDBBuildBDEDropIndexCommand.InternalExecute; + var + Table: TTable; + + function RemoveTableNamePrefix(const AName, ATableName: String): String; + begin + Result := AName; + if Pos(ATableName, Result) = 1 then + Result := Copy(Result, 1 + Length(ATableName), Length(Result)); + end; + begin + Table := TTable.Create(nil); + try + Table.TableName := IndexMetadata.TableMetadata.Name; + Table.DatabaseName := Connector.Connection.DatabaseName; + Table.Exclusive := True; + Table.Open; + with IndexMetadata do + if not (ixPrimary in Options) then + Table.DeleteIndex( + RemoveTableNamePrefix(Name, IndexMetadata.TableMetadata.Name)); + Table.Close; + finally + Table.Free; + end; + end; + + initialization RegisterClass(TInstantBDEConnectionDef); |