78 |
|
{$IFDEF FPC} Dynlibs, {$ENDIF} |
79 |
|
IB, IBHeader, FBActivityMonitor, FBMessages, IBExternals, FmtBCD; |
80 |
|
|
81 |
< |
{For Linux see result of GetFirebirdLibList method} |
81 |
> |
{For Linux see result of GetFirebirdLibListruntime/nongui/winipc.inc method} |
82 |
|
{$IFDEF DARWIN} |
83 |
|
const |
84 |
|
FIREBIRD_SO2 = 'libfbclient.dylib'; |
115 |
|
|
116 |
|
{ TFBStatus } |
117 |
|
|
118 |
< |
TFBStatus = class(TFBInterfacedObject) |
118 |
> |
TFBStatus = class(TFBInterfacedObject, IStatus) |
119 |
|
private |
120 |
|
FIBDataBaseErrorMessages: TIBDataBaseErrorMessages; |
121 |
+ |
FPrefix: AnsiString; |
122 |
+ |
function SQLCodeSupported: boolean; |
123 |
|
protected |
124 |
|
FOwner: TFBClientAPI; |
125 |
+ |
function GetIBMessage: Ansistring; virtual; abstract; |
126 |
+ |
function GetSQLMessage: Ansistring; |
127 |
|
public |
128 |
< |
constructor Create(aOwner: TFBClientAPI); |
128 |
> |
constructor Create(aOwner: TFBClientAPI; prefix: AnsiString=''); |
129 |
> |
constructor Copy(src: TFBStatus); |
130 |
|
function StatusVector: PStatusVector; virtual; abstract; |
131 |
+ |
function Clone: IStatus; virtual; abstract; |
132 |
|
|
133 |
|
{IStatus} |
134 |
< |
function GetIBErrorCode: Long; |
135 |
< |
function Getsqlcode: Long; |
134 |
> |
function InErrorState: boolean; virtual; abstract; |
135 |
> |
function GetIBErrorCode: TStatusCode; |
136 |
> |
function Getsqlcode: TStatusCode; |
137 |
|
function GetMessage: AnsiString; |
138 |
|
function CheckStatusVector(ErrorCodes: array of TFBStatusCode): Boolean; |
139 |
|
function GetIBDataBaseErrorMessages: TIBDataBaseErrorMessages; |
200 |
|
|
201 |
|
public |
202 |
|
{Taken from legacy API} |
196 |
– |
isc_sqlcode: Tisc_sqlcode; |
203 |
|
isc_sql_interprete: Tisc_sql_interprete; |
204 |
< |
isc_event_counts: Tisc_event_counts; |
199 |
< |
isc_event_block: Tisc_event_block; |
200 |
< |
isc_free: Tisc_free; |
204 |
> |
isc_sqlcode: Tisc_sqlcode; |
205 |
|
|
206 |
|
constructor Create(aFBLibrary: TFBLibrary); |
207 |
|
procedure IBAlloc(var P; OldSize, NewSize: Integer); |
224 |
|
property LocalTimeOffset: integer read FLocalTimeOffset; |
225 |
|
public |
226 |
|
{Encode/Decode} |
227 |
< |
procedure EncodeInteger(aValue: integer; len: integer; buffer: PByte); |
228 |
< |
function DecodeInteger(bufptr: PByte; len: short): integer; virtual; abstract; |
227 |
> |
procedure EncodeInteger(aValue: int64; len: integer; buffer: PByte); |
228 |
> |
function DecodeInteger(bufptr: PByte; len: short): int64; |
229 |
|
procedure SQLEncodeDate(aDate: TDateTime; bufptr: PByte); virtual; abstract; |
230 |
|
function SQLDecodeDate(byfptr: PByte): TDateTime; virtual; abstract; |
231 |
|
procedure SQLEncodeTime(aTime: TDateTime; bufptr: PByte); virtual; abstract; |
232 |
|
function SQLDecodeTime(bufptr: PByte): TDateTime; virtual; abstract; |
233 |
|
procedure SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte); virtual; abstract; |
234 |
|
function SQLDecodeDateTime(bufptr: PByte): TDateTime; virtual; abstract; |
231 |
– |
function FormatStatus(Status: TFBStatus): AnsiString; virtual; abstract; |
235 |
|
function Int128ToStr(bufptr: PByte; scale: integer): AnsiString; virtual; |
236 |
|
procedure StrToInt128(scale: integer; aValue: AnsiString; bufptr: PByte); |
237 |
|
virtual; |
246 |
|
function GetImplementationVersion: AnsiString; |
247 |
|
function GetClientMajor: integer; virtual; abstract; |
248 |
|
function GetClientMinor: integer; virtual; abstract; |
249 |
< |
end; |
249 |
> |
end; |
250 |
> |
|
251 |
> |
IJournallingHook = interface |
252 |
> |
['{7d3e45e0-3628-416a-9e22-c20474825031}'] |
253 |
> |
procedure TransactionStart(Tr: ITransaction); |
254 |
> |
function TransactionEnd(TransactionID: integer; Completion: TTrCompletionState): boolean; |
255 |
> |
procedure TransactionRetained(Tr: ITransaction; OldTransactionID: integer; Action: TTransactionAction); |
256 |
> |
procedure ExecQuery(Stmt: IStatement); |
257 |
> |
procedure ExecImmediateJnl(sql: AnsiString; tr: ITransaction); |
258 |
> |
end; |
259 |
|
|
260 |
|
implementation |
261 |
|
|
413 |
|
raise EIBInterBaseError.Create(GetStatus); |
414 |
|
end; |
415 |
|
|
416 |
< |
procedure TFBClientAPI.EncodeInteger(aValue: integer; len: integer; buffer: PByte); |
416 |
> |
procedure TFBClientAPI.EncodeInteger(aValue: int64; len: integer; buffer: PByte); |
417 |
|
begin |
418 |
|
while len > 0 do |
419 |
|
begin |
424 |
|
end; |
425 |
|
end; |
426 |
|
|
427 |
+ |
(* |
428 |
+ |
DecodeInteger is Translated from |
429 |
+ |
|
430 |
+ |
SINT64 API_ROUTINE isc_portable_integer(const UCHAR* ptr, SSHORT length) |
431 |
+ |
if (!ptr || length <= 0 || length > 8) |
432 |
+ |
return 0; |
433 |
+ |
|
434 |
+ |
SINT64 value = 0; |
435 |
+ |
int shift = 0; |
436 |
+ |
|
437 |
+ |
while (--length > 0) |
438 |
+ |
{ |
439 |
+ |
value += ((SINT64) *ptr++) << shift; |
440 |
+ |
shift += 8; |
441 |
+ |
} |
442 |
+ |
|
443 |
+ |
value += ((SINT64)(SCHAR) *ptr) << shift; |
444 |
+ |
|
445 |
+ |
return value; |
446 |
+ |
*) |
447 |
+ |
|
448 |
+ |
function TFBClientAPI.DecodeInteger(bufptr: PByte; len: short): int64; |
449 |
+ |
var shift: integer; |
450 |
+ |
begin |
451 |
+ |
Result := 0; |
452 |
+ |
if (BufPtr = nil) or (len <= 0) or (len > 8) then |
453 |
+ |
Exit; |
454 |
+ |
|
455 |
+ |
shift := 0; |
456 |
+ |
dec(len); |
457 |
+ |
while len > 0 do |
458 |
+ |
begin |
459 |
+ |
Result := Result + (int64(bufptr^) shl shift); |
460 |
+ |
Inc(bufptr); |
461 |
+ |
shift := shift + 8; |
462 |
+ |
dec(len); |
463 |
+ |
end; |
464 |
+ |
Result := Result + (int64(bufptr^) shl shift); |
465 |
+ |
end; |
466 |
+ |
|
467 |
|
function TFBClientAPI.Int128ToStr(bufptr: PByte; scale: integer): AnsiString; |
468 |
|
begin |
469 |
|
if not HasInt128Support then |
510 |
|
end; |
511 |
|
|
512 |
|
{$IFDEF UNIX} |
513 |
+ |
|
514 |
|
procedure TFBClientAPI.GetTZDataSettings; |
515 |
|
var S: TStringList; |
516 |
|
begin |
517 |
|
FLocalTimeOffset := GetLocalTimeOffset; |
518 |
< |
FLocalTimeZoneName := strpas(tzname[tzdaylight]); |
518 |
> |
{$if declared(Gettzname)} |
519 |
> |
FLocalTimeZoneName := Gettzname(tzdaylight); |
520 |
> |
{$else} |
521 |
> |
FLocalTimeZoneName := tzname[tzdaylight]; |
522 |
> |
{$ifend} |
523 |
|
FIsDaylightSavingsTime := tzdaylight; |
524 |
|
if FileExists(DefaultTimeZoneFile) then |
525 |
|
begin |
564 |
|
|
565 |
|
function TFBClientAPI.GetProcAddr(ProcName: PAnsiChar): Pointer; |
566 |
|
begin |
567 |
< |
Result := GetProcAddress(FFBLibrary.IBLibrary, ProcName); |
567 |
> |
Result := nil; |
568 |
> |
if assigned(FFBLibrary) and (FFBLibrary.IBLibrary <> NilHandle) then |
569 |
> |
Result := GetProcAddress(FFBLibrary.IBLibrary, ProcName); |
570 |
|
if not Assigned(Result) then |
571 |
|
raise Exception.CreateFmt(SFirebirdAPIFuncNotFound,[ProcName]); |
572 |
|
end; |
605 |
|
begin |
606 |
|
isc_sqlcode := GetProcAddr('isc_sqlcode'); {do not localize} |
607 |
|
isc_sql_interprete := GetProcAddr('isc_sql_interprete'); {do not localize} |
549 |
– |
isc_event_counts := GetProcAddr('isc_event_counts'); {do not localize} |
550 |
– |
isc_event_block := GetProcAddr('isc_event_block'); {do not localize} |
551 |
– |
isc_free := GetProcAddr('isc_free'); {do not localize} |
608 |
|
fb_shutdown := GetProcAddr('fb_shutdown'); {do not localize} |
609 |
< |
Result := assigned(isc_free); |
609 |
> |
Result := true; {don't case if these fail to load} |
610 |
|
end; |
611 |
|
|
612 |
|
procedure TFBClientAPI.FBShutdown; |
617 |
|
|
618 |
|
{ TFBStatus } |
619 |
|
|
620 |
< |
constructor TFBStatus.Create(aOwner: TFBClientAPI); |
620 |
> |
function TFBStatus.SQLCodeSupported: boolean; |
621 |
> |
begin |
622 |
> |
Result:= (FOwner <> nil) and assigned(FOwner.isc_sqlcode) and assigned(FOwner.isc_sql_interprete); |
623 |
> |
end; |
624 |
> |
|
625 |
> |
function TFBStatus.GetSQLMessage: Ansistring; |
626 |
> |
var local_buffer: array[0..IBHugeLocalBufferLength - 1] of AnsiChar; |
627 |
> |
begin |
628 |
> |
Result := ''; |
629 |
> |
if (FOwner <> nil) and assigned(FOwner.isc_sql_interprete) then |
630 |
> |
begin |
631 |
> |
FOwner.isc_sql_interprete(Getsqlcode, local_buffer, sizeof(local_buffer)); |
632 |
> |
Result := strpas(local_buffer); |
633 |
> |
end; |
634 |
> |
end; |
635 |
> |
|
636 |
> |
constructor TFBStatus.Create(aOwner: TFBClientAPI; prefix: AnsiString); |
637 |
|
begin |
638 |
|
inherited Create; |
639 |
|
FOwner := aOwner; |
640 |
< |
FIBDataBaseErrorMessages := [ShowSQLMessage, ShowIBMessage]; |
640 |
> |
FPrefix := prefix; |
641 |
> |
FIBDataBaseErrorMessages := [ShowIBMessage]; |
642 |
|
end; |
643 |
|
|
644 |
< |
function TFBStatus.GetIBErrorCode: Long; |
644 |
> |
constructor TFBStatus.Copy(src: TFBStatus); |
645 |
> |
begin |
646 |
> |
inherited Create; |
647 |
> |
FOwner := src.FOwner; |
648 |
> |
FPrefix := src.FPrefix; |
649 |
> |
SetIBDataBaseErrorMessages(src.GetIBDataBaseErrorMessages); |
650 |
> |
end; |
651 |
> |
|
652 |
> |
function TFBStatus.GetIBErrorCode: TStatusCode; |
653 |
|
begin |
654 |
|
Result := StatusVector^[1]; |
655 |
|
end; |
656 |
|
|
657 |
< |
function TFBStatus.Getsqlcode: Long; |
657 |
> |
function TFBStatus.Getsqlcode: TStatusCode; |
658 |
|
begin |
659 |
< |
with FOwner do |
660 |
< |
Result := isc_sqlcode(PISC_STATUS(StatusVector)); |
659 |
> |
if (FOwner <> nil) and assigned(FOwner.isc_sqlcode) then |
660 |
> |
Result := FOwner.isc_sqlcode(PISC_STATUS(StatusVector)) |
661 |
> |
else |
662 |
> |
Result := -999; {generic SQL Code} |
663 |
|
end; |
664 |
|
|
665 |
|
function TFBStatus.GetMessage: AnsiString; |
666 |
< |
var local_buffer: array[0..IBHugeLocalBufferLength - 1] of AnsiChar; |
584 |
< |
IBDataBaseErrorMessages: TIBDataBaseErrorMessages; |
585 |
< |
sqlcode: Long; |
666 |
> |
var IBDataBaseErrorMessages: TIBDataBaseErrorMessages; |
667 |
|
begin |
668 |
< |
Result := ''; |
668 |
> |
Result := FPrefix; |
669 |
|
IBDataBaseErrorMessages := FIBDataBaseErrorMessages; |
670 |
< |
sqlcode := Getsqlcode; |
671 |
< |
if (ShowSQLCode in IBDataBaseErrorMessages) then |
672 |
< |
Result := Result + 'SQLCODE: ' + IntToStr(sqlcode); {do not localize} |
673 |
< |
|
674 |
< |
Exclude(IBDataBaseErrorMessages, ShowSQLMessage); |
675 |
< |
if (ShowSQLMessage in IBDataBaseErrorMessages) then |
676 |
< |
begin |
677 |
< |
with FOwner do |
678 |
< |
isc_sql_interprete(sqlcode, local_buffer, sizeof(local_buffer)); |
679 |
< |
if (ShowSQLCode in FIBDataBaseErrorMessages) then |
680 |
< |
Result := Result + CRLF; |
600 |
< |
Result := Result + strpas(local_buffer); |
670 |
> |
if SQLCodeSupported then |
671 |
> |
begin |
672 |
> |
if (ShowSQLCode in IBDataBaseErrorMessages) then |
673 |
> |
Result := Result + 'SQLCODE: ' + IntToStr(Getsqlcode); {do not localize} |
674 |
> |
|
675 |
> |
if (ShowSQLMessage in IBDataBaseErrorMessages) then |
676 |
> |
begin |
677 |
> |
if ShowSQLCode in IBDataBaseErrorMessages then |
678 |
> |
Result := Result + LineEnding; |
679 |
> |
Result := Result + GetSQLMessage; |
680 |
> |
end; |
681 |
|
end; |
682 |
|
|
683 |
|
if (ShowIBMessage in IBDataBaseErrorMessages) then |
684 |
|
begin |
685 |
< |
if (ShowSQLCode in IBDataBaseErrorMessages) or |
606 |
< |
(ShowSQLMessage in IBDataBaseErrorMessages) then |
685 |
> |
if Result <> FPrefix then |
686 |
|
Result := Result + LineEnding; |
687 |
< |
Result := Result + FOwner.FormatStatus(self); |
687 |
> |
Result := Result + 'Engine Code: ' + IntToStr(GetIBErrorCode) + LineEnding + GetIBMessage; |
688 |
|
end; |
689 |
|
if (Result <> '') and (Result[Length(Result)] = '.') then |
690 |
|
Delete(Result, Length(Result), 1); |