unit uDABDEDriver; {----------------------------------------------------------------------------} { Data Abstract Library - Driver Library { { compiler: Delphi 6 and up { platform: Win32 { { (c)opyright RemObjects Software. all rights reserved. { { Using this code requires a valid license of the Data Abstract { which can be obtained at http://www.remobjects.com. {----------------------------------------------------------------------------} {$I ..\DataAbstract.inc} {$R DataAbstract_BDEDriver_Glyphs.res} {$DEFINE MAX_SUPPORT} interface uses DB, uDAEngine, uDAInterfaces, uROClasses, uDAInterfacesEx, uDAUtils, DBTables, uDAIBInterfaces, uDAADOInterfaces, uDAOracleInterfaces; type TDABDEProviderType = ( bdeSTANDARD, bdeDB2, bdeINFORMIX, bdeINTRBASE, bdeMSACCESS, bdeMSSQL, bdeORACLE, bdeSYBASE, bdeODBC); { TDABDEDriver } TDABDEDriver = class(TDADriverReference) end; { TDAEADODriver } TDAEBDEDriver = class(TDAEDriver, IDADriver40) protected function GetConnectionClass: TDAEConnectionClass; override; // IDADriver function GetDriverID: string; override; function GetDescription: string; override; procedure GetAuxDrivers(out List: IROStrings); override; procedure GetAuxParams(const AuxDriver: string; out List: IROStrings); override; function GetAvailableDriverOptions: TDAAvailableDriverOptions; override; function GetProviderDefaultCustomParameters(Provider: string): string; safecall; function GetDefaultConnectionType(const AuxDriver: string): string; override; safecall; public end; { TDAEADOConnection } TDAEBDEConnection = class(TDAEConnection, IDACanQueryDatabaseNames, IDAFileBasedDatabase, IDADirectoryBasedDatabase, IDAUseGenerators, {IDAADOConnection,} IDAInterbaseConnection, IDAOracleConnection, IDACanQueryGeneratorsNames) private fProviderName: string; fProviderType: TDABDEProviderType; fDatabase: TDataBase; FSession: TSession; protected function QueryInterface(const IID: TGUID; out Obj): HResult; override; stdcall; function CreateCustomConnection: TCustomConnection; override; function CreateMacroProcessor: TDASQLMacroProcessor; override; function GetDatasetClass: TDAEDatasetClass; override; function GetStoredProcedureClass: TDAEStoredProcedureClass; override; procedure DoApplyConnectionString(aConnStrParser: TDAConnectionStringParser; aConnectionObject: TCustomConnection); override; function DoBeginTransaction: integer; override; procedure DoCommitTransaction; override; procedure DoRollbackTransaction; override; function DoGetInTransaction: boolean; override; procedure DoGetTableNames(out List: IROStrings); override; procedure DoGetTableFields(const aTableName: string; out Fields: TDAFieldCollection); override; procedure DoGetViewNames(out List: IROStrings); override; procedure DoGetStoredProcedureNames(out List: IROStrings); override; procedure DoGetForeignKeys(out ForeignKeys: TDADriverForeignKeyCollection); override; function DoGetLastAutoInc(const GeneratorName: string): integer; override; function GetQuoteChars: TDAQuoteCharArray; override; function GetSPSelectSyntax(HasArguments: Boolean): string; override; safecall; function IdentifierNeedsQuoting(const iIdentifier: string): boolean; override; safecall; function QuoteFieldName(const aTableName, aFieldName: string): string; override; safecall; // IDACanQueryDatabaseNames function GetDatabaseNames: IROStrings; // IDAFileBasedDatabase function GetFileExtensions: IROStrings; // IDAUseGenerators function GetNextAutoinc(const GeneratorName: string): integer; safecall; // IDACanQueryGeneratorsNames function GetGeneratorNames: IROStrings; public destructor Destroy; override; end; { TDAEADOQuery } TDAEBDEQuery = class(TDAEDataset, IDAMustSetParams) protected function CreateDataset(aConnection: TDAEConnection): TDataset; override; function DoExecute: integer; override; function DoGetSQL: string; override; procedure DoSetSQL(const Value: string); override; procedure RefreshParams; override; safecall; procedure DoPrepare(Value: boolean); override; safecall; // IDAMustSetParams procedure SetParamValues(Params: TDAParamCollection); safecall; procedure GetParamValues(Params: TDAParamCollection); safecall; public end; { TDAEADOStoredProcedure } TDAEBDEStoredProcedure = class(TDAEStoredProcedure, IDAMustSetParams) protected function CreateDataset(aConnection: TDAEConnection): TDataset; override; procedure RefreshParams; override; function GetStoredProcedureName: string; override; procedure SetStoredProcedureName(const Name: string); override; function Execute: integer; override; // IDAMustSetParams procedure SetParamValues(Params: TDAParamCollection); safecall; procedure GetParamValues(Params: TDAParamCollection); safecall; procedure DoPrepare(Value: boolean); override; safecall; end; procedure Register; function GetDriverObject: IDADriver; stdcall; function ProviderToProviderType(AProvider: string): TDABDEProviderType; implementation uses Windows, SysUtils, Variants, Classes, uDARes, uROBinaryHelpers, uDADriverManager, uDAMacroProcessors, uDASQL92Interfaces; var _driver : TDAEDriver = nil; const BDE_LANGDRIVER = '(Access General,Access Greece,Access Japanese,Access Nord/Danish,Access Swed/Finnish,''ascii'' ANSI,' + 'Borland ANSI Arabic,Borland DAN Latin-1,Borland DEU Latin-1,Borland ENG Latin-1,Borland ENU Latin-1,Borland ESP Latin-1,' + 'Borland FIN Latin-1,Borland FRA Latin-1,Borland FRC Latin-1,Borland ISL Latin-1,Borland ITA Latin-1,Borland NLD Latin-1,' + 'Borland NOR Latin-1,Borland PTG Latin-1,Borland SVE Latin-1,DB2 SQL ANSI DEU,dBASE BUL 868,dBASE CHS cp936,dBASE CHT cp950,' + 'dBASE CSY cp852,dBASE CSY cp867,dBASE DAN cp865,dBASE DEU cp437,dBASE DEU cp850,dBASE ELL GR437,dBASE ENG cp437,dBASE ENG cp850,' + 'dBASE ENU cp437,dBASE ENU cp850,dBASE ESP cp437,dBASE ESP cp850,dBASE FIN cp437,dBASE FRA cp437,dBASE FRA cp850,dBASE FRC cp850,' + 'dBASE FRC cp863,dBASE HUN cp852,dBASE ITA cp437,dBASE ITA cp850,dBASE JPN cp932,dBASE JPN Dic932,dBASE KOR cp949,dBASE NLD cp437,' + 'dBASE NLD cp850,dBASE NOR cp865,dBASE PLK cp852,dBASE PTB cp850,dBASE PTG cp860,dBASE RUS cp866,dBASE SLO cp852,dBASE SVE cp437,' + 'dBASE SVE cp850,dBASE THA cp874,dBASE TRK cp857,FoxPro Czech 1250,FoxPro Czech DOS895,FoxPro German 1252,FoxPro German 437,FoxPro Nordic 1252,' + 'FoxPro Nordic 437,FoxPro Nordic 850,Hebrew dBASE,MSSQL ANSI Greek,Oracle SQL WE850,Paradox ANSI HEBREW,Paradox ''ascii'',Paradox BUL 868,' + 'Paradox China 936,Paradox Cyrr 866,Paradox Czech 852,Paradox Czech 867,Paradox ESP 437,Paradox Greek GR437,Paradox ''hebrew'',' + 'Paradox Hun 852 DC,Paradox ''intl'',Paradox ''intl'' 850,Paradox ISL 861,Paradox ''japan'',Paradox Korea 949,Paradox ''nordan'',' + 'Paradox ''nordan40'',Paradox Polish 852,Paradox Slovene 852,Paradox ''swedfin'',Paradox Taiwan 950,Paradox Thai 874,Paradox ''turk'',' + 'Pdox ANSI Bulgaria,Pdox ANSI Cyrillic,Pdox ANSI Czech,Pdox ANSI Greek,Pdox ANSI Hun. DC,Pdox ANSI Intl,Pdox ANSI Intl850,Pdox ANSI Nordan4,' + 'Pdox ANSI Polish,Pdox ANSI Slovene,Pdox ANSI Spanish,Pdox ANSI Swedfin,Pdox ANSI Swedfin,Pdox ANSI Turkish,Paradox ''ascii'' Japan,' + 'pdx ANSI Czech ''CH'',pdx ANSI ISO L_2 CZ,pdx Czech 852 ''CH'',pdx Czech 867 ''CH'',pdx ISO L_2 Czech,''Spanish'' ANSI,' + 'SQL Link ROMAN8,Sybase SQL Dic437,Sybase SQL Dic850,''WEurope'' ANSI)'; function ProviderToProviderType2(AProvider: string): TDABDEProviderType; begin if AnsiCompareText(AProvider, 'STANDARD') = 0 then Result := bdeSTANDARD else if AnsiCompareText(AProvider, 'DB2') = 0 then Result := bdeDB2 else if AnsiCompareText(AProvider, 'INFORMIX') = 0 then Result := bdeINFORMIX else if AnsiCompareText(AProvider, 'INTRBASE') = 0 then Result := bdeINTRBASE else if AnsiCompareText(AProvider, 'MSACCESS') = 0 then Result := bdeMSACCESS else if AnsiCompareText(AProvider, 'MSSQL') = 0 then Result := bdeMSSQL else if AnsiCompareText(AProvider, 'ORACLE') = 0 then Result := bdeORACLE else if AnsiCompareText(AProvider, 'SYBASE') = 0 then Result := bdeSYBASE else Result := bdeODBC; end; function ProviderToProviderType(AProvider: string): TDABDEProviderType; begin if Session.IsAlias(AProvider) then Result := ProviderToProviderType2(Session.GetAliasDriverName(AProvider)) else Result := ProviderToProviderType2(AProvider); end; function GetDriverObject: IDADriver; begin if (_driver = nil) then _driver := TDAEBDEDriver.Create(nil); result := _driver; end; type TDecimalVariant = packed record VarType: TVarType; scale: Byte; sign: Byte; Hi32: Cardinal; Lo32: Cardinal; Mid32: Cardinal; Dummy: Cardinal; end; function DecimalToInt64(const V: Variant): Int64; var vData : TDecimalVariant absolute V; begin if (vData.VarType = 14) and (vData.scale = 0) and (vData.Hi32 = 0) then begin Result := Int64(vData.Lo32) or (Int64(vData.Mid32) shl 32); if vData.sign <> 0 then result := -Result; end else result := v; end; function Int64ToDecimal(Data: Int64): Variant; var vd : TDecimalVariant absolute Result; begin VarClear(Result); vd.scale := 0; if data < 0 then begin vd.Sign := 128; data := -data; end else vd.sign := 0; vd.Hi32 := 0; vd.Mid32 := int64(data shr 32); vd.Lo32 := data; vd.VarType := 14; end; { TDAEBDEDriver } procedure TDAEBDEDriver.GetAuxDrivers(out List: IROStrings); var FList : TStringList; begin inherited GetAuxDrivers(List); FList := TStringList.Create; try try Session.GetAliasNames(FList); List.AddStrings(FList); except end; try Session.GetDriverNames(FList); List.AddStrings(FList); except end; finally FList.Free; end; List.Sorted := True; List.Sorted := False; end; procedure TDAEBDEDriver.GetAuxParams(const AuxDriver: string; out List: IROStrings); begin inherited GetAuxParams(AuxDriver, List); case ProviderToProviderType(AuxDriver) of bdeSTANDARD: begin List.Add('DEFAULT DRIVER=(PARADOX, DBASE, FOXPRO, ASCIIDRV)'); List.Add('ENABLE BCD=(TRUE, FALSE)'); end; bdeDB2: begin List.Add('BATCH COUNT=200'); List.Add('BLOB SIZE=32'); List.Add('BLOBS TO CACHE=64'); //List.Add('DB2 DSN'); { = 'DB2_SERVER'} List.Add('ENABLE BCD=(TRUE, FALSE)'); List.Add('ENABLE SCHEMA CACHE=(TRUE, FALSE)'); List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('MAX ROWS=-1'); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('ROWSET SIZE=20'); List.Add('SCHEMA CACHE DIR='); List.Add('SCHEMA CACHE SIZE=8'); List.Add('SCHEMA CACHE TIME=-1'); List.Add('SQLPASSTHRU MODE=(SHARED AUTOCOMMIT,SHARED NOAUTOCOMMIT,NOT SHARED)'); List.Add('SQLQRYMODE=(LOCAL,SERVER)'); end; bdeINFORMIX: begin List.Add('BATCH COUNT=200'); List.Add('BLOB SIZE=32'); List.Add('BLOBS TO CACHE=64'); List.Add('COLLCHAR=(0,1,2)'); List.Add('DATE MODE=0'); List.Add('DATE SEPARATOR=/'); List.Add('DBNLS=(0,1,2)'); List.Add('ENABLE BCD=(TRUE, FALSE)'); List.Add('ENABLE SCHEMA CACHE=(TRUE, FALSE)'); List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('LIST SYNONYMS=(NONE,ALL,PRIVATE)'); List.Add('LOCK MODE=5'); List.Add('MAX ROWS=-1'); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('SCHEMA CACHE DIR='); List.Add('SCHEMA CACHE SIZE=8'); List.Add('SCHEMA CACHE TIME=-1'); List.Add('SQLPASSTHRU MODE=(SHARED AUTOCOMMIT,SHARED NOAUTOCOMMIT,NOT SHARED)'); List.Add('SQLQRYMODE=(LOCAL,SERVER)'); end; bdeINTRBASE: begin List.Add('BATCH COUNT=200'); List.Add('BLOB SIZE=32'); List.Add('BLOBS TO CACHE=64'); List.Add('COMMIT RETAIN=(FALSE)'); List.Add('ENABLE BCD=(TRUE, FALSE)'); List.Add('ENABLE SCHEMA CACHE=(TRUE, FALSE)'); List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('MAX ROWS=-1'); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('ROLE NAME='); List.Add('SCHEMA CACHE DIR='); List.Add('SCHEMA CACHE SIZE=8'); List.Add('SCHEMA CACHE TIME=-1'); List.Add('SQLPASSTHRU MODE=(SHARED AUTOCOMMIT,SHARED NOAUTOCOMMIT,NOT SHARED)'); List.Add('SQLQRYMODE=(LOCAL,SERVER)'); List.Add('WAIT ON LOCKS=(FALSE)'); end; bdeMSACCESS: begin //List.Add('DATABASE NAME'); { DRIVE:/PATH/DATABASE.MDB} List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('SYSTEM DATABASE=(.MDW)'); end; bdeMSSQL: begin List.Add('APPLICATION MODE'); { } List.Add('BATCH COUNT=200'); List.Add('BLOB EDIT LOGGING=(TRUE, FALSE)'); List.Add('BLOB SIZE=32'); List.Add('BLOBS TO CACHE=64'); //List.Add('DATABASE NAME'); { } List.Add('DATE MODE=0'); List.Add('ENABLE BCD=(TRUE, FALSE)'); List.Add('ENABLE SCHEMA CACHE=(TRUE, FALSE)'); //List.Add('HOST NAME'); { } List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('MAX QUERY TIME=300'); List.Add('NATIONAL LANG NAME='); List.Add('MAX ROWS=-1'); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('SCHEMA CACHE DIR='); List.Add('SCHEMA CACHE SIZE=8'); List.Add('SCHEMA CACHE TIME=-1'); List.Add('SQLPASSTHRU MODE=(SHARED AUTOCOMMIT,SHARED NOAUTOCOMMIT,NOT SHARED)'); List.Add('SQLQRYMODE=(LOCAL,SERVER)'); List.Add('TDS PACKET SIZE=4096'); end; bdeORACLE: begin List.Add('BATCH COUNT=200'); List.Add('BLOB SIZE=32'); List.Add('BLOBS TO CACHE=64'); List.Add('ENABLE BCD=(TRUE, FALSE)'); List.Add('ENABLE INTEGERS=(TRUE, FALSE)'); List.Add('ENABLE SCHEMA CACHE=(TRUE, FALSE)'); List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('LIST SYNONYMS=(NONE,ALL,PRIVATE)'); List.Add('MAX ROWS=-1'); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('NET PROTOCOL=(TNS,TCP/IP,SPX/IPX,NETBIOS,NAMED PIPES,DECNET,3270,VINES,APPC,ASYNC)'); List.Add('OBJECT MODE=(TRUE, FALSE)'); List.Add('ROWSET SIZE=20'); List.Add('SCHEMA CACHE DIR='); List.Add('SCHEMA CACHE SIZE=8'); List.Add('SCHEMA CACHE TIME=-1'); List.Add('SQLPASSTHRU MODE=(SHARED AUTOCOMMIT,SHARED NOAUTOCOMMIT,NOT SHARED)'); List.Add('SQLQRYMODE=(LOCAL,SERVER)'); end; bdeSYBASE: begin List.Add('APPLICATION MODE='); List.Add('BATCH COUNT=200'); List.Add('BLOB EDIT LOGGING=(TRUE, FALSE)'); List.Add('BLOB SIZE=32'); List.Add('BLOBS TO CACHE=64'); List.Add('CS CURSOR ROWS=1'); //List.Add('DATABASE NAME'); { } List.Add('DATE MODE=0'); List.Add('ENABLE BCD=(TRUE, FALSE)'); List.Add('ENABLE SCHEMA CACHE=(TRUE, FALSE)'); List.Add('HOST NAME='); { } List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('MAX QUERY TIME=300'); List.Add('NATIONAL LANG NAME='); List.Add('MAX ROWS=-1'); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('SCHEMA CACHE DIR='); List.Add('SCHEMA CACHE SIZE=8'); List.Add('SCHEMA CACHE TIME=-1'); List.Add('SQLPASSTHRU MODE=(SHARED AUTOCOMMIT,SHARED NOAUTOCOMMIT,NOT SHARED)'); List.Add('SQLQRYMODE=(LOCAL,SERVER)'); List.Add('TDS PACKET SIZE=512'); end; bdeODBC: begin List.Add('BATCH COUNT=200'); List.Add('BLOB SIZE=32'); List.Add('BLOBS TO CACHE=64'); //List.Add('DATABASE NAME='); { } List.Add('ENABLE BCD=(TRUE, FALSE)'); List.Add('ENABLE SCHEMA CACHE=(TRUE, FALSE)'); List.Add('LANGDRIVER=' + BDE_LANGDRIVER); List.Add('MAX ROWS=-1'); List.Add('OPEN MODE=(READ/WRITE,READ ONLY)'); List.Add('ODBC DSN='); List.Add('ROWSET SIZE=20'); List.Add('SCHEMA CACHE DIR='); List.Add('SCHEMA CACHE SIZE=8'); List.Add('SCHEMA CACHE TIME=-1'); List.Add('SQLPASSTHRU MODE=(SHARED AUTOCOMMIT,SHARED NOAUTOCOMMIT,NOT SHARED)'); List.Add('SQLQRYMODE=(LOCAL,SERVER)'); end; end; List.Add('TransIsolation=(tiDirtyRead,tiReadCommitted,tiRepeatableRead)'); end; function TDAEBDEDriver.GetAvailableDriverOptions: TDAAvailableDriverOptions; begin result := [doAuxDriver, doServerName, doDatabaseName, doLogin, doCustom]; { TODO -c???: GetAuxParams } end; function TDAEBDEDriver.GetConnectionClass: TDAEConnectionClass; begin result := TDAEBDEConnection; end; function TDAEBDEDriver.GetDefaultConnectionType( const AuxDriver: string): string; begin case ProviderToProviderType(AuxDriver) of bdeSTANDARD : Result := Paradox_DriverType; bdeDB2 : Result := DB2_DriverType; bdeINFORMIX: Result := Informix_DriverType; bdeINTRBASE : Result := IB_DriverType; bdeMSACCESS : Result := Access_DriverType; bdeMSSQL: Result:=MSSQL_DriverType; bdeORACLE: Result:=Oracle_DriverType; bdeSYBASE: Result:=Sybase_DriverType; bdeODBC: Result:=ODBC_DriverType; else Result := inherited GetDefaultConnectionType(AuxDriver); end; end; function TDAEBDEDriver.GetDescription: string; begin result := 'Borland BDE Driver'; end; function TDAEBDEDriver.GetDriverID: string; begin result := 'BDE'; end; function Need_ODBC_DSN(Provider: string): boolean; var List : TStringList; begin List := TStringList.Create; try try if Session.IsAlias(Provider) then Session.GetAliasParams(Provider, List) else Session.GetDriverParams(Provider, List); Result := List.Values['ODBC DSN'] = ''; except // in case is invalid Provider, error is raised Result := False; end; finally List.Free; end; end; function TDAEBDEDriver.GetProviderDefaultCustomParameters( Provider: string): string; begin Result := ''; if Provider = '' then Exit; case ProviderToProviderType(Provider) of bdeODBC: if Need_ODBC_DSN(Provider) then Result := 'ODBC DSN='; bdeSTANDARD, bdeDB2, bdeMSACCESS: Result := 'TransIsolation=tiDirtyRead;'; end; end; { TDAEBDEQuery } function TDAEBDEQuery.CreateDataset(aConnection: TDAEConnection): TDataset; begin result := TQuery.Create(nil); TQuery(Result).DatabaseName := TDAEBDEConnection(aConnection).fDatabase.DatabaseName; TQuery(Result).SessionName := TDAEBDEConnection(aConnection).fDatabase.SessionName; end; function TDAEBDEQuery.DoExecute: integer; begin TQuery(Dataset).ExecSQL; result := TQuery(Dataset).RowsAffected; end; function TDAEBDEQuery.DoGetSQL: string; begin result := TQuery(Dataset).SQL.Text; end; procedure TDAEBDEQuery.DoPrepare(Value: boolean); begin if Value then TQuery(Dataset).Prepare else TQuery(Dataset).UnPrepare end; procedure TDAEBDEQuery.DoSetSQL(const Value: string); begin TQuery(Dataset).SQL.Text := Value; end; procedure TDAEBDEQuery.GetParamValues(Params: TDAParamCollection); var i : integer; par : TDAParam; inpar : TParam; ds : TQuery; begin ds := TQuery(Dataset); if not Assigned(ds.Params) then Exit; for i := 0 to (ds.Params.Count - 1) do begin inpar := ds.Params[i]; par := Params.ParamByName(inpar.Name); if par.ParamType in [daptOutput, daptInputOutput, daptResult] then begin if inpar.DataType = ftLargeint then par.Value := DecimalToInt64(inpar.Value) else par.Value := inpar.Value; end; end; end; procedure TDAEBDEQuery.RefreshParams; var i : Integer; par : TDAParam; outpar : TParam; ds : TQuery; begin inherited; ds := TQuery(Dataset); if not Assigned(ds.Params) then Exit; for i := 0 to ds.Params.Count - 1 do begin outpar := ds.Params[i]; par := self.ParamByName(outpar.Name); if outpar.DataType <> ftUnknown then par.DataType := VCLTypeToDAType(outpar.DataType); end; end; procedure TDAEBDEQuery.SetParamValues(Params: TDAParamCollection); var i : integer; par : TDAParam; outpar : TParam; ds : TQuery; ft : TFieldType; begin ds := TQuery(Dataset); if not Assigned(ds.Params) then Exit; for i := 0 to (ds.Params.Count - 1) do begin outpar := ds.Params[i]; par := Params.ParamByName(outpar.Name); ft := DATypeToVCLType(par.DataType); case par.ParamType of daptInput: outpar.ParamType := ptInput; daptOutput: outpar.ParamType := ptOutput; daptInputOutput: outpar.ParamType := ptInputOutput; daptResult: outpar.ParamType := ptResult; end; if par.DataType = datBlob then begin outpar.DataType := ftBlob; if not (par.ParamType in [daptOutput, daptResult]) then begin if VarIsEmpty(par.Value) or VarIsNull(par.Value) then outpar.Value := NULL else outpar.Value := VariantBinaryToString(par.Value); end; end else begin if (outpar.DataType <> ft) and (ft <> ftUnknown) then outpar.DataType := ft; if not (par.ParamType in [daptOutput, daptResult]) then begin if outpar.DataType = ftLargeint then Outpar.Value := Int64ToDecimal(par.Value) else outpar.Value := par.Value; end; end; if (VarIsEmpty(par.Value) or VarIsNull(par.Value)) and (par.DataType <> datUnknown) then begin if (outpar.DataType <> ft) and (ft <> ftUnknown) then outpar.DataType := ft; end; end; end; { TDAEBDEStoredProcedure } function TDAEBDEStoredProcedure.CreateDataset( aConnection: TDAEConnection): TDataset; begin result := TStoredProc.Create(nil); TStoredProc(result).DatabaseName := TDAEBDEConnection(aConnection).fDatabase.DatabaseName; TStoredProc(result).SessionName := TDAEBDEConnection(aConnection).fDatabase.SessionName; end; procedure TDAEBDEStoredProcedure.DoPrepare(Value: boolean); begin if value then TStoredProc(Dataset).Prepare else TStoredProc(Dataset).UnPrepare end; function TDAEBDEStoredProcedure.Execute: integer; var i : integer; pstr : string; params : TDAParamCollection; ds : TStoredProc; begin params := GetParams; ds := TStoredProc(Dataset); for i := ds.Params.Count - 1 downto 0 do begin if (ds.Params[i].DataType = ftInterface) and (ds.Params[i].ParamType in [ptOutput, ptInputOutput, ptReSult]) then ds.Params.Delete(i); end; for i := 0 to (params.Count - 1) do begin if (params[i].ParamType = daptOutput) and (ds.Params[i].ParamType <> ptOutput) then ds.Params[i].ParamType := ptOutput else if (params[i].ParamType in [daptInput, daptInputOutput]) then ds.Params.ParamByName(pstr + params[i].Name).Value := params[i].Value; end; Result := -1; ds.ExecProc; ds.GetResults; for i := 0 to (params.Count - 1) do if (params[i].ParamType in [daptOutput, daptInputOutput, daptResult]) then params[i].Value := ds.Params.ParamByName(pstr + params[i].Name).Value; end; procedure TDAEBDEStoredProcedure.GetParamValues( Params: TDAParamCollection); var i : integer; par : TDAParam; inpar : TParam; ds : TQuery; begin ds := TQuery(Dataset); if not Assigned(ds.Params) then Exit; for i := 0 to (ds.Params.Count - 1) do begin inpar := ds.Params[i]; par := Params.ParamByName(inpar.Name); if par.ParamType in [daptOutput, daptInputOutput, daptResult] then begin if inpar.DataType = ftLargeint then par.Value := DecimalToInt64(inpar.Value) else par.Value := inpar.Value; end; end; end; function TDAEBDEStoredProcedure.GetStoredProcedureName: string; begin result := TStoredProc(Dataset).StoredProcName; end; procedure TDAEBDEStoredProcedure.RefreshParams; var dsparams : TParams; i : integer; par : TDAParam; params : TDAParamCollection; nme : string; begin dsparams := TStoredProc(Dataset).Params; params := GetParams; params.Clear; for i := 0 to (dsparams.Count - 1) do begin par := params.Add; if (dsparams[i].DataType = ftInterface) and (dsParams[I].ParamType in [ptOutput, ptInputOutput, ptResult]) then Continue; nme := dsparams[i].Name; par.Name := nme; par.DataType := VCLTypeToDAType(dsparams[i].DataType); par.ParamType := TDAParamType(dsparams[i].ParamType); par.Size := dsparams[i].Size; end; end; procedure TDAEBDEStoredProcedure.SetParamValues( Params: TDAParamCollection); var i : integer; par : TDAParam; outpar : TParam; ds : TStoredProc; ft : TFieldType; begin ds := TStoredProc(Dataset); if not Assigned(ds.Params) then Exit; for i := 0 to (ds.ParamCount - 1) do begin outpar := ds.Params[i]; par := Params.ParamByName(outpar.Name); ft := DATypeToVCLType(par.DataType); case par.ParamType of daptInput: outpar.ParamType := ptInput; daptOutput: outpar.ParamType := ptOutput; daptInputOutput: outpar.ParamType := ptInputOutput; daptResult: outpar.ParamType := ptResult; end; if par.DataType = datBlob then begin outpar.DataType := ftBlob; if not (par.ParamType in [daptOutput, daptResult]) then begin if VarIsEmpty(par.Value) or VarIsNull(par.Value) then outpar.Value := NULL else outpar.Value := VariantBinaryToString(par.Value); end; end else begin if (outpar.DataType <> ft) and (ft <> ftUnknown) then outpar.DataType := ft; if not (par.ParamType in [daptOutput, daptResult]) then begin if outpar.DataType = ftLargeint then Outpar.Value := Int64ToDecimal(par.Value) else outpar.Value := par.Value; end; end; if (VarIsEmpty(par.Value) or VarIsNull(par.Value)) and (par.DataType <> datUnknown) then begin if (outpar.DataType <> ft) and (ft <> ftUnknown) then outpar.DataType := ft; end; end; end; procedure TDAEBDEStoredProcedure.SetStoredProcedureName( const Name: string); begin TStoredProc(Dataset).StoredProcName := Name; end; { TDAEBDEConnection } function TDAEBDEConnection.CreateCustomConnection: TCustomConnection; begin FDatabase := TDatabase.Create(nil); FSession := TSession.Create(nil); FSession.AutoSessionName := True; fDatabase.SessionName := FSession.SessionName; Result := fDatabase; fDatabase.LoginPrompt := False; fDatabase.DatabaseName := copy(NewStrippedGuidAsString, 1, 30); end; function TDAEBDEConnection.CreateMacroProcessor: TDASQLMacroProcessor; begin {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: Result := IB_CreateMacroProcessor; bdeMSSQL: Result := MSSQL_CreateMacroProcessor; bdeORACLE: Result := TOracleMacroProcessor.Create; else Result:=inherited CreateMacroProcessor; end; {$ELSE} Result:=inherited CreateMacroProcessor; {$ENDIF} end; destructor TDAEBDEConnection.Destroy; begin FreeAndNil(FSession); inherited; end; procedure TDAEBDEConnection.DoApplyConnectionString( aConnStrParser: TDAConnectionStringParser; aConnectionObject: TCustomConnection); procedure SetUserNamePassword; begin with aConnStrParser do begin if (Self.UserID <> '') then fDatabase.Params.Values['USER NAME'] := Self.UserID else if (UserID <> '') then fDatabase.Params.Values['USER NAME'] := UserID; if (Self.Password <> '') then fDatabase.Params.Values['PASSWORD'] := Self.Password else if (Password <> '') then fDatabase.Params.Values['PASSWORD'] := Password; end; end; var i : Integer; begin inherited; with aConnStrParser do begin if AuxDriver <> '' then begin fDatabase.Params.Clear; fDatabase.AliasName := ''; fDatabase.DriverName := ''; fProviderType := ProviderToProviderType(AuxDriver); if fDatabase.Session.IsAlias(AuxDriver) then fDatabase.AliasName := AuxDriver else fDatabase.DriverName := AuxDriver; end else raise EDADriverException.Create('No aux driver specified for BDE connection'); fProviderName := AuxDriver; case fProviderType of bdeSTANDARD: begin //fDatabase.Params.Values['DEFAULT DRIVER'] := ; {PARADOX, DBASE, FOXPRO, ASCIIDRV} //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} if Database <> '' then fDatabase.Params.Values['PATH'] := Database; end; bdeDB2: begin //fDatabase.Params.Values['BATCH COUNT'] := { = 200} //fDatabase.Params.Values['BLOB SIZE'] := { = 32} //fDatabase.Params.Values['BLOBS TO CACHE'] := { = 64} if Server <> '' then fDatabase.Params.Values['DB2 DSN'] := Server; { = 'DB2_SERVER'} //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE SCHEMA CACHE'] := { TRUE / FALSE} //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['MAX ROWS'] := { = -1} //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['ROWSET SIZE'] := { = 20} //fDatabase.Params.Values['SCHEMA CACHE DIR'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE SIZE'] := { = 8} //fDatabase.Params.Values['SCHEMA CACHE TIME'] := { = -1} //fDatabase.Params.Values['SQLPASSTHRU MODE'] := { SHARED AUTOCOMMIT, SHARED NOAUTOCOMMIT, NOT SHARED} //fDatabase.Params.Values['SQLQRYMODE'] := { = '',LOCAL,SERVER} SetUserNamePassword; end; bdeINFORMIX: begin //fDatabase.Params.Values['BATCH COUNT'] := { = 200} //fDatabase.Params.Values['BLOB SIZE'] := { = 32} //fDatabase.Params.Values['BLOBS TO CACHE'] := { = 64} //fDatabase.Params.Values['COLLCHAR'] := { = 0,1,2} if Database <> '' then fDatabase.Params.Values['DATABASE NAME'] := Database; //fDatabase.Params.Values['DATE MODE'] := { = 0}; //fDatabase.Params.Values['DATE SEPARATOR'] := { = '/'}; //fDatabase.Params.Values['DBNLS'] := { = '',0,1,2}; //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE SCHEMA CACHE'] := { TRUE / FALSE} //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['LIST SYNONYMS'] := { NONE, ALL, PRIVATE} //fDatabase.Params.Values['LOCK MODE'] := { = 5} //fDatabase.Params.Values['MAX ROWS'] := { = -1} //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['SCHEMA CACHE DIR'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE SIZE'] := { = 8} //fDatabase.Params.Values['SCHEMA CACHE TIME'] := { = -1} if Server <> '' then fDatabase.Params.Values['SERVER NAME'] := Server; //fDatabase.Params.Values['SQLPASSTHRU MODE'] := { SHARED AUTOCOMMIT, SHARED NOAUTOCOMMIT, NOT SHARED} //fDatabase.Params.Values['SQLQRYMODE'] := { = '',LOCAL,SERVER} SetUserNamePassword; end; bdeINTRBASE: begin //fDatabase.Params.Values['BATCH COUNT'] := { = 200} //fDatabase.Params.Values['BLOB SIZE'] := { = 32} //fDatabase.Params.Values['BLOBS TO CACHE'] := { = 64} //fDatabase.Params.Values['COMMIT RETAIN'] := { = FALSE} //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE SCHEMA CACHE'] := { TRUE / FALSE} //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['MAX ROWS'] := { = -1} //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['ROLE NAME'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE DIR'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE SIZE'] := { = 8} //fDatabase.Params.Values['SCHEMA CACHE TIME'] := { = -1} if Database <> '' then fDatabase.Params.Values['SERVER NAME'] := StringReplace(Database, '\', '/', [rfReplaceAll]); { = IB_SERVER:/PATH/DATABASE.GDB} if Server <> '' then fDatabase.Params.Values['SERVER NAME'] := Server + ':' + fDatabase.Params.Values['SERVER NAME']; { = IB_SERVER:/PATH/DATABASE.GDB} //fDatabase.Params.Values['SQLPASSTHRU MODE'] := { SHARED AUTOCOMMIT, SHARED NOAUTOCOMMIT, NOT SHARED} //fDatabase.Params.Values['SQLQRYMODE'] := { = '',LOCAL,SERVER} SetUserNamePassword; //fDatabase.Params.Values['WAIT ON LOCKS'] := {FALSE}; end; bdeMSACCESS: begin if Database <> '' then fDatabase.Params.Values['DATABASE NAME'] := StringReplace(Database, '\', '/', [rfReplaceAll]); { DRIVE:/PATH/DATABASE.MDB} //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['SYSTEM DATABASE'] := { *.MDW} SetUserNamePassword; end; bdeMSSQL: begin //fDatabase.Params.Values['APPLICATION MODE'] := { } //fDatabase.Params.Values['BATCH COUNT'] := { = 200} //fDatabase.Params.Values['BLOB EDIT LOGGING'] := { '',TRUE,FALSE} //fDatabase.Params.Values['BLOB SIZE'] := { = 32} //fDatabase.Params.Values['BLOBS TO CACHE'] := { = 64} if Database <> '' then fDatabase.Params.Values['DATABASE NAME'] := Database; //fDatabase.Params.Values['DATE MODE'] := { = 0}; //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE SCHEMA CACHE'] := { TRUE / FALSE} //fDatabase.Params.Values['HOST NAME'] := { }; //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['MAX QUERY TIME'] := { 300} //fDatabase.Params.Values['MAX ROWS'] := { = -1} //fDatabase.Params.Values['NATIONAL LANG NAME'] := { } //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['SCHEMA CACHE DIR'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE SIZE'] := { = 8} //fDatabase.Params.Values['SCHEMA CACHE TIME'] := { = -1} if Server <> '' then fDatabase.Params.Values['SERVER NAME'] := Server; { = MSS_SERVER} //fDatabase.Params.Values['SQLPASSTHRU MODE'] := { SHARED AUTOCOMMIT, SHARED NOAUTOCOMMIT, NOT SHARED} //fDatabase.Params.Values['SQLQRYMODE'] := { = '',LOCAL,SERVER} //fDatabase.Params.Values['TDS PACKET SIZE'] := { = 4096} SetUserNamePassword; end; bdeORACLE: begin //fDatabase.Params.Values['BATCH COUNT'] := { = 200} //fDatabase.Params.Values['BLOB SIZE'] := { = 32} //fDatabase.Params.Values['BLOBS TO CACHE'] := { = 64} //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE INTEGERS'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE SCHEMA CACHE'] := { TRUE / FALSE} //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['LIST SYNONYMS'] := { NONE, ALL, PRIVATE} //fDatabase.Params.Values['MAX ROWS'] := { = -1} //fDatabase.Params.Values['NET PROTOCOL'] := { = TNS, TCP/IP,SPX/IPX,NETBIOS,NAMED PIPES,DECNET,3270,VINES,APPC,ASYNC} //fDatabase.Params.Values['OBJECT MODE'] := { = TRUE/FALSE} //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['ROWSET SIZE'] := { = 20} //fDatabase.Params.Values['SCHEMA CACHE DIR'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE SIZE'] := { = 8} //fDatabase.Params.Values['SCHEMA CACHE TIME'] := { = -1} if Server <> '' then fDatabase.Params.Values['SERVER NAME'] := Server; { = ORA_SERVER} //fDatabase.Params.Values['SQLPASSTHRU MODE'] := { SHARED AUTOCOMMIT, SHARED NOAUTOCOMMIT, NOT SHARED} //fDatabase.Params.Values['SQLQRYMODE'] := { = '',LOCAL,SERVER} SetUserNamePassword; end; bdeSYBASE: begin //fDatabase.Params.Values['APPLICATION MODE'] := { } //fDatabase.Params.Values['BATCH COUNT'] := { = 200} //fDatabase.Params.Values['BLOB EDIT LOGGING'] := { '',TRUE,FALSE} //fDatabase.Params.Values['BLOB SIZE'] := { = 32} //fDatabase.Params.Values['BLOBS TO CACHE'] := { = 64} //fDatabase.Params.Values['CS CURSOR ROWS'] := { = 1} if Database <> '' then fDatabase.Params.Values['DATABASE NAME'] := Database; //fDatabase.Params.Values['DATE MODE'] := { = 0}; //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE SCHEMA CACHE'] := { TRUE / FALSE} //fDatabase.Params.Values['HOST NAME'] := { }; //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['MAX QUERY TIME'] := { 300} //fDatabase.Params.Values['MAX ROWS'] := { = -1} //fDatabase.Params.Values['NATIONAL LANG NAME'] := { } //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['SCHEMA CACHE DIR'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE SIZE'] := { = 8} //fDatabase.Params.Values['SCHEMA CACHE TIME'] := { = -1} if Server <> '' then fDatabase.Params.Values['SERVER NAME'] := Server; { = SYB_SERVER} //fDatabase.Params.Values['SQLPASSTHRU MODE'] := { SHARED AUTOCOMMIT, SHARED NOAUTOCOMMIT, NOT SHARED} //fDatabase.Params.Values['SQLQRYMODE'] := { = '',LOCAL,SERVER} //fDatabase.Params.Values['TDS PACKET SIZE'] := { = 512} SetUserNamePassword; end; bdeODBC: begin //fDatabase.Params.Values['BATCH COUNT'] := { = 200} //fDatabase.Params.Values['BLOB SIZE'] := { = 32} //fDatabase.Params.Values['BLOBS TO CACHE'] := { = 64} if Database <> '' then fDatabase.Params.Values['DATABASE NAME'] := Database; //fDatabase.Params.Values['ENABLE BCD'] := { TRUE / FALSE} //fDatabase.Params.Values['ENABLE SCHEMA CACHE'] := { TRUE / FALSE} //fDatabase.Params.Values['LANGDRIVER'] := { ...} //fDatabase.Params.Values['MAX ROWS'] := { = -1} //fDatabase.Params.Values['ODBC DSN'] := {} //fDatabase.Params.Values['OPEN MODE'] := { READ/WRITE, READ ONLY} //fDatabase.Params.Values['ROWSET SIZE'] := { = 20} //fDatabase.Params.Values['SCHEMA CACHE DIR'] := { = ''} //fDatabase.Params.Values['SCHEMA CACHE SIZE'] := { = 8} //fDatabase.Params.Values['SCHEMA CACHE TIME'] := { = -1} //fDatabase.Params.Values['SQLPASSTHRU MODE'] := { SHARED AUTOCOMMIT, SHARED NOAUTOCOMMIT, NOT SHARED} //fDatabase.Params.Values['SQLQRYMODE'] := { = '',LOCAL,SERVER} SetUserNamePassword; end; end; for i := 0 to AuxParamsCount - 1 do begin if AnsiSameText(AuxParamNames[i], 'TransIsolation') then begin if AnsiSameText(AuxParams[AuxParamNames[i]], 'tiDirtyRead') then fDatabase.TransIsolation := tiDirtyRead else if AnsiSameText(AuxParams[AuxParamNames[i]], 'tiReadCommitted') then fDatabase.TransIsolation := tiReadCommitted else if AnsiSameText(AuxParams[AuxParamNames[i]], 'tiRepeatableRead') then fDatabase.TransIsolation := tiRepeatableRead; end else fDatabase.Params.Values[AuxParamNames[i]] := AuxParams[AuxParamNames[i]]; end; end; end; function TDAEBDEConnection.DoBeginTransaction: integer; begin result := -1; fDatabase.StartTransaction; end; procedure TDAEBDEConnection.DoCommitTransaction; begin fDatabase.Commit; end; procedure TDAEBDEConnection.DoGetForeignKeys( out ForeignKeys: TDADriverForeignKeyCollection); begin inherited DoGetForeignKeys(ForeignKeys); {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: IB_DoGetForeignKeys(GetDatasetClass.Create(Self), ForeignKeys); bdeMSSQL: MSSQL_DoGetForeignKeys(GetDatasetClass.Create(Self), ForeignKeys, True); end; {$ENDIF} end; function TDAEBDEConnection.DoGetInTransaction: boolean; begin Result := fDatabase.InTransaction; end; function TDAEBDEConnection.DoGetLastAutoInc( const GeneratorName: string): integer; begin Result := inherited DoGetLastAutoInc(GeneratorName); {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: Result := IB_GetLastAutoInc(GeneratorName, GetDatasetClass.Create(Self)); bdeMSSQL: Result := MSSQL_DoGetLastAutoInc(GeneratorName, GetDatasetClass.Create(Self)); bdeOracle: Result := Oracle_DoGetLastAutoInc(GeneratorName,GetDatasetClass.Create(Self)); end; {$ENDIF} end; procedure TDAEBDEConnection.DoGetStoredProcedureNames( out List: IROStrings); begin inherited DoGetStoredProcedureNames(List); {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: IB_GetObjectNames(GetDatasetClass.Create(Self), List, dotProcedure); bdeMSSQL: MSSQL_DoGetNames(GetDatasetClass.Create(Self), List, dotProcedure, True); else fDatabase.Session.GetStoredProcNames(fDatabase.DatabaseName, List.Strings); end; {$ELSE} fDatabase.Session.GetStoredProcNames(fDatabase.DatabaseName, List.Strings); {$ENDIF} end; procedure TDAEBDEConnection.DoGetTableFields(const aTableName: string; out Fields: TDAFieldCollection); begin {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: IB_GetTableFields(QuoteIdentifierIfNeeded(aTableName), GetDatasetClass.Create(Self), Fields); bdeMSSQL: MSSQL_DoGetTableFields(QuoteIdentifierIfNeeded(aTableName), GetDatasetClass.Create(Self), Fields); else inherited DoGetTableFields(QuoteIdentifierIfNeeded(aTableName), Fields); end; {$ELSE} inherited DoGetTableFields(QuoteIdentifierIfNeeded(aTableName), Fields); {$ENDIF} end; procedure TDAEBDEConnection.DoGetTableNames(out List: IROStrings); begin inherited DoGetTableNames(List); {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: IB_GetObjectNames(GetDatasetClass.Create(Self), List, dotTable); bdeMSSQL: MSSQL_DoGetNames(GetDatasetClass.Create(Self), List, dotTable, True); else fDatabase.GetTableNames(List.Strings); end; {$ELSE} fDatabase.GetTableNames(List.Strings); {$ENDIF} end; procedure TDAEBDEConnection.DoGetViewNames(out List: IROStrings); begin inherited DoGetViewNames(List); {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: IB_GetObjectNames(GetDatasetClass.Create(Self), List, dotView); bdeMSSQL: MSSQL_DoGetNames(GetDatasetClass.Create(Self), List, dotView, True); end; {$ENDIF} end; procedure TDAEBDEConnection.DoRollbackTransaction; begin fDatabase.Rollback; end; function TDAEBDEConnection.GetDatabaseNames: IROStrings; begin {$IFDEF MAX_SUPPORT} case fProviderType of bdeMSSQL: Result := MSSQL_GetDatabaseNames(Self); else Result := NewROStrings; fDatabase.Session.GetDatabaseNames(Result.Strings); end; {$ELSE} Result := NewROStrings; fDatabase.Session.GetDatabaseNames(Result.Strings); {$ENDIF} end; function TDAEBDEConnection.GetDatasetClass: TDAEDatasetClass; begin Result := TDAEBDEQuery; end; function TDAEBDEConnection.GetFileExtensions: IROStrings; begin case fProviderType of bdeINTRBASE: Result := IB_GetFileExtensions; bdeMSACCESS: begin Result := NewROStrings; result.Add('*.mdb;MSAccess files (*.mdb)'); result.Add('*.*;All files (*.*)'); end; else Result := NewROStrings; end; end; function TDAEBDEConnection.GetGeneratorNames: IROStrings; begin case fProviderType of bdeINTRBASE: Result:= IB_GetGeneratorNames(GetDatasetClass.Create(Self)); else Result := NewROStrings; end; end; function TDAEBDEConnection.GetNextAutoinc( const GeneratorName: string): integer; begin result := -1; {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: Result := IB_GetNextAutoinc(GeneratorName, GetDatasetClass.Create(Self)); bdeOracle: Result := Oracle_GetNextAutoinc(GeneratorName, GetDatasetClass.Create(Self)); end; {$ENDIF} end; function TDAEBDEConnection.GetQuoteChars: TDAQuoteCharArray; begin case fProviderType of bdeMSSQL: result:=MSSQL_GetQuoteChars; else Result[0] := '"'; Result[1] := '"'; end; end; function TDAEBDEConnection.GetSPSelectSyntax( HasArguments: Boolean): string; begin Result := inherited GetSPSelectSyntax(HasArguments); {$IFDEF MAX_SUPPORT} case fProviderType of bdeINTRBASE: Result := IB_GetSPSelectSyntax(HasArguments); bdeMSSQL: Result := MSSQL_GetSPSelectSyntax(HasArguments); bdeOracle: Result := Oracle_GetSPSelectSyntax(HasArguments); end; {$ENDIF} end; function TDAEBDEConnection.GetStoredProcedureClass: TDAEStoredProcedureClass; begin Result := TDAEBDEStoredProcedure; end; function TDAEBDEConnection.IdentifierNeedsQuoting( const iIdentifier: string): boolean; begin Result := inherited IdentifierNeedsQuoting(iIdentifier); if not Result then case fProviderType of bdeMSSQL: Result := MSSQL_IdentifierNeedsQuoting(iIdentifier); bdeINTRBASE: Result := IB_IdentifierNeedsQuoting(iIdentifier); else Result := SQL92_IdentifierNeedsQuoting(iIdentifier); end; end; function TDAEBDEConnection.QueryInterface(const IID: TGUID; out Obj): HResult; begin Result := E_NOINTERFACE; if IsEqualGUID(IID, IDAInterbaseConnection) then begin if not (fProviderType in [bdeINTRBASE]) then Exit; end; if IsEqualGUID(IID, IDAADOConnection) then begin if not (fProviderType in [bdeMSSQL]) then Exit; end; if IsEqualGUID(IID, IDAOracleConnection) then begin if not (fProviderType in [bdeOracle]) then Exit; end; if IsEqualGUID(IID, IDAUseGenerators) then begin if not (fProviderType in [bdeINTRBASE, bdeOracle]) then Exit; end; if IsEqualGUID(IID, IDACanQueryGeneratorsNames) then begin if not (fProviderType in [bdeINTRBASE]) then Exit; end; if IsEqualGUID(IID, IDAFileBasedDatabase) then begin if not (fProviderType in [bdeINTRBASE, bdeMSACCESS]) then Exit; end; if IsEqualGUID(IID, IDACanQueryDatabaseNames) then begin if not (fProviderType in [bdeINFORMIX, bdeMSSQL, bdeORACLE, bdeSYBASE]) then Exit; end; if IsEqualGUID(IID, IDADirectoryBasedDatabase) then begin if not (fProviderType in [bdeSTANDARD]) then Exit; end; Result := inherited QueryInterface(IID, Obj); end; procedure Register; begin RegisterComponents(DAPalettePageName, [TDABDEDriver]); end; exports GetDriverObject name func_GetDriverObject; function TDAEBDEConnection.QuoteFieldName(const aTableName, aFieldName: string): string; begin Result := inherited QuoteFieldName(aTableName, aFieldName); case fProviderType of bdeSTANDARD: if (aTableName <> '') and (aFieldName <> Result) then Result := QuoteIdentifierIfNeeded(aTableName) + '.' + Result; end; end; initialization _driver := nil; RegisterDriverProc(GetDriverObject); finalization UnregisterDriverProc(GetDriverObject); FreeAndNIL(_driver); end.