unit uDADBISAMDriver; {----------------------------------------------------------------------------} { 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. {----------------------------------------------------------------------------} {$IFDEF MSWINDOWS} {$I ..\DataAbstract.inc} {$ELSE} {$I ../DataAbstract.inc} {$ENDIF} {$R DataAbstract_DBISAMDriver_Glyphs.res} {$I dbisamvr.inc} {$IFNDEF DBISAM_V4} {$DEFINE DBISAM_V3} {$ENDIF} interface uses DB, Classes, uDAEngine, uDAInterfaces, uROClasses, DBISAMTb, uDAUtils; type { TDADBISAMDriver } TDADBISAMDriver = class(TDADriverReference) end; { IDBISAMConnection } IDBISAMConnection = interface ['{C6222EF8-FBAE-42AE-B034-8FFAE8FF2578}'] end; { IDBISAMConnectionProperties Provides access to common properties of DBISAM connections } IDBISAMConnectionProperties = interface ['{41BAFCD6-D6EA-477E-B489-7EA6E05FFCC0}'] function GetForceBufferFlush: Boolean; procedure SetForceBufferFlush(Value: Boolean); function GetKeepConnections: Boolean; procedure SetKeepConnections(Value: Boolean); function GetLockProtocol: TLockProtocol; procedure SetLockProtocol(Value: TLockProtocol); function GetLockRetryCount: Byte; procedure SetLockRetryCount(Value: Byte); function GetLockWaitTime: Word; procedure SetLockWaitTime(Value: Word); function GetPrivateDir: string; procedure SetPrivateDir(const Value: string); function GetRemotePort: Integer; procedure SetRemotePort(Value: Integer); function GetRemoteService: string; procedure SetRemoteService(const Value: string); function GetRemoteTrace: Boolean; procedure SetRemoteTrace(Value: Boolean); {$IFDEF DBISAM_V3} function GetRemoteType: TRemoteType; procedure SetRemoteType(Value: TRemoteType); {$ENDIF} {$IFDEF DBISAM_V4} function GetRemoteCompression: Byte; procedure SetRemoteCompression(Value: Byte); function GetRemoteEncryption: Boolean; procedure SetRemoteEncryption(Value: Boolean); function GetRemoteEncryptionPassword: string; procedure SetRemoteEncryptionPassword(const Value: string); function GetRemoteTimeout: Integer; procedure SetRemoteTimeout(Value: Integer); {$ENDIF} procedure AddPassword( const aPassword: string); procedure RemovePassword(const aPassword: string); procedure RemoveAllPasswords; property ForceBufferFlush: Boolean read GetForceBufferFlush write SetForceBufferFlush; property KeepConnections: Boolean read GetKeepConnections write SetKeepConnections; property LockProtocol: TLockProtocol read GetLockProtocol write SetLockProtocol; property LockRetryCount: Byte read GetLockRetryCount write SetLockRetryCount; property LockWaitTime: Word read GetLockWaitTime write SetLockWaitTime; property PrivateDir: string read GetPrivateDir write SetPrivateDir; property RemotePort: Integer read GetRemotePort write SetRemotePort; property RemoteService: string read GetRemoteService write SetRemoteService; property RemoteTrace: Boolean read GetRemoteTrace write SetRemoteTrace; {$IFDEF DBISAM_V3} property RemoteType: TRemoteType read GetRemoteType write SetRemoteType; {$ENDIF} {$IFDEF DBISAM_V4} property RemoteCompression: Byte read GetRemoteCompression write SetRemoteCompression; property RemoteEncryption: Boolean read GetRemoteEncryption write SetRemoteEncryption; property RemoteEncryptionPassword: string read GetRemoteEncryptionPassword write SetRemoteEncryptionPassword; property RemoteTimeout: Integer read GetRemoteTimeout write SetRemoteTimeout; {$ENDIF} end; { TDBISAMConnection } TDBISAMConnection = class(TDAConnectionWrapper) private fDatabase: TDBISAMDatabase; fSession: TDBISAMSession; protected function GetConnected: Boolean; override; procedure SetConnected(Value: Boolean); override; public constructor Create(AOwner: TComponent); override; property Database: TDBISAMDatabase read fDatabase; property Session: TDBISAMSession read fSession; end; { TDAEDBISAMDriver } TDAEDBISAMDriver = class(TDAEDriver) private protected function GetConnectionClass: TDAEConnectionClass; override; // IDADriver function GetDriverID: string; override; function GetDescription: string; override; procedure GetAuxParams(const AuxDriver: string; out List: IROStrings); override; function GetAvailableDriverOptions: TDAAvailableDriverOptions; override; function GetDefaultConnectionType(const AuxDriver: string): string; override; safecall; public end; { TDAEDBISAMConnection } TDAEDBISAMConnection = class(TDAEConnection, IDBISAMConnection, IDBISAMConnectionProperties) private fConnection: TDBISAMConnection; protected // IDBISAMConnectionProperties function GetForceBufferFlush: Boolean; procedure SetForceBufferFlush(Value: Boolean); function GetKeepConnections: Boolean; procedure SetKeepConnections(Value: Boolean); function GetLockProtocol: TLockProtocol; procedure SetLockProtocol(Value: TLockProtocol); function GetLockRetryCount: Byte; procedure SetLockRetryCount(Value: Byte); function GetLockWaitTime: Word; procedure SetLockWaitTime(Value: Word); function GetPrivateDir: string; procedure SetPrivateDir(const Value: string); function GetRemotePort: Integer; procedure SetRemotePort(Value: Integer); function GetRemoteService: string; procedure SetRemoteService(const Value: string); function GetRemoteTrace: Boolean; procedure SetRemoteTrace(Value: Boolean); {$IFDEF DBISAM_V3} function GetRemoteType: TRemoteType; procedure SetRemoteType(Value: TRemoteType); {$ENDIF} {$IFDEF DBISAM_V4} function GetRemoteCompression: Byte; procedure SetRemoteCompression(Value: Byte); function GetRemoteEncryption: Boolean; procedure SetRemoteEncryption(Value: Boolean); function GetRemoteEncryptionPassword: string; procedure SetRemoteEncryptionPassword(const Value: string); function GetRemoteTimeout: Integer; procedure SetRemoteTimeout(Value: Integer); {$ENDIF} procedure AddPassword( const aPassword: string); procedure RemovePassword(const aPassword: string); procedure RemoveAllPasswords; // IDAConnection function CreateCustomConnection: TCustomConnection; override; function CreateMacroProcessor: TDASQLMacroProcessor; override; function GetDatasetClass: TDAEDatasetClass; 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; function DoGetLastAutoInc(const GeneratorName: string): integer; override; procedure DoGetTableFields(const aTableName: string; out Fields: TDAFieldCollection);override; function IdentifierNeedsQuoting(const iIdentifier: string): boolean; override; {$IFNDEF FPC_SAFECALL_BUG}safecall;{$ENDIF} public end; { TDAEDBISAMQuery } TDAEDBISAMQuery = class(TDAEDataset, IDAMustSetParams) private protected function CreateDataset(aConnection: TDAEConnection): TDataset; override; procedure ClearParams; override; function DoExecute: Integer; override; function DoGetSQL: string; override; procedure DoSetSQL(const Value: string); override; procedure DoPrepare(Value: Boolean); override; // IDAMustSetParams {$IFDEF DBISAM_V4} procedure RefreshParams; override; {$ENDIF} procedure SetParamValues(AParams: TDAParamCollection); override;{$IFNDEF FPC_SAFECALL_BUG}safecall;{$ENDIF} procedure GetParamValues(AParams: TDAParamCollection); override;{$IFNDEF FPC_SAFECALL_BUG}safecall;{$ENDIF} end; const DBISAM_DriverType = 'DBISAM'; procedure Register; function GetDriverObject: IDADriver; stdcall; implementation uses SysUtils, uDADriverManager, uDARes, uDAMacroProcessors, Variants, uROBinaryHelpers; var _driver: TDAEDriver = nil; dbisam_reservedwords: array of string; procedure Register; begin RegisterComponents(DAPalettePageName, [TDADBISAMDriver]); end; {$IFDEF DataAbstract_SchemaModelerOnly} {$INCLUDE ..\DataAbstract_SchemaModelerOnly.inc} {$ENDIF DataAbstract_SchemaModelerOnly} function GetDriverObject: IDADriver; begin {$IFDEF DataAbstract_SchemaModelerOnly} if not RunningInSchemaModeler then begin result := nil; exit; end; {$ENDIF} if (_driver = nil) then _driver := TDAEDBISAMDriver.Create(nil); result := _driver; end; { TDBISAMConnection } constructor TDBISAMConnection.Create(AOwner: TComponent); begin inherited; fSession := TDBISAMSession.Create(Self); fSession.AutoSessionName := TRUE; fDatabase := TDBISAMDatabase.Create(Self); fDatabase.SessionName := fSession.SessionName; fDatabase.DatabaseName := 'DBISAMDB'; end; function TDBISAMConnection.GetConnected: Boolean; begin result := fDatabase.Connected; end; procedure TDBISAMConnection.SetConnected(Value: Boolean); begin if not(csDestroying in fDatabase.ComponentState) then begin try fSession.Active := Value; fDatabase.Connected := Value; except fSession.Active := FALSE; fDatabase.Connected := FALSE; raise; end; end; end; { TDAEDBISAMConnection } procedure TDAEDBISAMConnection.DoApplyConnectionString( aConnStrParser: TDAConnectionStringParser; aConnectionObject: TCustomConnection); begin inherited; with aConnStrParser do begin if (Self.UserID <> '') then fConnection.Session.RemoteUser := Self.UserID else fConnection.Session.RemoteUser := UserID; if (Self.Password <> '') then fConnection.Session.RemotePassword := Self.Password else fConnection.Session.RemotePassword := Password; if (Server <> '') then begin // Remote connection fConnection.Session.SessionType := stRemote; fConnection.Session.RemoteHost := Server; fConnection.Database.RemoteDatabase := Database; if (AuxParams['RemotePort'] <> '') then fConnection.Session.RemotePort := StrToInt(AuxParams['RemotePort']); if (AuxParams['RemoteService'] <> '') then fConnection.Session.RemoteService := AuxParams['RemoteService']; if (AuxParams['RemoteTrace'] = 'False') then fConnection.Session.RemoteTrace := False else if (AuxParams['RemoteTrace'] = 'True') then fConnection.Session.RemoteTrace := True; {$IFDEF DBISAM_V3} if (AuxParams['RemoteType'] = 'rtLAN') then fConnection.Session.RemoteType := rtLAN else if (AuxParams['RemoteType'] = 'rtInternet') then fConnection.Session.RemoteType := rtInternet; {$ENDIF} {$IFDEF DBISAM_V4} if (AuxParams['RemoteCompression'] <> '') then if (StrToInt(AuxParams['RemoteCompression']) in [0..9]) then fConnection.Session.RemoteCompression := StrToInt(AuxParams['RemoteCompression']); if (AuxParams['RemoteEncryption'] = 'False') then fConnection.Session.RemoteEncryption := False else if (AuxParams['RemoteEncryption'] = 'True') then fConnection.Session.RemoteEncryption := True; if (AuxParams['RemoteEncryptionPassword'] <> '') then fConnection.Session.RemoteEncryptionPassword := AuxParams['RemoteEncryptionPassword']; if (AuxParams['RemoteTimeout'] <> '') then fConnection.Session.RemoteTimeout := StrToInt(AuxParams['RemoteTimeout']); {$ENDIF} end else begin // Local connection fConnection.Session.SessionType := stLocal; fConnection.Database.Directory := Database; end; if (AuxParams['ForceBufferFlush'] = 'False') then fConnection.Session.ForceBufferFlush := False else if (AuxParams['ForceBufferFlush'] = 'True') then fConnection.Session.ForceBufferFlush := True; if (AuxParams['KeepConnections'] = 'False') then begin fConnection.Session.KeepConnections := False; fConnection.Database.KeepConnection := False; end else if (AuxParams['KeepConnections'] = 'True') then begin fConnection.Session.KeepConnections := True; fConnection.Database.KeepConnection := True; end; if (AuxParams['LockProtocol'] = 'lpOptimistic') then fConnection.Session.LockProtocol := lpOptimistic else if (AuxParams['LockProtocol'] = 'lpPessimistic') then fConnection.Session.LockProtocol := lpPessimistic; if (AuxParams['LockRetryCount'] <> '') then fConnection.Session.LockRetryCount := StrToInt(AuxParams['LockRetryCount']); if (AuxParams['LockWaitTime'] <> '') then fConnection.Session.LockWaitTime := StrToInt(AuxParams['LockWaitTime']); if (AuxParams['PrivateDir'] <> '') then fConnection.Session.PrivateDir := AuxParams['PrivateDir']; if (AuxParams['TablePassword'] <> '') then begin fConnection.Session.Active := True; fConnection.Session.AddPassword(AuxParams['TablePassword']); end; end; end; function TDAEDBISAMConnection.DoBeginTransaction: integer; begin result := -1; fConnection.Database.StartTransaction; end; procedure TDAEDBISAMConnection.DoCommitTransaction; begin with fConnection do Database.Commit(Session.ForceBufferFlush); end; function TDAEDBISAMConnection.CreateCustomConnection: TCustomConnection; begin result := TDBISAMConnection.Create(nil); fConnection := TDBISAMConnection(result); end; function TDAEDBISAMConnection.GetDatasetClass: TDAEDatasetClass; begin result := TDAEDBISAMQuery end; procedure TDAEDBISAMConnection.DoGetTableNames(out List: IROStrings); var _database: string; begin List := TROStrings.Create; if (fConnection.Session.SessionType = stLocal) then _database := fConnection.Database.Directory else _database := fConnection.Database.RemoteDatabase; fConnection.Session.GetTableNames(_database, List.Strings); end; procedure TDAEDBISAMConnection.DoRollbackTransaction; begin fConnection.Database.Rollback; end; function TDAEDBISAMConnection.DoGetInTransaction: Boolean; begin result := fConnection.Database.InTransaction; end; function TDAEDBISAMConnection.CreateMacroProcessor: TDASQLMacroProcessor; begin result := TDADBISAMMacroProcessor.Create; end; function TDAEDBISAMConnection.GetForceBufferFlush: Boolean; begin result := fConnection.Session.ForceBufferFlush; end; procedure TDAEDBISAMConnection.SetForceBufferFlush(Value: Boolean); begin fConnection.Session.ForceBufferFlush := Value; end; function TDAEDBISAMConnection.GetKeepConnections: Boolean; begin result := fConnection.Session.KeepConnections; end; procedure TDAEDBISAMConnection.SetKeepConnections(Value: Boolean); begin fConnection.Session.KeepConnections := Value; fConnection.Database.KeepConnection := Value; end; function TDAEDBISAMConnection.GetLockProtocol: TLockProtocol; begin result := fConnection.Session.LockProtocol; end; procedure TDAEDBISAMConnection.SetLockProtocol(Value: TLockProtocol); begin fConnection.Session.LockProtocol := Value; end; function TDAEDBISAMConnection.GetLockRetryCount: Byte; begin result := fConnection.Session.LockRetryCount; end; procedure TDAEDBISAMConnection.SetLockRetryCount(Value: Byte); begin fConnection.Session.LockRetryCount := Value; end; function TDAEDBISAMConnection.GetLockWaitTime: Word; begin result := fConnection.Session.LockWaitTime; end; procedure TDAEDBISAMConnection.SetLockWaitTime(Value: Word); begin fConnection.Session.LockWaitTime := Value; end; function TDAEDBISAMConnection.GetPrivateDir: string; begin result := fConnection.Session.PrivateDir; end; procedure TDAEDBISAMConnection.SetPrivateDir(const Value: string); begin fConnection.Session.PrivateDir := Value; end; function TDAEDBISAMConnection.GetRemotePort: Integer; begin result := fConnection.Session.RemotePort; end; procedure TDAEDBISAMConnection.SetRemotePort(Value: Integer); begin fConnection.Session.RemotePort := Value; end; function TDAEDBISAMConnection.GetRemoteService: string; begin result := fConnection.Session.RemoteService; end; procedure TDAEDBISAMConnection.SetRemoteService(const Value: string); begin fConnection.Session.RemoteService := Value; end; function TDAEDBISAMConnection.GetRemoteTrace: Boolean; begin result := fConnection.Session.RemoteTrace; end; procedure TDAEDBISAMConnection.SetRemoteTrace(Value: Boolean); begin fConnection.Session.RemoteTrace := Value; end; {$IFDEF DBISAM_V3} function TDAEDBISAMConnection.GetRemoteType: TRemoteType; begin result := fConnection.Session.RemoteType; end; procedure TDAEDBISAMConnection.SetRemoteType(Value: TRemoteType); begin fConnection.Session.RemoteType := Value; end; {$ENDIF} {$IFDEF DBISAM_V4} function TDAEDBISAMConnection.GetRemoteCompression: Byte; begin result := fConnection.Session.RemoteCompression; end; procedure TDAEDBISAMConnection.SetRemoteCompression(Value: Byte); begin fConnection.Session.RemoteCompression := Value; end; function TDAEDBISAMConnection.GetRemoteEncryption: Boolean; begin result := fConnection.Session.RemoteEncryption; end; procedure TDAEDBISAMConnection.SetRemoteEncryption(Value: Boolean); begin fConnection.Session.RemoteEncryption := Value; end; function TDAEDBISAMConnection.GetRemoteEncryptionPassword: string; begin result := fConnection.Session.RemoteEncryptionPassword; end; procedure TDAEDBISAMConnection.SetRemoteEncryptionPassword(const Value: string); begin fConnection.Session.RemoteEncryptionPassword := Value; end; function TDAEDBISAMConnection.GetRemoteTimeout: Integer; begin result := fConnection.Session.RemoteTimeout; end; procedure TDAEDBISAMConnection.SetRemoteTimeout(Value: Integer); begin fConnection.Session.RemoteTimeout := Value; end; {$ENDIF} procedure TDAEDBISAMConnection.AddPassword( const aPassword: string); begin fConnection.Session.AddPassword(aPassword); end; procedure TDAEDBISAMConnection.RemovePassword( const aPassword: string); begin fConnection.Session.RemovePassword(aPassword); end; procedure TDAEDBISAMConnection.RemoveAllPasswords; begin fConnection.Session.RemoveAllPasswords; end; function TDAEDBISAMConnection.DoGetLastAutoInc( const GeneratorName: string): integer; var lQuery: IDADataset; begin Result:= inherited DoGetLastAutoInc(GeneratorName); if GeneratorName <> '' then begin lQuery:=GetDatasetClass.Create(Self); try lQuery.SQL := 'SELECT LASTAUTOINC('''+GeneratorName+''') from '+QuoteIdentifierIfNeeded(GeneratorName); lQuery.Open; Result := lQuery.Fields[0].AsInteger; finally lQuery:=nil; end; end; end; {$IFDEF DELPHI10UP} {$WARN SYMBOL_DEPRECATED OFF} {$ENDIF DELPHI10UP} procedure TDAEDBISAMConnection.DoGetTableFields(const aTableName: string; out Fields: TDAFieldCollection); var i: integer; pos1: integer; fld: TDAField; {$IFDEF DBISAM_V4} lofld:TDBISAMFieldDef; {$ELSE} lofld:TFieldDef; {$ENDIF} s: string; ltable: TDBISAMTable; begin Fields:=TDAFieldCollection.Create(nil); ltable:=TDBISAMTable.Create(nil); try ltable.DatabaseName := fConnection.Database.DatabaseName; ltable.SessionName := fConnection.Session.SessionName; ltable.TableName := aTableName; ltable.FieldDefs.Update; for i:=0 to ltable.FieldDefs.Count-1 do begin lofld:=ltable.FieldDefs[i]; fld:= Fields.Add; fld.Name:= lofld.Name; fld.DataType:= VCLTypeToDAType(lofld.DataType); fld.Size:= lofld.Size; fld.Required:= lofld.Required; {$IFDEF DBISAM_V4} fld.DefaultValue:=lofld.DefaultValue; fld.Description:=lofld.Description; {$ENDIF DBISAM_V4} fld.ReadOnly:= DB.faReadonly in lofld.Attributes; if fld.DataType = datAutoInc then fld.GeneratorName:= aTableName; if fld.DataType = datDecimal then begin case lofld.DataType of ftBCD: begin fld.DecimalPrecision:=20; fld.DecimalScale:=lofld.Size; end; end; end; end; //pk ltable.IndexDefs.Update; For i:=0 to ltable.IndexDefs.Count - 1 do if ixPrimary in ltable.IndexDefs[i].Options then begin Pos1 := 1; s:=ltable.IndexDefs[i].Fields; while Pos1 <= Length(s) do begin fld := Fields.FindField(ExtractFieldName(s, Pos1)); if fld <> nil then fld.InPrimaryKey:=True; end; end; finally ltable.free; end; end; {$IFDEF DELPHI10UP} {$WARN SYMBOL_DEPRECATED ON} {$ENDIF DELPHI10UP} function TDAEDBISAMConnection.IdentifierNeedsQuoting( const iIdentifier: string): boolean; begin Result := inherited IdentifierNeedsQuoting(iIdentifier) or TestIdentifier(iIdentifier,dbisam_reservedwords); end; { TDAEDBISAMDriver } procedure TDAEDBISAMDriver.GetAuxParams(const AuxDriver: string; out List: IROStrings); begin inherited; List.Add('ForceBufferFlush=False,True'); List.Add('KeepConnections=False,True'); List.Add('LockProtocol=lpOptimistic,lpPessimistic'); List.Add('LockRetryCount='); List.Add('LockWaitTime='); List.Add('PrivateDir='); List.Add('RemotePort='); List.Add('RemoteService='); List.Add('RemoteTrace=False,True'); List.Add('TablePassword='); {$IFDEF DBISAM_V3} List.Add('RemoteType=rtLAN,rtInternet'); {$ENDIF} {$IFDEF DBISAM_V4} List.Add('RemoteCompression='); List.Add('RemoteEncryption=False,True'); List.Add('RemoteEncryptionPassword='); List.Add('RemoteTimeout='); {$ENDIF} List.Sorted := True; end; function TDAEDBISAMDriver.GetAvailableDriverOptions: TDAAvailableDriverOptions; begin result := [doServerName, doDatabaseName, doLogin, doCustom]; end; function TDAEDBISAMDriver.GetConnectionClass: TDAEConnectionClass; begin result := TDAEDBISAMConnection end; function TDAEDBISAMDriver.GetDefaultConnectionType( const AuxDriver: string): string; begin Result:=DBISAM_DriverType; end; function TDAEDBISAMDriver.GetDescription: string; begin {$IFDEF DBISAM_V3} result := 'DBISAM3 Driver'{$IFDEF DataAbstract_SchemaModelerOnly} + SchemaModelerOnly{$ENDIF}; {$ENDIF} {$IFDEF DBISAM_V4} result := 'DBISAM4 Driver'{$IFDEF DataAbstract_SchemaModelerOnly} + SchemaModelerOnly{$ENDIF}; {$ENDIF} end; function TDAEDBISAMDriver.GetDriverID: string; begin {$IFDEF DBISAM_V3} result := 'DBISAM3'; {$ENDIF} {$IFDEF DBISAM_V4} result := 'DBISAM4'; {$ENDIF} end; { TDAEDBISAMQuery } function TDAEDBISAMQuery.CreateDataset(aConnection: TDAEConnection): TDataset; begin result := TDBISAMQuery.Create(nil); with TDBISAMQuery(result) do begin DatabaseName := TDAEDBISAMConnection(aConnection).fConnection.Database.DatabaseName; SessionName := TDAEDBISAMConnection(aConnection).fConnection.Session.SessionName; ReadOnly := True; RequestLive := True; end; end; function TDAEDBISAMQuery.DoExecute: integer; begin with TDBISAMQuery(Dataset) do begin ExecSQL; result := RowsAffected; end; end; function TDAEDBISAMQuery.DoGetSQL: string; begin result := TDBISAMQuery(Dataset).SQL.Text end; procedure TDAEDBISAMQuery.DoPrepare(Value: Boolean); begin TDBISAMQuery(Dataset).Prepared := Value; end; procedure TDAEDBISAMQuery.SetParamValues(AParams: TDAParamCollection); var i: integer; par: uDAInterfaces.TDAParam; {$IFDEF DBISAM_V4} outpar: TDBISAMParam; {$ELSE} outpar: TParam; {$ENDIF} ft: TFieldType; lParIsEmpty: Boolean; begin for i := 0 to (AParams.Count - 1) do begin par := AParams[i]; outpar := TDBISAMQuery(Dataset).Params.ParamByName(par.Name); ft := DATypeToVCLType(par.DataType); {$IFNDEF DBISAM_V4} case par.ParamType of daptInput: outpar.ParamType := ptInput; daptOutput: outpar.ParamType := ptOutput; daptInputOutput: outpar.ParamType := ptInputOutput; daptResult: outpar.ParamType := ptResult; end; {$ENDIF DBISAM_V3} lParIsEmpty := VarIsEmpty(par.Value) or VarIsNull(par.Value); if par.DataType = datBlob then begin outpar.DataType := ftBlob; if not (par.ParamType in [daptOutput, daptResult]) then begin if lParIsEmpty 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 outpar.Value := par.Value; end; if lParIsEmpty and (par.DataType <> datUnknown) then begin if (outpar.DataType <> ft) and (ft <> ftUnknown) then outpar.DataType := ft; end; end; end; procedure TDAEDBISAMQuery.GetParamValues(AParams: TDAParamCollection); var i: integer; par: uDAInterfaces.TDAParam; begin for i := 0 to (AParams.Count - 1) do begin par := AParams[i]; if Par.ParamType in [daptOutput, daptInputOutput, daptResult] then Par.Value := TDBISAMQuery(Dataset).Params.ParamByName(par.Name).Value; end; end; procedure TDAEDBISAMQuery.DoSetSQL(const Value: string); begin TDBISAMQuery(Dataset).SQL.Text := Value; end; {$IFDEF DBISAM_V4} procedure TDAEDBISAMQuery.RefreshParams; var i: Integer; par: TDAParam; outpar: TDBISAMParam; ds: TDBISAMQuery; begin inherited; ds := TDBISAMQuery(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 begin par.DataType := VCLTypeToDAType(outpar.DataType); end; end; end; {$ENDIF} exports GetDriverObject name func_GetDriverObject; procedure TDAEDBISAMQuery.ClearParams; begin inherited; TDBISAMQuery(Dataset).Params.Clear; end; procedure dbisam_InitializeReservedWords; begin SetLength(dbisam_reservedwords, 220); // sorted with TStringList.Sort (bds2007) dbisam_reservedwords[0] := 'ABS'; dbisam_reservedwords[1] := 'ACOS'; dbisam_reservedwords[2] := 'ADD'; dbisam_reservedwords[3] := 'ALL'; dbisam_reservedwords[4] := 'ALLTRIM'; dbisam_reservedwords[5] := 'ALTER'; dbisam_reservedwords[6] := 'AND'; dbisam_reservedwords[7] := 'AS'; dbisam_reservedwords[8] := 'ASC'; dbisam_reservedwords[9] := 'ASCENDING'; dbisam_reservedwords[10] := 'ASIN'; dbisam_reservedwords[11] := 'AT'; dbisam_reservedwords[12] := 'ATAN'; dbisam_reservedwords[13] := 'ATAN2'; dbisam_reservedwords[14] := 'AUTOINC'; dbisam_reservedwords[15] := 'AVG'; dbisam_reservedwords[16] := 'BETWEEN'; dbisam_reservedwords[17] := 'BINARY'; dbisam_reservedwords[18] := 'BIT'; dbisam_reservedwords[19] := 'BLOB'; dbisam_reservedwords[20] := 'BLOCK'; dbisam_reservedwords[21] := 'BOOL'; dbisam_reservedwords[22] := 'BOOLEAN'; dbisam_reservedwords[23] := 'BOTH'; dbisam_reservedwords[24] := 'BY'; dbisam_reservedwords[25] := 'BYTES'; dbisam_reservedwords[26] := 'CAST'; dbisam_reservedwords[27] := 'CEIL'; dbisam_reservedwords[28] := 'CEILING'; dbisam_reservedwords[29] := 'CHAR'; dbisam_reservedwords[30] := 'CHARACTER'; dbisam_reservedwords[31] := 'CHARCASE'; dbisam_reservedwords[32] := 'CHARS'; dbisam_reservedwords[33] := 'COALESCE'; dbisam_reservedwords[34] := 'COLUMN'; dbisam_reservedwords[35] := 'COLUMNS'; dbisam_reservedwords[36] := 'COMMIT'; dbisam_reservedwords[37] := 'COMPRESS'; dbisam_reservedwords[38] := 'CONCAT'; dbisam_reservedwords[39] := 'CONSTRAINT'; dbisam_reservedwords[40] := 'COS'; dbisam_reservedwords[41] := 'COT'; dbisam_reservedwords[42] := 'COUNT'; dbisam_reservedwords[43] := 'CREATE'; dbisam_reservedwords[44] := 'CURRENT_DATE'; dbisam_reservedwords[45] := 'CURRENT_GUID'; dbisam_reservedwords[46] := 'CURRENT_TIME'; dbisam_reservedwords[47] := 'CURRENT_TIMESTAMP'; dbisam_reservedwords[48] := 'DAY'; dbisam_reservedwords[49] := 'DAYOFWEEK'; dbisam_reservedwords[50] := 'DAYOFYEAR'; dbisam_reservedwords[51] := 'DAYSFROMMSECS'; dbisam_reservedwords[52] := 'DECIMAL'; dbisam_reservedwords[53] := 'DEFAULT'; dbisam_reservedwords[54] := 'DEGREES'; dbisam_reservedwords[55] := 'DELETE'; dbisam_reservedwords[56] := 'DELIMITER'; dbisam_reservedwords[57] := 'DESC'; dbisam_reservedwords[58] := 'DESCENDING'; dbisam_reservedwords[59] := 'DESCRIPTION'; dbisam_reservedwords[60] := 'DISTINCT'; dbisam_reservedwords[61] := 'DROP'; dbisam_reservedwords[62] := 'DUPBYTE'; dbisam_reservedwords[63] := 'ELSE'; dbisam_reservedwords[64] := 'EMPTY'; dbisam_reservedwords[65] := 'ENCRYPTED'; dbisam_reservedwords[66] := 'ESCAPE'; dbisam_reservedwords[67] := 'EXCEPT'; dbisam_reservedwords[68] := 'EXISTS'; dbisam_reservedwords[69] := 'EXP'; dbisam_reservedwords[70] := 'EXPORT'; dbisam_reservedwords[71] := 'EXTRACT'; dbisam_reservedwords[72] := 'FALSE'; dbisam_reservedwords[73] := 'FLOAT'; dbisam_reservedwords[74] := 'FLOOR'; dbisam_reservedwords[75] := 'FLUSH'; dbisam_reservedwords[76] := 'FOR'; dbisam_reservedwords[77] := 'FORCEINDEXREBUILD'; dbisam_reservedwords[78] := 'FROM'; dbisam_reservedwords[79] := 'FULL'; dbisam_reservedwords[80] := 'GRAPHIC'; dbisam_reservedwords[81] := 'GROUP'; dbisam_reservedwords[82] := 'GUID'; dbisam_reservedwords[83] := 'HAVING'; dbisam_reservedwords[84] := 'HEADERS'; dbisam_reservedwords[85] := 'HOUR'; dbisam_reservedwords[86] := 'HOURSFROMMSECS'; dbisam_reservedwords[87] := 'IDENT_CURRENT'; dbisam_reservedwords[88] := 'IDENTITY'; dbisam_reservedwords[89] := 'IF'; dbisam_reservedwords[90] := 'IFNULL'; dbisam_reservedwords[91] := 'IMPORT'; dbisam_reservedwords[92] := 'IN'; dbisam_reservedwords[93] := 'INCLUDE'; dbisam_reservedwords[94] := 'INDEX'; dbisam_reservedwords[95] := 'INNER'; dbisam_reservedwords[96] := 'INSERT'; dbisam_reservedwords[97] := 'INT'; dbisam_reservedwords[98] := 'INTEGER'; dbisam_reservedwords[99] := 'INTERSECT'; dbisam_reservedwords[100] := 'INTERVAL'; dbisam_reservedwords[101] := 'INTO'; dbisam_reservedwords[102] := 'IS'; dbisam_reservedwords[103] := 'JOIN'; dbisam_reservedwords[104] := 'KEY'; dbisam_reservedwords[105] := 'LARGEINT'; dbisam_reservedwords[106] := 'LAST'; dbisam_reservedwords[107] := 'LASTAUTOINC'; dbisam_reservedwords[108] := 'LCASE'; dbisam_reservedwords[109] := 'LEADING'; dbisam_reservedwords[110] := 'LEFT'; dbisam_reservedwords[111] := 'LENGTH'; dbisam_reservedwords[112] := 'LIKE'; dbisam_reservedwords[113] := 'LOCALE'; dbisam_reservedwords[114] := 'LOG'; dbisam_reservedwords[115] := 'LOG10'; dbisam_reservedwords[116] := 'LONGVARBINARY'; dbisam_reservedwords[117] := 'LONGVARCHAR'; dbisam_reservedwords[118] := 'LOWER'; dbisam_reservedwords[119] := 'LTRIM'; dbisam_reservedwords[120] := 'MAJOR'; dbisam_reservedwords[121] := 'MAX'; dbisam_reservedwords[122] := 'MAXIMUM'; dbisam_reservedwords[123] := 'MEMO'; dbisam_reservedwords[124] := 'MIN'; dbisam_reservedwords[125] := 'MINIMUM'; dbisam_reservedwords[126] := 'MINOR'; dbisam_reservedwords[127] := 'MINSFROMMSECS'; dbisam_reservedwords[128] := 'MINUTE'; dbisam_reservedwords[129] := 'MOD'; dbisam_reservedwords[130] := 'MONEY'; dbisam_reservedwords[131] := 'MONTH'; dbisam_reservedwords[132] := 'MSECOND'; dbisam_reservedwords[133] := 'MSECSFROMMSECS'; dbisam_reservedwords[134] := 'NOBACKUP'; dbisam_reservedwords[135] := 'NOCASE'; dbisam_reservedwords[136] := 'NOCHANGE'; dbisam_reservedwords[137] := 'NOJOINOPTIMIZE'; dbisam_reservedwords[138] := 'NONE'; dbisam_reservedwords[139] := 'NOT'; dbisam_reservedwords[140] := 'NULL'; dbisam_reservedwords[141] := 'NUMERIC'; dbisam_reservedwords[142] := 'OCCURS'; dbisam_reservedwords[143] := 'ON'; dbisam_reservedwords[144] := 'OPTIMIZE'; dbisam_reservedwords[145] := 'OR'; dbisam_reservedwords[146] := 'ORDER'; dbisam_reservedwords[147] := 'OUTER'; dbisam_reservedwords[148] := 'PAGE'; dbisam_reservedwords[149] := 'PI'; dbisam_reservedwords[150] := 'POS'; dbisam_reservedwords[151] := 'POSITION'; dbisam_reservedwords[152] := 'POWER'; dbisam_reservedwords[153] := 'PRIMARY'; dbisam_reservedwords[154] := 'RADIANS'; dbisam_reservedwords[155] := 'RAND'; dbisam_reservedwords[156] := 'RANGE'; dbisam_reservedwords[157] := 'REDEFINE'; dbisam_reservedwords[158] := 'RENAME'; dbisam_reservedwords[159] := 'REPAIR'; dbisam_reservedwords[160] := 'REPEAT'; dbisam_reservedwords[161] := 'REPLACE'; dbisam_reservedwords[162] := 'RIGHT'; dbisam_reservedwords[163] := 'ROLLBACK'; dbisam_reservedwords[164] := 'ROUND'; dbisam_reservedwords[165] := 'RTRIM'; dbisam_reservedwords[166] := 'RUNSUM'; dbisam_reservedwords[167] := 'SECOND'; dbisam_reservedwords[168] := 'SECSFROMMSECS'; dbisam_reservedwords[169] := 'SELECT'; dbisam_reservedwords[170] := 'SET'; dbisam_reservedwords[171] := 'SIGN'; dbisam_reservedwords[172] := 'SIN'; dbisam_reservedwords[173] := 'SIZE'; dbisam_reservedwords[174] := 'SMALLINT'; dbisam_reservedwords[175] := 'SPACE'; dbisam_reservedwords[176] := 'SQRT'; dbisam_reservedwords[177] := 'START'; dbisam_reservedwords[178] := 'STDDEV'; dbisam_reservedwords[179] := 'STOP'; dbisam_reservedwords[180] := 'SUBSTRING'; dbisam_reservedwords[181] := 'SUM'; dbisam_reservedwords[182] := 'TABLE'; dbisam_reservedwords[183] := 'TAN'; dbisam_reservedwords[184] := 'TEXT'; dbisam_reservedwords[185] := 'TEXTOCCURS'; dbisam_reservedwords[186] := 'TEXTSEARCH'; dbisam_reservedwords[187] := 'THEN'; dbisam_reservedwords[188] := 'TIME'; dbisam_reservedwords[189] := 'TIMESTAMP'; dbisam_reservedwords[190] := 'TO'; dbisam_reservedwords[191] := 'TOP'; dbisam_reservedwords[192] := 'TRAILBYTE'; dbisam_reservedwords[193] := 'TRAILING'; dbisam_reservedwords[194] := 'TRANSACTION'; dbisam_reservedwords[195] := 'TRIM'; dbisam_reservedwords[196] := 'TRUE'; dbisam_reservedwords[197] := 'TRUNC'; dbisam_reservedwords[198] := 'TRUNCATE'; dbisam_reservedwords[199] := 'UCASE'; dbisam_reservedwords[200] := 'UNION'; dbisam_reservedwords[201] := 'UNIQUE'; dbisam_reservedwords[202] := 'UPDATE'; dbisam_reservedwords[203] := 'UPGRADE'; dbisam_reservedwords[204] := 'UPPER'; dbisam_reservedwords[205] := 'USER'; dbisam_reservedwords[206] := 'VALUES'; dbisam_reservedwords[207] := 'VARBINARY'; dbisam_reservedwords[208] := 'VARBYTES'; dbisam_reservedwords[209] := 'VARCHAR'; dbisam_reservedwords[210] := 'VERIFY'; dbisam_reservedwords[211] := 'VERSION'; dbisam_reservedwords[212] := 'WEEK'; dbisam_reservedwords[213] := 'WHERE'; dbisam_reservedwords[214] := 'WITH'; dbisam_reservedwords[215] := 'WORD'; dbisam_reservedwords[216] := 'WORDS'; dbisam_reservedwords[217] := 'WORK'; dbisam_reservedwords[218] := 'YEAR'; dbisam_reservedwords[219] := 'YEARSFROMMSECS'; end; initialization _driver := nil; RegisterDriverProc(GetDriverObject); dbisam_InitializeReservedWords; finalization dbisam_reservedwords := nil; UnregisterDriverProc(GetDriverObject); FreeAndNIL(_driver); end.