98 |
|
FSQLSubType: integer; |
99 |
|
FSQLData: PByte; {Address of SQL Data in Message Buffer} |
100 |
|
FSQLNullIndicator: PShort; {Address of null indicator} |
101 |
< |
FDataLength: integer; |
102 |
< |
FMetadataSize: integer; |
101 |
> |
FDataLength: cardinal; |
102 |
> |
FMetadataSize: cardinal; |
103 |
|
FNullable: boolean; |
104 |
|
FScale: integer; |
105 |
|
FCharSetID: cardinal; |
116 |
|
function GetRelationName: AnsiString; override; |
117 |
|
function GetScale: integer; override; |
118 |
|
function GetCharSetID: cardinal; override; |
119 |
– |
function GetCodePage: TSystemCodePage; override; |
120 |
– |
function GetCharSetWidth: integer; override; |
119 |
|
function GetIsNull: Boolean; override; |
120 |
|
function GetIsNullable: boolean; override; |
121 |
|
function GetSQLData: PByte; override; |
122 |
|
function GetDataLength: cardinal; override; |
123 |
|
function GetSize: cardinal; override; |
126 |
– |
function GetAttachment: IAttachment; override; |
124 |
|
function GetDefaultTextSQLType: cardinal; override; |
125 |
|
procedure SetIsNull(Value: Boolean); override; |
126 |
|
procedure SetIsNullable(Value: Boolean); override; |
127 |
< |
procedure SetSQLData(AValue: PByte; len: cardinal); override; |
128 |
< |
procedure SetScale(aValue: integer); override; |
129 |
< |
procedure SetDataLength(len: cardinal); override; |
133 |
< |
procedure SetSQLType(aValue: cardinal); override; |
127 |
> |
procedure InternalSetScale(aValue: integer); override; |
128 |
> |
procedure InternalSetDataLength(len: cardinal); override; |
129 |
> |
procedure InternalSetSQLType(aValue: cardinal); override; |
130 |
|
procedure SetCharSetID(aValue: cardinal); override; |
131 |
|
procedure SetMetaSize(aValue: cardinal); override; |
132 |
|
public |
141 |
|
function GetArrayMetaData: IArrayMetaData; override; |
142 |
|
function GetBlobMetaData: IBlobMetaData; override; |
143 |
|
function CreateBlob: IBlob; override; |
144 |
+ |
procedure SetSQLData(AValue: PByte; len: cardinal); override; |
145 |
|
end; |
146 |
|
|
147 |
|
{ TIBXSQLDA } |
155 |
|
protected |
156 |
|
FStatement: TFB30Statement; |
157 |
|
FFirebird30ClientAPI: TFB30ClientAPI; |
158 |
+ |
FMessageBuffer: PByte; {Message Buffer} |
159 |
+ |
FMsgLength: integer; {Message Buffer length} |
160 |
|
function GetTransactionSeqNo: integer; override; |
161 |
|
procedure FreeXSQLDA; virtual; |
162 |
|
function GetStatement: IStatement; override; |
163 |
|
function GetPrepareSeqNo: integer; override; |
164 |
|
procedure SetCount(Value: Integer); override; |
165 |
+ |
procedure AllocMessageBuffer(len: integer); virtual; |
166 |
+ |
procedure FreeMessageBuffer; virtual; |
167 |
|
public |
168 |
< |
constructor Create(aStatement: TFB30Statement); |
168 |
> |
constructor Create(aStatement: TFB30Statement); overload; |
169 |
> |
constructor Create(api: IFirebirdAPI); overload; |
170 |
|
destructor Destroy; override; |
171 |
|
procedure Changed; virtual; |
172 |
|
function CheckStatementStatus(Request: TStatementStatus): boolean; override; |
173 |
|
function ColumnsInUseCount: integer; override; |
174 |
< |
function GetTransaction: TFB30Transaction; virtual; |
174 |
> |
function GetMetaData: Firebird.IMessageMetadata; virtual; |
175 |
|
procedure Initialize; override; |
176 |
|
function StateChanged(var ChangeSeqNo: integer): boolean; override; |
177 |
|
function CanChangeMetaData: boolean; override; |
176 |
– |
property MetaData: Firebird.IMessageMetadata read FMetaData; |
178 |
|
property Count: Integer read FCount write SetCount; |
179 |
|
property Statement: TFB30Statement read FStatement; |
180 |
|
end; |
183 |
|
|
184 |
|
TIBXINPUTSQLDA = class(TIBXSQLDA) |
185 |
|
private |
185 |
– |
FMessageBuffer: PByte; {Message Buffer} |
186 |
– |
FMsgLength: integer; {Message Buffer length} |
186 |
|
FCurMetaData: Firebird.IMessageMetadata; |
188 |
– |
procedure FreeMessageBuffer; |
187 |
|
procedure FreeCurMetaData; |
188 |
|
function GetMessageBuffer: PByte; |
191 |
– |
function GetMetaData: Firebird.IMessageMetadata; |
189 |
|
function GetModified: Boolean; |
190 |
|
function GetMsgLength: integer; |
191 |
|
procedure BuildMetadata; |
195 |
– |
procedure PackBuffer; |
192 |
|
protected |
193 |
+ |
procedure PackBuffer; |
194 |
|
procedure FreeXSQLDA; override; |
195 |
|
public |
196 |
< |
constructor Create(aStatement: TFB30Statement); |
196 |
> |
constructor Create(aStatement: TFB30Statement); overload; |
197 |
> |
constructor Create(api: IFirebirdAPI); overload; |
198 |
|
destructor Destroy; override; |
199 |
|
procedure Bind(aMetaData: Firebird.IMessageMetadata); |
200 |
|
procedure Changed; override; |
201 |
+ |
function GetMetaData: Firebird.IMessageMetadata; override; |
202 |
|
procedure ReInitialise; |
203 |
|
function IsInputDataArea: boolean; override; |
205 |
– |
property MetaData: Firebird.IMessageMetadata read GetMetaData; |
204 |
|
property MessageBuffer: PByte read GetMessageBuffer; |
205 |
|
property MsgLength: integer read GetMsgLength; |
206 |
|
end; |
210 |
|
TIBXOUTPUTSQLDA = class(TIBXSQLDA) |
211 |
|
private |
212 |
|
FTransaction: TFB30Transaction; {transaction used to execute the statement} |
215 |
– |
FMessageBuffer: PByte; {Message Buffer} |
216 |
– |
FMsgLength: integer; {Message Buffer length} |
213 |
|
protected |
214 |
< |
procedure FreeXSQLDA; override; |
214 |
> |
function GetTransaction: ITransaction; override; |
215 |
|
public |
216 |
|
procedure Bind(aMetaData: Firebird.IMessageMetadata); |
217 |
|
procedure GetData(index: integer; var aIsNull: boolean; var len: short; |
239 |
|
function FetchAbsolute(position: Integer): boolean; {fetch record by its absolute position in result set} |
240 |
|
function FetchRelative(offset: Integer): boolean; {fetch record by position relative to current} |
241 |
|
function GetCursorName: AnsiString; |
246 |
– |
function GetTransaction: ITransaction; override; |
242 |
|
function IsBof: boolean; |
243 |
|
function IsEof: boolean; |
244 |
|
procedure Close; |
302 |
|
destructor Destroy; override; |
303 |
|
function Fetch(FetchType: TFetchType; PosOrOffset: integer=0): boolean; |
304 |
|
property StatementIntf: Firebird.IStatement read FStatementIntf; |
305 |
+ |
property SQLParams: TIBXINPUTSQLDA read FSQLParams; |
306 |
+ |
property SQLRecord: TIBXOUTPUTSQLDA read FSQLRecord; |
307 |
|
|
308 |
|
public |
309 |
|
{IStatement} |
428 |
|
status := MasterIntf.getStatus; |
429 |
|
FCompletionState.getStatus(StatusIntf,status,updateNo); |
430 |
|
Check4DataBaseError; |
431 |
< |
Result := FormatFBStatus(status); |
431 |
> |
Result := FormatStatus(status); |
432 |
|
end; |
433 |
|
end; |
434 |
|
|
534 |
|
end; |
535 |
|
|
536 |
|
function TIBXSQLVAR.GetAliasName: AnsiString; |
537 |
+ |
var metadata: Firebird.IMessageMetadata; |
538 |
|
begin |
539 |
< |
with FFirebird30ClientAPI do |
540 |
< |
begin |
541 |
< |
result := strpas(TIBXSQLDA(Parent).MetaData.getAlias(StatusIntf,Index)); |
542 |
< |
Check4DataBaseError; |
539 |
> |
metadata := TIBXSQLDA(Parent).GetMetaData; |
540 |
> |
try |
541 |
> |
with FFirebird30ClientAPI do |
542 |
> |
begin |
543 |
> |
result := strpas(metaData.getAlias(StatusIntf,Index)); |
544 |
> |
Check4DataBaseError; |
545 |
> |
end; |
546 |
> |
finally |
547 |
> |
metadata.release; |
548 |
|
end; |
549 |
|
end; |
550 |
|
|
554 |
|
end; |
555 |
|
|
556 |
|
function TIBXSQLVAR.GetOwnerName: AnsiString; |
557 |
+ |
var metadata: Firebird.IMessageMetadata; |
558 |
|
begin |
559 |
< |
with FFirebird30ClientAPI do |
560 |
< |
begin |
561 |
< |
result := strpas(TIBXSQLDA(Parent).MetaData.getOwner(StatusIntf,Index)); |
562 |
< |
Check4DataBaseError; |
559 |
> |
metadata := TIBXSQLDA(Parent).GetMetaData; |
560 |
> |
try |
561 |
> |
with FFirebird30ClientAPI do |
562 |
> |
begin |
563 |
> |
result := strpas(metaData.getOwner(StatusIntf,Index)); |
564 |
> |
Check4DataBaseError; |
565 |
> |
end; |
566 |
> |
finally |
567 |
> |
metadata.release; |
568 |
|
end; |
569 |
|
end; |
570 |
|
|
599 |
|
end; |
600 |
|
end; |
601 |
|
|
593 |
– |
function TIBXSQLVAR.GetCodePage: TSystemCodePage; |
594 |
– |
begin |
595 |
– |
result := CP_NONE; |
596 |
– |
with Statement.GetAttachment do |
597 |
– |
CharSetID2CodePage(GetCharSetID,result); |
598 |
– |
end; |
599 |
– |
|
600 |
– |
function TIBXSQLVAR.GetCharSetWidth: integer; |
601 |
– |
begin |
602 |
– |
result := 1; |
603 |
– |
with Statement.GetAttachment DO |
604 |
– |
CharSetWidth(GetCharSetID,result); |
605 |
– |
end; |
606 |
– |
|
602 |
|
function TIBXSQLVAR.GetIsNull: Boolean; |
603 |
|
begin |
604 |
|
Result := IsNullable and (FSQLNullIndicator^ = -1); |
624 |
|
Result := FMetadataSize; |
625 |
|
end; |
626 |
|
|
632 |
– |
function TIBXSQLVAR.GetAttachment: IAttachment; |
633 |
– |
begin |
634 |
– |
Result := FStatement.GetAttachment; |
635 |
– |
end; |
636 |
– |
|
627 |
|
function TIBXSQLVAR.GetArrayMetaData: IArrayMetaData; |
628 |
|
begin |
629 |
|
if GetSQLType <> SQL_ARRAY then |
630 |
|
IBError(ibxeInvalidDataConversion,[nil]); |
631 |
|
|
632 |
|
if FArrayMetaData = nil then |
633 |
< |
FArrayMetaData := TFB30ArrayMetaData.Create(FStatement.GetAttachment as TFB30Attachment, |
634 |
< |
FStatement.GetTransaction as TFB30Transaction, |
633 |
> |
FArrayMetaData := TFB30ArrayMetaData.Create(GetAttachment as TFB30Attachment, |
634 |
> |
GetTransaction as TFB30Transaction, |
635 |
|
GetRelationName,GetFieldName); |
636 |
|
Result := FArrayMetaData; |
637 |
|
end; |
642 |
|
IBError(ibxeInvalidDataConversion,[nil]); |
643 |
|
|
644 |
|
if FBlobMetaData = nil then |
645 |
< |
FBlobMetaData := TFB30BlobMetaData.Create(FStatement.GetAttachment as TFB30Attachment, |
646 |
< |
FStatement.GetTransaction as TFB30Transaction, |
645 |
> |
FBlobMetaData := TFB30BlobMetaData.Create(GetAttachment as TFB30Attachment, |
646 |
> |
GetTransaction as TFB30Transaction, |
647 |
|
GetRelationName,GetFieldName, |
648 |
|
GetSubType); |
649 |
|
(FBlobMetaData as TFBBlobMetaData).SetCharSetID(GetCharSetID); |
686 |
|
Changed; |
687 |
|
end; |
688 |
|
|
689 |
< |
procedure TIBXSQLVAR.SetScale(aValue: integer); |
689 |
> |
procedure TIBXSQLVAR.InternalSetScale(aValue: integer); |
690 |
|
begin |
691 |
|
FScale := aValue; |
692 |
|
Changed; |
693 |
|
end; |
694 |
|
|
695 |
< |
procedure TIBXSQLVAR.SetDataLength(len: cardinal); |
695 |
> |
procedure TIBXSQLVAR.InternalSetDataLength(len: cardinal); |
696 |
|
begin |
697 |
|
if not FOwnsSQLData then |
698 |
|
FSQLData := nil; |
703 |
|
Changed; |
704 |
|
end; |
705 |
|
|
706 |
< |
procedure TIBXSQLVAR.SetSQLType(aValue: cardinal); |
706 |
> |
procedure TIBXSQLVAR.InternalSetSQLType(aValue: cardinal); |
707 |
|
begin |
718 |
– |
if (FSQLType <> aValue) and not CanChangeSQLType then |
719 |
– |
IBError(ibxeSQLTypeUnchangeable,[TSQLDataItem.GetSQLTypeName(FSQLType),TSQLDataItem.GetSQLTypeName(aValue)]); |
708 |
|
FSQLType := aValue; |
709 |
|
Changed; |
710 |
|
end; |
758 |
|
else |
759 |
|
begin |
760 |
|
if FArrayIntf = nil then |
761 |
< |
FArrayIntf := TFB30Array.Create(FStatement.GetAttachment as TFB30Attachment, |
762 |
< |
TIBXSQLDA(Parent).GetTransaction, |
761 |
> |
FArrayIntf := TFB30Array.Create(GetAttachment as TFB30Attachment, |
762 |
> |
GetTransaction as TFB30Transaction, |
763 |
|
GetArrayMetaData,PISC_QUAD(SQLData)^); |
764 |
|
Result := FArrayIntf; |
765 |
|
end; |
776 |
|
if IsNull then |
777 |
|
Result := nil |
778 |
|
else |
779 |
< |
Result := TFB30Blob.Create(FStatement.GetAttachment as TFB30Attachment, |
780 |
< |
TIBXSQLDA(Parent).GetTransaction, |
779 |
> |
Result := TFB30Blob.Create(GetAttachment as TFB30Attachment, |
780 |
> |
GetTransaction as TFB30Transaction, |
781 |
|
GetBlobMetaData, |
782 |
|
Blob_ID,BPB); |
783 |
|
FBlob := Result; |
786 |
|
|
787 |
|
function TIBXSQLVAR.CreateBlob: IBlob; |
788 |
|
begin |
789 |
< |
Result := TFB30Blob.Create(FStatement.GetAttachment as TFB30Attachment, |
790 |
< |
FStatement.GetTransaction as TFB30Transaction, |
789 |
> |
Result := TFB30Blob.Create(GetAttachment as TFB30Attachment, |
790 |
> |
GetTransaction as TFB30Transaction, |
791 |
|
GetSubType,GetCharSetID,nil); |
792 |
|
end; |
793 |
|
|
866 |
|
Result := FResults.FStatement.FCursor; |
867 |
|
end; |
868 |
|
|
881 |
– |
function TResultSet.GetTransaction: ITransaction; |
882 |
– |
begin |
883 |
– |
Result := FResults.FTransaction; |
884 |
– |
end; |
885 |
– |
|
869 |
|
function TResultSet.IsBof: boolean; |
870 |
|
begin |
871 |
|
Result := FResults.FStatement.FBof; |
897 |
|
end; |
898 |
|
end; |
899 |
|
|
917 |
– |
procedure TIBXINPUTSQLDA.FreeMessageBuffer; |
918 |
– |
begin |
919 |
– |
if FMessageBuffer <> nil then |
920 |
– |
begin |
921 |
– |
FreeMem(FMessageBuffer); |
922 |
– |
FMessageBuffer := nil; |
923 |
– |
end; |
924 |
– |
FMsgLength := 0; |
925 |
– |
end; |
926 |
– |
|
900 |
|
procedure TIBXINPUTSQLDA.FreeCurMetaData; |
901 |
|
begin |
902 |
|
if FCurMetaData <> nil then |
916 |
|
begin |
917 |
|
BuildMetadata; |
918 |
|
Result := FCurMetaData; |
919 |
+ |
if Result <> nil then |
920 |
+ |
Result.addRef; |
921 |
|
end; |
922 |
|
|
923 |
|
function TIBXINPUTSQLDA.GetMsgLength: integer; |
929 |
|
procedure TIBXINPUTSQLDA.BuildMetadata; |
930 |
|
var Builder: Firebird.IMetadataBuilder; |
931 |
|
i: integer; |
932 |
+ |
version: NativeInt; |
933 |
|
begin |
934 |
|
if (FCurMetaData = nil) and (Count > 0) then |
935 |
|
with FFirebird30ClientAPI do |
940 |
|
for i := 0 to Count - 1 do |
941 |
|
with TIBXSQLVar(Column[i]) do |
942 |
|
begin |
943 |
< |
Builder.setType(StatusIntf,i,FSQLType+1); |
943 |
> |
version := Builder.vtable.version; |
944 |
> |
if version >= 4 then |
945 |
> |
{Firebird 4 or later} |
946 |
> |
begin |
947 |
> |
Builder.setField(StatusIntf,i,PAnsiChar(Name)); |
948 |
> |
Check4DataBaseError; |
949 |
> |
Builder.setAlias(StatusIntf,i,PAnsiChar(Name)); |
950 |
> |
Check4DataBaseError; |
951 |
> |
end; |
952 |
> |
Builder.setType(StatusIntf,i,FSQLType); |
953 |
|
Check4DataBaseError; |
954 |
|
Builder.setSubType(StatusIntf,i,FSQLSubType); |
955 |
|
Check4DataBaseError; |
981 |
|
procedure TIBXINPUTSQLDA.PackBuffer; |
982 |
|
var i: integer; |
983 |
|
P: PByte; |
984 |
+ |
MsgLen: cardinal; |
985 |
+ |
aNullIndicator: short; |
986 |
|
begin |
987 |
|
BuildMetadata; |
988 |
|
|
989 |
|
if (FMsgLength = 0) and (FCurMetaData <> nil) then |
990 |
|
with FFirebird30ClientAPI do |
991 |
|
begin |
992 |
< |
FMsgLength := FCurMetaData.getMessageLength(StatusIntf); |
992 |
> |
MsgLen := FCurMetaData.getMessageLength(StatusIntf); |
993 |
|
Check4DataBaseError; |
994 |
|
|
995 |
< |
IBAlloc(FMessageBuffer,0,FMsgLength); |
995 |
> |
AllocMessageBuffer(MsgLen); |
996 |
|
|
997 |
|
for i := 0 to Count - 1 do |
998 |
|
with TIBXSQLVar(Column[i]) do |
1023 |
|
begin |
1024 |
|
Move(FNullIndicator,(FMessageBuffer + FCurMetaData.getNullOffset(StatusIntf,i))^,sizeof(FNullIndicator)); |
1025 |
|
Check4DataBaseError; |
1026 |
+ |
end |
1027 |
+ |
else |
1028 |
+ |
begin |
1029 |
+ |
aNullIndicator := 0; |
1030 |
+ |
Move(aNullIndicator,(FMessageBuffer + FCurMetaData.getNullOffset(StatusIntf,i))^,sizeof(aNullIndicator)); |
1031 |
|
end; |
1032 |
|
end; |
1033 |
|
end; |
1037 |
|
begin |
1038 |
|
inherited FreeXSQLDA; |
1039 |
|
FreeCurMetaData; |
1048 |
– |
FreeMessageBuffer; |
1040 |
|
end; |
1041 |
|
|
1042 |
|
constructor TIBXINPUTSQLDA.Create(aStatement: TFB30Statement); |
1045 |
|
FMessageBuffer := nil; |
1046 |
|
end; |
1047 |
|
|
1048 |
+ |
constructor TIBXINPUTSQLDA.Create(api: IFirebirdAPI); |
1049 |
+ |
begin |
1050 |
+ |
inherited Create(api); |
1051 |
+ |
FMessageBuffer := nil; |
1052 |
+ |
end; |
1053 |
+ |
|
1054 |
|
destructor TIBXINPUTSQLDA.Destroy; |
1055 |
|
begin |
1056 |
|
FreeXSQLDA; |
1061 |
|
var i: integer; |
1062 |
|
begin |
1063 |
|
FMetaData := aMetaData; |
1064 |
+ |
FMetaData.AddRef; |
1065 |
|
with FFirebird30ClientAPI do |
1066 |
|
begin |
1067 |
|
Count := aMetadata.getCount(StatusIntf); |
1104 |
|
|
1105 |
|
{ TIBXOUTPUTSQLDA } |
1106 |
|
|
1107 |
< |
procedure TIBXOUTPUTSQLDA.FreeXSQLDA; |
1107 |
> |
function TIBXOUTPUTSQLDA.GetTransaction: ITransaction; |
1108 |
|
begin |
1109 |
< |
inherited FreeXSQLDA; |
1110 |
< |
FreeMem(FMessageBuffer); |
1111 |
< |
FMessageBuffer := nil; |
1112 |
< |
FMsgLength := 0; |
1109 |
> |
if FTransaction <> nil then |
1110 |
> |
Result := FTransaction |
1111 |
> |
else |
1112 |
> |
Result := inherited GetTransaction; |
1113 |
|
end; |
1114 |
|
|
1115 |
|
procedure TIBXOUTPUTSQLDA.Bind(aMetaData: Firebird.IMessageMetadata); |
1116 |
|
var i: integer; |
1117 |
+ |
MsgLen: cardinal; |
1118 |
|
begin |
1119 |
|
FMetaData := aMetaData; |
1120 |
+ |
FMetaData.AddRef; |
1121 |
|
with FFirebird30ClientAPI do |
1122 |
|
begin |
1123 |
< |
Count := metadata.getCount(StatusIntf); |
1123 |
> |
Count := aMetaData.getCount(StatusIntf); |
1124 |
|
Check4DataBaseError; |
1125 |
|
Initialize; |
1126 |
|
|
1127 |
< |
FMsgLength := metaData.getMessageLength(StatusIntf); |
1127 |
> |
MsgLen := aMetaData.getMessageLength(StatusIntf); |
1128 |
|
Check4DataBaseError; |
1129 |
< |
IBAlloc(FMessageBuffer,0,FMsgLength); |
1129 |
> |
AllocMessageBuffer(MsgLen); |
1130 |
|
|
1131 |
|
for i := 0 to Count - 1 do |
1132 |
|
with TIBXSQLVar(Column[i]) do |
1133 |
|
begin |
1134 |
|
InitColumnMetaData(aMetaData); |
1135 |
< |
FSQLData := FMessageBuffer + metaData.getOffset(StatusIntf,i); |
1135 |
> |
FSQLData := FMessageBuffer + aMetaData.getOffset(StatusIntf,i); |
1136 |
|
Check4DataBaseError; |
1137 |
|
if FNullable then |
1138 |
|
begin |
1180 |
|
// writeln('Creating ',ClassName); |
1181 |
|
end; |
1182 |
|
|
1183 |
+ |
constructor TIBXSQLDA.Create(api: IFirebirdAPI); |
1184 |
+ |
begin |
1185 |
+ |
inherited Create; |
1186 |
+ |
FStatement := nil; |
1187 |
+ |
FSize := 0; |
1188 |
+ |
FFirebird30ClientAPI := api as TFB30ClientAPI; |
1189 |
+ |
end; |
1190 |
+ |
|
1191 |
|
destructor TIBXSQLDA.Destroy; |
1192 |
|
begin |
1193 |
|
FreeXSQLDA; |
1203 |
|
function TIBXSQLDA.CheckStatementStatus(Request: TStatementStatus): boolean; |
1204 |
|
begin |
1205 |
|
Result := false; |
1206 |
+ |
if FStatement <> nil then |
1207 |
|
case Request of |
1208 |
|
ssPrepared: |
1209 |
|
Result := FStatement.IsPrepared; |
1210 |
|
|
1211 |
|
ssExecuteResults: |
1212 |
< |
Result :=FStatement.FSingleResults; |
1212 |
> |
Result := FStatement.FSingleResults; |
1213 |
|
|
1214 |
|
ssCursorOpen: |
1215 |
|
Result := FStatement.FOpen; |
1227 |
|
Result := FCount; |
1228 |
|
end; |
1229 |
|
|
1221 |
– |
function TIBXSQLDA.GetTransaction: TFB30Transaction; |
1222 |
– |
begin |
1223 |
– |
Result := FStatement.GetTransaction as TFB30Transaction; |
1224 |
– |
end; |
1225 |
– |
|
1230 |
|
procedure TIBXSQLDA.Initialize; |
1231 |
|
begin |
1232 |
|
if FMetaData <> nil then |
1235 |
|
|
1236 |
|
function TIBXSQLDA.StateChanged(var ChangeSeqNo: integer): boolean; |
1237 |
|
begin |
1238 |
< |
Result := FStatement.ChangeSeqNo <> ChangeSeqNo; |
1238 |
> |
Result := (FStatement <> nil) and (FStatement.ChangeSeqNo <> ChangeSeqNo); |
1239 |
|
if Result then |
1240 |
|
ChangeSeqNo := FStatement.ChangeSeqNo; |
1241 |
|
end; |
1261 |
|
end; |
1262 |
|
end; |
1263 |
|
|
1264 |
+ |
procedure TIBXSQLDA.AllocMessageBuffer(len: integer); |
1265 |
+ |
begin |
1266 |
+ |
with FFirebird30ClientAPI do |
1267 |
+ |
IBAlloc(FMessageBuffer,0,len); |
1268 |
+ |
FMsgLength := len; |
1269 |
+ |
end; |
1270 |
+ |
|
1271 |
+ |
procedure TIBXSQLDA.FreeMessageBuffer; |
1272 |
+ |
begin |
1273 |
+ |
if FMessageBuffer <> nil then |
1274 |
+ |
begin |
1275 |
+ |
FreeMem(FMessageBuffer); |
1276 |
+ |
FMessageBuffer := nil; |
1277 |
+ |
end; |
1278 |
+ |
FMsgLength := 0; |
1279 |
+ |
end; |
1280 |
+ |
|
1281 |
+ |
function TIBXSQLDA.GetMetaData: Firebird.IMessageMetadata; |
1282 |
+ |
begin |
1283 |
+ |
Result := FMetadata; |
1284 |
+ |
if Result <> nil then |
1285 |
+ |
Result.addRef; |
1286 |
+ |
end; |
1287 |
+ |
|
1288 |
|
function TIBXSQLDA.GetTransactionSeqNo: integer; |
1289 |
|
begin |
1290 |
|
Result := FTransactionSeqNo; |
1303 |
|
FCount := 0; |
1304 |
|
SetLength(FColumnList,0); |
1305 |
|
FSize := 0; |
1306 |
+ |
FreeMessageBuffer; |
1307 |
|
end; |
1308 |
|
|
1309 |
|
function TIBXSQLDA.GetStatement: IStatement; |
1313 |
|
|
1314 |
|
function TIBXSQLDA.GetPrepareSeqNo: integer; |
1315 |
|
begin |
1316 |
< |
Result := FStatement.FPrepareSeqNo; |
1316 |
> |
if FStatement = nil then |
1317 |
> |
Result := 0 |
1318 |
> |
else |
1319 |
> |
Result := FStatement.FPrepareSeqNo; |
1320 |
|
end; |
1321 |
|
|
1322 |
|
{ TFB30Statement } |
1363 |
|
|
1364 |
|
procedure TFB30Statement.InternalPrepare(CursorName: AnsiString); |
1365 |
|
var GUID : TGUID; |
1366 |
+ |
metadata: Firebird.IMessageMetadata; |
1367 |
|
begin |
1368 |
|
if FPrepared then |
1369 |
|
Exit; |
1424 |
|
SQLExecProcedure: |
1425 |
|
begin |
1426 |
|
{set up input sqlda} |
1427 |
< |
FSQLParams.Bind(FStatementIntf.getInputMetadata(StatusIntf)); |
1427 |
> |
metadata := FStatementIntf.getInputMetadata(StatusIntf); |
1428 |
|
Check4DataBaseError; |
1429 |
+ |
try |
1430 |
+ |
FSQLParams.Bind(metadata); |
1431 |
+ |
finally |
1432 |
+ |
metadata.release; |
1433 |
+ |
end; |
1434 |
|
|
1435 |
|
{setup output sqlda} |
1436 |
|
if FSQLStatementType in [SQLSelect, SQLSelectForUpdate, |
1437 |
|
SQLExecProcedure] then |
1438 |
< |
FSQLRecord.Bind(FStatementIntf.getOutputMetadata(StatusIntf)); |
1439 |
< |
Check4DataBaseError; |
1438 |
> |
begin |
1439 |
> |
metadata := FStatementIntf.getOutputMetadata(StatusIntf); |
1440 |
> |
Check4DataBaseError; |
1441 |
> |
try |
1442 |
> |
FSQLRecord.Bind(metadata); |
1443 |
> |
finally |
1444 |
> |
metadata.release; |
1445 |
> |
end; |
1446 |
> |
end; |
1447 |
|
end; |
1448 |
|
end; |
1449 |
|
end; |
1477 |
|
function TFB30Statement.InternalExecute(aTransaction: ITransaction): IResults; |
1478 |
|
|
1479 |
|
procedure ExecuteQuery(outMetaData: Firebird.IMessageMetaData=nil; outBuffer: pointer=nil); |
1480 |
+ |
var inMetadata: Firebird.IMessageMetaData; |
1481 |
|
begin |
1482 |
|
with FFirebird30ClientAPI do |
1483 |
|
begin |
1484 |
|
SavePerfStats(FBeforeStats); |
1485 |
< |
FStatementIntf.execute(StatusIntf, |
1486 |
< |
(aTransaction as TFB30Transaction).TransactionIntf, |
1487 |
< |
FSQLParams.MetaData, |
1488 |
< |
FSQLParams.MessageBuffer, |
1489 |
< |
outMetaData, |
1490 |
< |
outBuffer); |
1491 |
< |
Check4DataBaseError; |
1485 |
> |
inMetadata := FSQLParams.GetMetaData; |
1486 |
> |
try |
1487 |
> |
FStatementIntf.execute(StatusIntf, |
1488 |
> |
(aTransaction as TFB30Transaction).TransactionIntf, |
1489 |
> |
inMetaData, |
1490 |
> |
FSQLParams.MessageBuffer, |
1491 |
> |
outMetaData, |
1492 |
> |
outBuffer); |
1493 |
> |
Check4DataBaseError; |
1494 |
> |
finally |
1495 |
> |
if inMetadata <> nil then |
1496 |
> |
inMetadata.release; |
1497 |
> |
end; |
1498 |
|
FStatisticsAvailable := SavePerfStats(FAfterStats); |
1499 |
|
end; |
1500 |
|
end; |
1501 |
|
|
1502 |
|
var Cursor: IResultSet; |
1503 |
+ |
outMetadata: Firebird.IMessageMetaData; |
1504 |
|
|
1505 |
|
begin |
1506 |
|
Result := nil; |
1537 |
|
|
1538 |
|
SQLExecProcedure: |
1539 |
|
begin |
1540 |
< |
ExecuteQuery(FSQLRecord.MetaData,FSQLRecord.MessageBuffer); |
1541 |
< |
Result := TResults.Create(FSQLRecord); |
1542 |
< |
FSingleResults := true; |
1540 |
> |
outMetadata := FSQLRecord.GetMetaData; |
1541 |
> |
try |
1542 |
> |
ExecuteQuery(outMetadata,FSQLRecord.MessageBuffer); |
1543 |
> |
Result := TResults.Create(FSQLRecord); |
1544 |
> |
FSingleResults := true; |
1545 |
> |
finally |
1546 |
> |
if outMetadata <> nil then |
1547 |
> |
outMetadata.release; |
1548 |
> |
end; |
1549 |
|
end; |
1550 |
|
|
1551 |
|
else |
1566 |
|
function TFB30Statement.InternalOpenCursor(aTransaction: ITransaction; |
1567 |
|
Scrollable: boolean): IResultSet; |
1568 |
|
var flags: cardinal; |
1569 |
+ |
inMetadata, |
1570 |
+ |
outMetadata: Firebird.IMessageMetadata; |
1571 |
|
begin |
1572 |
|
flags := 0; |
1573 |
|
if (FSQLStatementType <> SQLSelect) and not (stHasCursor in getFlags) then |
1596 |
|
Check4DataBaseError; |
1597 |
|
end; |
1598 |
|
|
1599 |
< |
FResultSet := FStatementIntf.openCursor(StatusIntf, |
1599 |
> |
inMetadata := FSQLParams.GetMetaData; |
1600 |
> |
outMetadata := FSQLRecord.GetMetaData; |
1601 |
> |
try |
1602 |
> |
FResultSet := FStatementIntf.openCursor(StatusIntf, |
1603 |
|
(aTransaction as TFB30Transaction).TransactionIntf, |
1604 |
< |
FSQLParams.MetaData, |
1604 |
> |
inMetaData, |
1605 |
|
FSQLParams.MessageBuffer, |
1606 |
< |
FSQLRecord.MetaData, |
1606 |
> |
outMetaData, |
1607 |
|
flags); |
1608 |
< |
Check4DataBaseError; |
1608 |
> |
Check4DataBaseError; |
1609 |
> |
finally |
1610 |
> |
if inMetadata <> nil then |
1611 |
> |
inMetadata.release; |
1612 |
> |
if outMetadata <> nil then |
1613 |
> |
outMetadata.release; |
1614 |
> |
end; |
1615 |
|
|
1616 |
|
if FCollectStatistics then |
1617 |
|
begin |
1736 |
|
): boolean; |
1737 |
|
var fetchResult: integer; |
1738 |
|
begin |
1739 |
< |
result := false; |
1739 |
> |
result := false; |
1740 |
|
if not FOpen then |
1741 |
|
IBError(ibxeSQLClosed, [nil]); |
1742 |
|
|
1749 |
|
IBError(ibxeEOF,[nil]); |
1750 |
|
{ Go to the next record... } |
1751 |
|
fetchResult := FResultSet.fetchNext(StatusIntf,FSQLRecord.MessageBuffer); |
1752 |
+ |
Check4DataBaseError; |
1753 |
|
if fetchResult = Firebird.IStatus.RESULT_NO_DATA then |
1754 |
|
begin |
1755 |
|
FBOF := false; |
1764 |
|
IBError(ibxeBOF,[nil]); |
1765 |
|
{ Go to the next record... } |
1766 |
|
fetchResult := FResultSet.fetchPrior(StatusIntf,FSQLRecord.MessageBuffer); |
1767 |
+ |
Check4DataBaseError; |
1768 |
|
if fetchResult = Firebird.IStatus.RESULT_NO_DATA then |
1769 |
|
begin |
1770 |
|
FBOF := true; |
1774 |
|
end; |
1775 |
|
|
1776 |
|
ftFirst: |
1777 |
< |
fetchResult := FResultSet.fetchFirst(StatusIntf,FSQLRecord.MessageBuffer); |
1777 |
> |
begin |
1778 |
> |
fetchResult := FResultSet.fetchFirst(StatusIntf,FSQLRecord.MessageBuffer); |
1779 |
> |
Check4DataBaseError; |
1780 |
> |
end; |
1781 |
|
|
1782 |
|
ftLast: |
1783 |
< |
fetchResult := FResultSet.fetchLast(StatusIntf,FSQLRecord.MessageBuffer); |
1783 |
> |
begin |
1784 |
> |
fetchResult := FResultSet.fetchLast(StatusIntf,FSQLRecord.MessageBuffer); |
1785 |
> |
Check4DataBaseError; |
1786 |
> |
end; |
1787 |
|
|
1788 |
|
ftAbsolute: |
1789 |
< |
fetchResult := FResultSet.fetchAbsolute(StatusIntf,PosOrOffset,FSQLRecord.MessageBuffer); |
1789 |
> |
begin |
1790 |
> |
fetchResult := FResultSet.fetchAbsolute(StatusIntf,PosOrOffset,FSQLRecord.MessageBuffer); |
1791 |
> |
Check4DataBaseError; |
1792 |
> |
end; |
1793 |
|
|
1794 |
|
ftRelative: |
1795 |
< |
fetchResult := FResultSet.fetchRelative(StatusIntf,PosOrOffset,FSQLRecord.MessageBuffer); |
1795 |
> |
begin |
1796 |
> |
fetchResult := FResultSet.fetchRelative(StatusIntf,PosOrOffset,FSQLRecord.MessageBuffer); |
1797 |
> |
Check4DataBaseError; |
1798 |
> |
end; |
1799 |
|
end; |
1800 |
|
|
1717 |
– |
Check4DataBaseError; |
1801 |
|
if fetchResult <> Firebird.IStatus.RESULT_OK then |
1802 |
|
exit; {result = false} |
1803 |
|
|
1891 |
|
|
1892 |
|
procedure TFB30Statement.AddToBatch; |
1893 |
|
var BatchPB: TXPBParameterBlock; |
1894 |
+ |
inMetadata: Firebird.IMessageMetadata; |
1895 |
|
|
1896 |
|
const SixteenMB = 16 * 1024 * 1024; |
1897 |
+ |
MB256 = 256* 1024 *1024; |
1898 |
|
begin |
1899 |
|
FBatchCompletion := nil; |
1900 |
|
if not FPrepared then |
1901 |
|
InternalPrepare; |
1902 |
|
CheckHandle; |
1903 |
|
CheckBatchModeAvailable; |
1904 |
< |
with FFirebird30ClientAPI do |
1905 |
< |
begin |
1906 |
< |
if FBatch = nil then |
1904 |
> |
inMetadata := FSQLParams.GetMetaData; |
1905 |
> |
try |
1906 |
> |
with FFirebird30ClientAPI do |
1907 |
|
begin |
1908 |
< |
{Start Batch} |
1909 |
< |
BatchPB := TXPBParameterBlock.Create(FFirebird30ClientAPI,Firebird.IXpbBuilder.BATCH); |
1910 |
< |
with FFirebird30ClientAPI do |
1911 |
< |
try |
1912 |
< |
FBatchBufferSize := FBatchRowLimit * FSQLParams.MetaData.getAlignedLength(StatusIntf); |
1913 |
< |
Check4DatabaseError; |
1914 |
< |
if FBatchBufferSize < SixteenMB then |
1915 |
< |
FBatchBufferSize := SixteenMB; |
1916 |
< |
if FBatchBufferSize > 256 * 1024 *1024 {assumed limit} then |
1917 |
< |
IBError(ibxeBatchBufferSizeTooBig,[FBatchBufferSize]); |
1918 |
< |
|
1919 |
< |
BatchPB.insertInt(Firebird.IBatch.TAG_RECORD_COUNTS,1); |
1920 |
< |
BatchPB.insertInt(Firebird.IBatch.TAG_BUFFER_BYTES_SIZE,FBatchBufferSize); |
1921 |
< |
FBatch := FStatementIntf.createBatch(StatusIntf, |
1922 |
< |
FSQLParams.MetaData, |
1923 |
< |
BatchPB.getDataLength, |
1924 |
< |
BatchPB.getBuffer); |
1925 |
< |
Check4DataBaseError; |
1908 |
> |
if FBatch = nil then |
1909 |
> |
begin |
1910 |
> |
{Start Batch} |
1911 |
> |
BatchPB := TXPBParameterBlock.Create(FFirebird30ClientAPI,Firebird.IXpbBuilder.BATCH); |
1912 |
> |
with FFirebird30ClientAPI do |
1913 |
> |
try |
1914 |
> |
if FBatchRowLimit = maxint then |
1915 |
> |
FBatchBufferSize := MB256 |
1916 |
> |
else |
1917 |
> |
begin |
1918 |
> |
FBatchBufferSize := FBatchRowLimit * inMetadata.getAlignedLength(StatusIntf); |
1919 |
> |
Check4DatabaseError; |
1920 |
> |
if FBatchBufferSize < SixteenMB then |
1921 |
> |
FBatchBufferSize := SixteenMB; |
1922 |
> |
if FBatchBufferSize > MB256 {assumed limit} then |
1923 |
> |
IBError(ibxeBatchBufferSizeTooBig,[FBatchBufferSize]); |
1924 |
> |
end; |
1925 |
> |
BatchPB.insertInt(Firebird.IBatch.TAG_RECORD_COUNTS,1); |
1926 |
> |
BatchPB.insertInt(Firebird.IBatch.TAG_BUFFER_BYTES_SIZE,FBatchBufferSize); |
1927 |
> |
FBatch := FStatementIntf.createBatch(StatusIntf, |
1928 |
> |
inMetadata, |
1929 |
> |
BatchPB.getDataLength, |
1930 |
> |
BatchPB.getBuffer); |
1931 |
> |
Check4DataBaseError; |
1932 |
|
|
1933 |
< |
finally |
1934 |
< |
BatchPB.Free; |
1933 |
> |
finally |
1934 |
> |
BatchPB.Free; |
1935 |
> |
end; |
1936 |
> |
FBatchRowCount := 0; |
1937 |
> |
FBatchBufferUsed := 0; |
1938 |
|
end; |
1845 |
– |
FBatchRowCount := 0; |
1846 |
– |
FBatchBufferUsed := 0; |
1847 |
– |
end; |
1939 |
|
|
1940 |
< |
Inc(FBatchRowCount); |
1941 |
< |
Inc(FBatchBufferUsed,FSQLParams.MetaData.getAlignedLength(StatusIntf)); |
1942 |
< |
Check4DataBaseError; |
1943 |
< |
if FBatchBufferUsed > FBatchBufferSize then |
1944 |
< |
raise EIBBatchBufferOverflow.Create(Ord(ibxeBatchRowBufferOverflow), |
1945 |
< |
Format(GetErrorMessage(ibxeBatchRowBufferOverflow), |
1946 |
< |
[FBatchRowCount,FBatchBufferSize])); |
1940 |
> |
Inc(FBatchRowCount); |
1941 |
> |
Inc(FBatchBufferUsed,inMetadata.getAlignedLength(StatusIntf)); |
1942 |
> |
Check4DataBaseError; |
1943 |
> |
if FBatchBufferUsed > FBatchBufferSize then |
1944 |
> |
raise EIBBatchBufferOverflow.Create(Ord(ibxeBatchRowBufferOverflow), |
1945 |
> |
Format(GetErrorMessage(ibxeBatchRowBufferOverflow), |
1946 |
> |
[FBatchRowCount,FBatchBufferSize])); |
1947 |
|
|
1948 |
< |
FBatch.Add(StatusIntf,1,FSQLParams.GetMessageBuffer); |
1949 |
< |
Check4DataBaseError |
1948 |
> |
FBatch.Add(StatusIntf,1,FSQLParams.GetMessageBuffer); |
1949 |
> |
Check4DataBaseError |
1950 |
> |
end; |
1951 |
> |
finally |
1952 |
> |
if inMetadata <> nil then |
1953 |
> |
inMetadata.release; |
1954 |
|
end; |
1955 |
|
end; |
1956 |
|
|