121 |
|
TIBXSQLVAR = class(TSQLVarData) |
122 |
|
private |
123 |
|
FStatement: TFB25Statement; |
124 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
125 |
|
FBlob: IBlob; {Cache references} |
126 |
|
FArray: IArray; |
127 |
|
FNullIndicator: short; |
128 |
|
FOwnsSQLData: boolean; |
129 |
|
FBlobMetaData: IBlobMetaData; |
130 |
|
FArrayMetaData: IArrayMetaData; |
131 |
+ |
FMetadataSize: short; {size of field from metadata} |
132 |
|
FXSQLVAR: PXSQLVAR; { Points to the PXSQLVAR in the owner object } |
133 |
|
protected |
134 |
|
function GetSQLType: cardinal; override; |
140 |
|
function GetScale: integer; override; |
141 |
|
function GetCharSetID: cardinal; override; |
142 |
|
function GetCodePage: TSystemCodePage; override; |
143 |
+ |
function GetCharSetWidth: integer; override; |
144 |
|
function GetIsNull: Boolean; override; |
145 |
|
function GetIsNullable: boolean; override; |
146 |
|
function GetSQLData: PByte; override; |
147 |
|
function GetDataLength: cardinal; override; |
148 |
+ |
function GetSize: cardinal; override; |
149 |
|
procedure SetIsNull(Value: Boolean); override; |
150 |
|
procedure SetIsNullable(Value: Boolean); override; |
151 |
|
procedure SetSQLData(AValue: PByte; len: cardinal); override; |
181 |
|
function GetXSQLDA: PXSQLDA; |
182 |
|
protected |
183 |
|
FStatement: TFB25Statement; |
184 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
185 |
|
function GetTransactionSeqNo: integer; override; |
186 |
|
procedure FreeXSQLDA; |
187 |
|
function GetStatement: IStatement; override; |
246 |
|
private |
247 |
|
FDBHandle: TISC_DB_HANDLE; |
248 |
|
FHandle: TISC_STMT_HANDLE; |
249 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
250 |
|
FSQLParams: TIBXINPUTSQLDA; |
251 |
|
FSQLRecord: TIBXOUTPUTSQLDA; |
252 |
|
FCursor: AnsiString; { Cursor name...} |
258 |
|
procedure InternalPrepare; override; |
259 |
|
function InternalExecute(aTransaction: ITransaction): IResults; override; |
260 |
|
function InternalOpenCursor(aTransaction: ITransaction): IResultSet; override; |
261 |
+ |
procedure ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; var processedSQL: AnsiString); override; |
262 |
|
procedure FreeHandle; override; |
263 |
|
procedure InternalClose(Force: boolean); override; |
264 |
|
public |
265 |
|
constructor Create(Attachment: TFB25Attachment; Transaction: ITransaction; |
266 |
|
sql: AnsiString; aSQLDialect: integer); |
267 |
|
constructor CreateWithParameterNames(Attachment: TFB25Attachment; |
268 |
< |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean); |
268 |
> |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean; |
269 |
> |
CaseSensitiveParams: boolean=false); |
270 |
|
destructor Destroy; override; |
271 |
|
function FetchNext: boolean; |
272 |
|
|
358 |
|
CharSetID2CodePage(GetCharSetID,result); |
359 |
|
end; |
360 |
|
|
361 |
+ |
function TIBXSQLVAR.GetCharSetWidth: integer; |
362 |
+ |
begin |
363 |
+ |
result := 1; |
364 |
+ |
with Statement.GetAttachment DO |
365 |
+ |
CharSetWidth(GetCharSetID,result); |
366 |
+ |
end; |
367 |
+ |
|
368 |
|
function TIBXSQLVAR.GetIsNull: Boolean; |
369 |
|
begin |
370 |
|
result := IsNullable and (FNullIndicator = -1); |
385 |
|
Result := FXSQLVAR^.sqllen; |
386 |
|
end; |
387 |
|
|
388 |
+ |
function TIBXSQLVAR.GetSize: cardinal; |
389 |
+ |
begin |
390 |
+ |
Result := FMetadataSize; |
391 |
+ |
end; |
392 |
+ |
|
393 |
|
function TIBXSQLVAR.GetArrayMetaData: IArrayMetaData; |
394 |
|
begin |
395 |
|
if GetSQLType <> SQL_ARRAY then |
461 |
|
begin |
462 |
|
inherited Initialize; |
463 |
|
FOwnsSQLData := true; |
464 |
< |
with FirebirdClientAPI, FXSQLVar^ do |
464 |
> |
with FFirebird25ClientAPI, FXSQLVar^ do |
465 |
|
begin |
466 |
+ |
FMetadataSize := sqllen; |
467 |
|
case sqltype and (not 1) of |
468 |
|
SQL_TEXT, SQL_TYPE_DATE, SQL_TYPE_TIME, SQL_TIMESTAMP, |
469 |
|
SQL_BLOB, SQL_ARRAY, SQL_QUAD, SQL_SHORT, SQL_BOOLEAN, |
547 |
|
if not FOwnsSQLData then |
548 |
|
FXSQLVAR^.sqldata := nil; |
549 |
|
FXSQLVAR^.sqllen := len; |
550 |
< |
with FirebirdClientAPI do |
550 |
> |
with FFirebird25ClientAPI do |
551 |
|
IBAlloc(FXSQLVAR^.sqldata, 0, FXSQLVAR^.sqllen); |
552 |
|
FOwnsSQLData := true; |
553 |
|
Changed; |
579 |
|
begin |
580 |
|
inherited Create(aParent,aIndex); |
581 |
|
FStatement := aParent.Statement; |
582 |
+ |
FFirebird25ClientAPI := aParent.FFirebird25ClientAPI; |
583 |
|
end; |
584 |
|
|
585 |
|
procedure TIBXSQLVAR.FreeSQLData; |
650 |
|
begin |
651 |
|
if Count = 0 then |
652 |
|
Count := 1; |
653 |
< |
with Firebird25ClientAPI do |
653 |
> |
with FFirebird25ClientAPI do |
654 |
|
begin |
655 |
|
if (FXSQLDA <> nil) then |
656 |
|
if isc_dsql_describe_bind(StatusVector, @(FStatement.Handle), FStatement.SQLDialect, |
682 |
|
begin |
683 |
|
{ Allocate an initial output descriptor (with one column) } |
684 |
|
Count := 1; |
685 |
< |
with Firebird25ClientAPI do |
685 |
> |
with FFirebird25ClientAPI do |
686 |
|
begin |
687 |
|
{ Using isc_dsql_describe, get the right size for the columns... } |
688 |
|
if isc_dsql_describe(StatusVector, @(FStatement.Handle), FStatement.SQLDialect, FXSQLDA) > 0 then |
717 |
|
len := sqllen; |
718 |
|
if not IsNull and ((sqltype and (not 1)) = SQL_VARYING) then |
719 |
|
begin |
720 |
< |
with FirebirdClientAPI do |
720 |
> |
with FFirebird25ClientAPI do |
721 |
|
len := DecodeInteger(data,2); |
722 |
|
Inc(data,2); |
723 |
|
end; |
734 |
|
begin |
735 |
|
inherited Create; |
736 |
|
FStatement := aStatement; |
737 |
+ |
FFirebird25ClientAPI := aStatement.FFirebird25ClientAPI; |
738 |
|
FSize := 0; |
739 |
|
// writeln('Creating ',ClassName); |
740 |
|
end; |
821 |
|
OldSize := 0; |
822 |
|
if Count > FSize then |
823 |
|
begin |
824 |
< |
Firebird25ClientAPI.IBAlloc(FXSQLDA, OldSize, XSQLDA_LENGTH(Count)); |
824 |
> |
FFirebird25ClientAPI.IBAlloc(FXSQLDA, OldSize, XSQLDA_LENGTH(Count)); |
825 |
|
SetLength(FColumnList, FCount); |
826 |
|
FXSQLDA^.version := SQLDA_VERSION1; |
827 |
|
p := @FXSQLDA^.sqlvar[0]; |
919 |
|
procedure TFB25Statement.GetDsqlInfo(info_request: byte; buffer: ISQLInfoResults |
920 |
|
); |
921 |
|
begin |
922 |
< |
with Firebird25ClientAPI, buffer as TSQLInfoResultsBuffer do |
922 |
> |
with FFirebird25ClientAPI, buffer as TSQLInfoResultsBuffer do |
923 |
|
if isc_dsql_sql_info(StatusVector, @(FHandle), 1, @info_request, |
924 |
|
GetBufSize, Buffer) > 0 then |
925 |
|
IBDatabaseError; |
936 |
|
IBError(ibxeEmptyQuery, [nil]); |
937 |
|
try |
938 |
|
CheckTransaction(FTransactionIntf); |
939 |
< |
with Firebird25ClientAPI do |
939 |
> |
with FFirebird25ClientAPI do |
940 |
|
begin |
941 |
|
Call(isc_dsql_alloc_statement2(StatusVector, @(FDBHandle), |
942 |
|
@FHandle), True); |
944 |
|
if FHasParamNames then |
945 |
|
begin |
946 |
|
if FProcessedSQL = '' then |
947 |
< |
FSQLParams.PreprocessSQL(FSQL,FGenerateParamNames,FProcessedSQL); |
947 |
> |
ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL); |
948 |
|
Call(isc_dsql_prepare(StatusVector, @(TRHandle), @FHandle, 0, |
949 |
|
PAnsiChar(FProcessedSQL), FSQLDialect, nil), True); |
950 |
|
end |
988 |
|
if (FHandle <> nil) then |
989 |
|
FreeHandle; |
990 |
|
if E is EIBInterBaseError then |
991 |
< |
raise EIBInterBaseError.Create(EIBInterBaseError(E).SQLCode, |
992 |
< |
EIBInterBaseError(E).IBErrorCode, |
970 |
< |
EIBInterBaseError(E).Message + |
971 |
< |
sSQLErrorSeparator + FSQL) |
972 |
< |
else |
973 |
< |
raise; |
991 |
> |
E.Message := E.Message + sSQLErrorSeparator + FSQL; |
992 |
> |
raise; |
993 |
|
end; |
994 |
|
end; |
995 |
|
FPrepared := true; |
1026 |
|
|
1027 |
|
try |
1028 |
|
TRHandle := (aTransaction as TFB25Transaction).Handle; |
1029 |
< |
with Firebird25ClientAPI do |
1029 |
> |
with FFirebird25ClientAPI do |
1030 |
|
begin |
1031 |
|
if FCollectStatistics then |
1032 |
|
GetPerfCounters(FBeforeStats); |
1087 |
|
if (FSQLParams.FTransactionSeqNo < (FTransactionIntf as TFB25transaction).TransactionSeqNo) then |
1088 |
|
IBError(ibxeInterfaceOutofDate,[nil]); |
1089 |
|
|
1090 |
< |
with Firebird25ClientAPI do |
1090 |
> |
with FFirebird25ClientAPI do |
1091 |
|
begin |
1092 |
|
if FCollectStatistics then |
1093 |
|
GetPerfCounters(FBeforeStats); |
1126 |
|
Inc(FChangeSeqNo); |
1127 |
|
end; |
1128 |
|
|
1129 |
+ |
procedure TFB25Statement.ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; |
1130 |
+ |
var processedSQL: AnsiString); |
1131 |
+ |
begin |
1132 |
+ |
FSQLParams.PreprocessSQL(sql,GenerateParamNames, processedSQL); |
1133 |
+ |
end; |
1134 |
+ |
|
1135 |
|
procedure TFB25Statement.FreeHandle; |
1136 |
|
var |
1137 |
|
isc_res: ISC_STATUS; |
1140 |
|
ReleaseInterfaces; |
1141 |
|
try |
1142 |
|
if FHandle <> nil then |
1143 |
< |
with Firebird25ClientAPI do |
1143 |
> |
with FFirebird25ClientAPI do |
1144 |
|
begin |
1145 |
|
isc_res := |
1146 |
|
Call(isc_dsql_free_statement(StatusVector, @FHandle, DSQL_drop), False); |
1160 |
|
begin |
1161 |
|
if (FHandle <> nil) and (SQLStatementType = SQLSelect) and FOpen then |
1162 |
|
try |
1163 |
< |
with Firebird25ClientAPI do |
1163 |
> |
with FFirebird25ClientAPI do |
1164 |
|
begin |
1165 |
|
isc_res := Call( |
1166 |
|
isc_dsql_free_statement(StatusVector, @FHandle, DSQL_close), |
1185 |
|
begin |
1186 |
|
inherited Create(Attachment,Transaction,sql,aSQLDialect); |
1187 |
|
FDBHandle := Attachment.Handle; |
1188 |
+ |
FFirebird25ClientAPI := Attachment.Firebird25ClientAPI; |
1189 |
+ |
OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError; |
1190 |
|
FSQLParams := TIBXINPUTSQLDA.Create(self); |
1191 |
|
FSQLRecord := TIBXOUTPUTSQLDA.Create(self); |
1192 |
|
InternalPrepare; |
1193 |
|
end; |
1194 |
|
|
1195 |
< |
constructor TFB25Statement.CreateWithParameterNames(Attachment: TFB25Attachment; |
1196 |
< |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; |
1197 |
< |
GenerateParamNames: boolean); |
1195 |
> |
constructor TFB25Statement.CreateWithParameterNames( |
1196 |
> |
Attachment: TFB25Attachment; Transaction: ITransaction; sql: AnsiString; |
1197 |
> |
aSQLDialect: integer; GenerateParamNames: boolean; |
1198 |
> |
CaseSensitiveParams: boolean); |
1199 |
|
begin |
1200 |
|
inherited CreateWithParameterNames(Attachment,Transaction,sql,aSQLDialect,GenerateParamNames); |
1201 |
|
FDBHandle := Attachment.Handle; |
1202 |
+ |
FFirebird25ClientAPI := Attachment.Firebird25ClientAPI; |
1203 |
+ |
OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError; |
1204 |
|
FSQLParams := TIBXINPUTSQLDA.Create(self); |
1205 |
+ |
FSQLParams.CaseSensitiveParams := CaseSensitiveParams; |
1206 |
|
FSQLRecord := TIBXOUTPUTSQLDA.Create(self); |
1207 |
|
InternalPrepare; |
1208 |
|
end; |
1224 |
|
if FEOF then |
1225 |
|
IBError(ibxeEOF,[nil]); |
1226 |
|
|
1227 |
< |
with Firebird25ClientAPI do |
1227 |
> |
with FFirebird25ClientAPI do |
1228 |
|
begin |
1229 |
|
{ Go to the next record... } |
1230 |
|
fetch_res := |
1250 |
|
FBOF := false; |
1251 |
|
result := true; |
1252 |
|
end; |
1253 |
+ |
if FCollectStatistics then |
1254 |
+ |
begin |
1255 |
+ |
GetPerfCounters(FAfterStats); |
1256 |
+ |
FStatisticsAvailable := true; |
1257 |
+ |
end; |
1258 |
|
end; |
1259 |
|
FSQLRecord.RowChange; |
1260 |
|
if FEOF then |
1287 |
|
result := '' |
1288 |
|
else |
1289 |
|
begin |
1290 |
< |
RB := TSQLInfoResultsBuffer.Create(4*4096); |
1290 |
> |
RB := TSQLInfoResultsBuffer.Create(FFirebird25ClientAPI,4*4096); |
1291 |
|
GetDsqlInfo(isc_info_sql_get_plan,RB); |
1292 |
|
if RB.Count > 0 then |
1293 |
|
Result := RB[0].GetAsString; |