From: Joao M. <jcm...@us...> - 2005-12-31 11:45:34
|
Update of /cvsroot/instantobjects/Source/Brokers/ZeosDBO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3059/Brokers/ZeosDBO Modified Files: InstantZeosDBO.pas Log Message: Added IbFb and MySQL database creation support for ZeosDBO Broker; Moved string constants from InstantZeosDBO to InstantConsts unit. Index: InstantZeosDBO.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Brokers/ZeosDBO/InstantZeosDBO.pas,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** InstantZeosDBO.pas 22 Nov 2005 23:08:05 -0000 1.6 --- InstantZeosDBO.pas 31 Dec 2005 11:45:24 -0000 1.7 *************** *** 25,29 **** * * Contributor(s): ! * Enrique Esquivel * * ***** END LICENSE BLOCK ***** *) --- 25,29 ---- * * Contributor(s): ! * Enrique Esquivel, David Taylor * * ***** END LICENSE BLOCK ***** *) *************** *** 84,87 **** --- 84,89 ---- end; + TInstantZeosDBOBroker = class; + TInstantZeosDBOConnector = class(TInstantRelationalConnector) private *************** *** 97,100 **** --- 99,103 ---- procedure SetLoginPrompt(const Value: Boolean); procedure SetUseDelimitedIdents(const Value: Boolean); + function GetBroker: TInstantZeosDBOBroker; protected procedure AfterConnectionChange; virtual; *************** *** 118,121 **** --- 121,125 ---- class function ConnectionDefClass: TInstantConnectionDefClass; override; function HasConnection: Boolean; + property Broker: TInstantZeosDBOBroker read GetBroker; published property Connection: TZConnection read GetConnection write SetConnection; *************** *** 138,154 **** function GetSQLDelimiters: string; override; function GetSQLQuote: Char; override; function InternalCreateQuery: TInstantQuery; override; function InternalDataTypeToColumnType(DataType: TInstantDataType): string; virtual; abstract; function UseBooleanFields: Boolean; virtual; abstract; public function CreateDataSet(const AStatement: string; AParams: TParams = nil): TDataSet; override; function CreateDBBuildCommand(const CommandType: TInstantDBBuildCommandType): TInstantDBBuildCommand; override; function DataTypeToColumnType(DataType: TInstantDataType; Size: Integer): string; override; function Execute(const AStatement: string; AParams: TParams = nil): Integer; override; property Connector: TInstantZeosDBOConnector read GetConnector; end; TInstantZeosDBOResolver = class(TInstantSQLResolver) ! // Read an integer field and convert it to boolean expression protected function ReadBooleanField(DataSet: TDataSet; const FieldName: string): Boolean; override; --- 142,162 ---- function GetSQLDelimiters: string; override; function GetSQLQuote: Char; override; + procedure InternalCreateDatabase; virtual; function InternalCreateQuery: TInstantQuery; override; function InternalDataTypeToColumnType(DataType: TInstantDataType): string; virtual; abstract; + function InternalDBNotExistsErrorCode: Integer; virtual; function UseBooleanFields: Boolean; virtual; abstract; public + procedure CreateDatabase; function CreateDataSet(const AStatement: string; AParams: TParams = nil): TDataSet; override; function CreateDBBuildCommand(const CommandType: TInstantDBBuildCommandType): TInstantDBBuildCommand; override; function DataTypeToColumnType(DataType: TInstantDataType; Size: Integer): string; override; function Execute(const AStatement: string; AParams: TParams = nil): Integer; override; + function DBNotExistsErrorCode: Integer; property Connector: TInstantZeosDBOConnector read GetConnector; end; TInstantZeosDBOResolver = class(TInstantSQLResolver) ! // Read an integer field and convert it to boolean expression protected function ReadBooleanField(DataSet: TDataSet; const FieldName: string): Boolean; override; *************** *** 156,160 **** TInstantZeosDBOTranslator = class(TInstantRelationalTranslator) ! // Translate boolean expressions to '0' or '1' protected function TranslateConstant(Constant: TInstantIQLConstant; Writer: TInstantIQLWriter): Boolean; override; --- 164,168 ---- TInstantZeosDBOTranslator = class(TInstantRelationalTranslator) ! // Translate boolean expressions to '0' or '1' protected function TranslateConstant(Constant: TInstantIQLConstant; Writer: TInstantIQLWriter): Boolean; override; *************** *** 191,195 **** --- 199,205 ---- TInstantZeosDBOIbFbBroker = class(TInstantZeosDBOBroker) protected + procedure InternalCreateDatabase; override; function InternalDataTypeToColumnType(DataType: TInstantDataType): string; override; + function InternalDBNotExistsErrorCode: Integer; override; function UseBooleanFields: Boolean; override; end; *************** *** 221,226 **** --- 231,238 ---- TInstantZeosDBOMySQLBroker = class(TInstantZeosDBOBroker) protected + procedure InternalCreateDatabase; override; function InternalDataTypeToColumnType(DataType: TInstantDataType): string; override; + function InternalDBNotExistsErrorCode: Integer; override; function UseBooleanFields: Boolean; override; end; *************** *** 283,287 **** InstantConsts, InstantClasses, InstantZeosDBOConnectionDefEdit, InstantZeosDBOCatalog, InstantUtils, ZClasses, ZCompatibility, ZDbcIntfs, ! ZDataset; {$IFDEF SQLITE_SUPPORT} --- 295,299 ---- InstantConsts, InstantClasses, InstantZeosDBOConnectionDefEdit, InstantZeosDBOCatalog, InstantUtils, ZClasses, ZCompatibility, ZDbcIntfs, ! {$IFDEF MYSQL_SUPPORT}ZDbcMySql,{$ENDIF} ZDataset; {$IFDEF SQLITE_SUPPORT} *************** *** 462,468 **** {$IFDEF IBFB_SUPPORT} if SameText(FConnection.Protocol, 'interbase-5') or ! SameText(FConnection.Protocol, 'interbase-6') or ! SameText(FConnection.Protocol, 'firebird-1.0') or ! SameText(FConnection.Protocol, 'firebird-1.5') then Result := TInstantZeosDBOIbFbBroker.Create(Self); {$ENDIF} --- 474,480 ---- {$IFDEF IBFB_SUPPORT} if SameText(FConnection.Protocol, 'interbase-5') or ! SameText(FConnection.Protocol, 'interbase-6') or ! SameText(FConnection.Protocol, 'firebird-1.0') or ! SameText(FConnection.Protocol, 'firebird-1.5') then Result := TInstantZeosDBOIbFbBroker.Create(Self); {$ENDIF} *************** *** 470,474 **** {$IFDEF ORACLE_SUPPORT} if SameText(FConnection.Protocol, 'oracle') or ! SameText(FConnection.Protocol, 'oracle-9i') then Result := TInstantZeosDBOOracleBroker.Create(Self); {$ENDIF} --- 482,486 ---- {$IFDEF ORACLE_SUPPORT} if SameText(FConnection.Protocol, 'oracle') or ! SameText(FConnection.Protocol, 'oracle-9i') then Result := TInstantZeosDBOOracleBroker.Create(Self); {$ENDIF} *************** *** 476,483 **** {$IFDEF PGSQL_SUPPORT} if SameText(FConnection.Protocol, 'postgresql') or ! SameText(FConnection.Protocol, 'postgresql-6.5') or ! SameText(FConnection.Protocol, 'postgresql-7.2') or ! SameText(FConnection.Protocol, 'postgresql-7.3') or ! SameText(FConnection.Protocol, 'postgresql-7.4') then Result := TInstantZeosDBOPgSQLBroker.Create(Self); {$ENDIF} --- 488,495 ---- {$IFDEF PGSQL_SUPPORT} if SameText(FConnection.Protocol, 'postgresql') or ! SameText(FConnection.Protocol, 'postgresql-6.5') or ! SameText(FConnection.Protocol, 'postgresql-7.2') or ! SameText(FConnection.Protocol, 'postgresql-7.3') or ! SameText(FConnection.Protocol, 'postgresql-7.4') then Result := TInstantZeosDBOPgSQLBroker.Create(Self); {$ENDIF} *************** *** 485,492 **** {$IFDEF MYSQL_SUPPORT} if SameText(FConnection.Protocol, 'mysql') or ! SameText(FConnection.Protocol, 'mysql-3.20') or ! SameText(FConnection.Protocol, 'mysql-3.23') or ! SameText(FConnection.Protocol, 'mysql-4.0') or ! SameText(FConnection.Protocol, 'mysql-4.1') then Result := TInstantZeosDBOMySQLBroker.Create(Self); {$ENDIF} --- 497,504 ---- {$IFDEF MYSQL_SUPPORT} if SameText(FConnection.Protocol, 'mysql') or ! SameText(FConnection.Protocol, 'mysql-3.20') or ! SameText(FConnection.Protocol, 'mysql-3.23') or ! SameText(FConnection.Protocol, 'mysql-4.0') or ! SameText(FConnection.Protocol, 'mysql-4.1') then Result := TInstantZeosDBOMySQLBroker.Create(Self); {$ENDIF} *************** *** 494,504 **** {$IFDEF SQLITE_SUPPORT} if SameText(FConnection.Protocol, 'sqlite') or ! SameText(FConnection.Protocol, 'sqlite-2.8') then Result := TInstantZeosDBOSQLiteBroker.Create(Self); {$ENDIF} if Result = nil then ! raise EInstantError.CreateFmt('ZeosDBO protocol "%s" not supported', ! [FConnection.Protocol]); end; --- 506,516 ---- {$IFDEF SQLITE_SUPPORT} if SameText(FConnection.Protocol, 'sqlite') or ! SameText(FConnection.Protocol, 'sqlite-2.8') then Result := TInstantZeosDBOSQLiteBroker.Create(Self); {$ENDIF} if Result = nil then ! raise EInstantError.CreateFmt(SProtocolNotSupported, ! [FConnection.Protocol]); end; *************** *** 520,523 **** --- 532,542 ---- end; + function TInstantZeosDBOConnector.GetBroker: TInstantZeosDBOBroker; + begin + { TODO : Check if current broker is appropriate + (before FConnection.Protocol). } + Result := inherited Broker as TInstantZeosDBOBroker; + end; + function TInstantZeosDBOConnector.GetConnected: Boolean; begin *************** *** 537,542 **** function TInstantZeosDBOConnector.GetDatabaseExists: Boolean; begin ! { TODO : Implement } ! Result := True; end; --- 556,574 ---- function TInstantZeosDBOConnector.GetDatabaseExists: Boolean; begin ! AssignLoginOptions; ! try ! Connection.Connect; ! Result := True; ! Connection.Disconnect; ! except ! on E : EZSQLException do ! begin ! if (E.ErrorCode = Broker.DBNotExistsErrorCode) then ! Result := False ! else ! raise EZSQLException.CreateWithCode(E.ErrorCode, ! Format('%s. Error Code: %d', [E.Message, E.ErrorCode])); ! end; ! end; end; *************** *** 581,585 **** procedure TInstantZeosDBOConnector.InternalCreateDatabase; begin ! { TODO : Implement } end; --- 613,619 ---- procedure TInstantZeosDBOConnector.InternalCreateDatabase; begin ! if (Connection.Connected) then ! raise EInstantError.Create(SDatabaseOpen); ! Broker.CreateDatabase; end; *************** *** 684,687 **** --- 718,726 ---- end; + procedure TInstantZeosDBOBroker.CreateDatabase; + begin + InternalCreateDatabase; + end; + function TInstantZeosDBOBroker.CreateDataSet(const AStatement: string; AParams: TParams): TDataSet; *************** *** 750,753 **** --- 789,797 ---- end; + function TInstantZeosDBOBroker.DBNotExistsErrorCode: Integer; + begin + Result := InternalDBNotExistsErrorCode; + end; + function TInstantZeosDBOBroker.Execute(const AStatement: string; AParams: TParams): Integer; *************** *** 794,797 **** --- 838,846 ---- end; + procedure TInstantZeosDBOBroker.InternalCreateDatabase; + begin + raise EInstantError.CreateFmt(SDatabaseCreationNotSupported, [GetDBMSName]); + end; + function TInstantZeosDBOBroker.InternalCreateQuery: TInstantQuery; begin *************** *** 802,805 **** --- 851,859 ---- end; + function TInstantZeosDBOBroker.InternalDBNotExistsErrorCode: Integer; + begin + Result := 0; + end; + { TInstantZeosDBOResolver } *************** *** 840,844 **** {$IFDEF SYBASE_SUPPORT} - function TInstantZeosDBOSybaseBroker.InternalDataTypeToColumnType( DataType: TInstantDataType): string; --- 894,897 ---- *************** *** 866,870 **** {$IFDEF MSSQL_SUPPORT} - function TInstantZeosDBOMSSQLBroker.InternalDataTypeToColumnType( DataType: TInstantDataType): string; --- 919,922 ---- *************** *** 892,895 **** --- 944,964 ---- {$IFDEF IBFB_SUPPORT} + procedure TInstantZeosDBOIbFbBroker.InternalCreateDatabase; + begin + // do not call inherited + with Connector.Connection do + begin + Properties.Text := Format( + 'createNewDatabase=CREATE DATABASE ''%s'' ' + + 'USER ''%s'' PASSWORD ''%s'' PAGE_SIZE 4096 ' + + 'DEFAULT CHARACTER SET ISO8859_1', [Database, User, Password]); + try + Connect; + finally + Disconnect; + Properties.Clear; + end; + end; + end; function TInstantZeosDBOIbFbBroker.InternalDataTypeToColumnType( *************** *** 909,912 **** --- 978,986 ---- end; + function TInstantZeosDBOIbFbBroker.InternalDBNotExistsErrorCode: Integer; + begin + Result := -902; + end; + function TInstantZeosDBOIbFbBroker.UseBooleanFields: Boolean; begin *************** *** 918,922 **** {$IFDEF ORACLE_SUPPORT} - function TInstantZeosDBOOracleBroker.InternalDataTypeToColumnType( DataType: TInstantDataType): string; --- 992,995 ---- *************** *** 944,948 **** {$IFDEF PGSQL_SUPPORT} - function TInstantZeosDBOPgSQLBroker.InternalDataTypeToColumnType( DataType: TInstantDataType): string; --- 1017,1020 ---- *************** *** 970,973 **** --- 1042,1067 ---- {$IFDEF MYSQL_SUPPORT} + procedure TInstantZeosDBOMySQLBroker.InternalCreateDatabase; + var + MySqlConnection: IZMySqlConnection; + begin + // do not call inherited + with Connector.Connection do + begin + Properties.Text := 'dbless=TRUE'; + try + Connect; + DbcConnection.QueryInterface(IZMySqlConnection, MySqlConnection); + if Assigned(MySqlConnection) then + MySqlConnection.GetPlainDriver. + CreateDatabase(MySqlConnection.GetConnectionHandle, PChar(Database)) + else + inherited; + finally + Disconnect; + Properties.Clear; + end; + end; + end; function TInstantZeosDBOMySQLBroker.InternalDataTypeToColumnType( *************** *** 987,990 **** --- 1081,1089 ---- end; + function TInstantZeosDBOMySQLBroker.InternalDBNotExistsErrorCode: Integer; + begin + Result := 1049; + end; + function TInstantZeosDBOMySQLBroker.UseBooleanFields: Boolean; begin |