121 |
|
TIBXSQLVAR = class(TSQLVarData) |
122 |
|
private |
123 |
|
FStatement: TFB25Statement; |
124 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
125 |
|
FBlob: IBlob; {Cache references} |
126 |
|
FArray: IArray; |
127 |
|
FNullIndicator: short; |
178 |
|
function GetXSQLDA: PXSQLDA; |
179 |
|
protected |
180 |
|
FStatement: TFB25Statement; |
181 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
182 |
|
function GetTransactionSeqNo: integer; override; |
183 |
|
procedure FreeXSQLDA; |
184 |
|
function GetStatement: IStatement; override; |
243 |
|
private |
244 |
|
FDBHandle: TISC_DB_HANDLE; |
245 |
|
FHandle: TISC_STMT_HANDLE; |
246 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
247 |
|
FSQLParams: TIBXINPUTSQLDA; |
248 |
|
FSQLRecord: TIBXOUTPUTSQLDA; |
249 |
|
FCursor: AnsiString; { Cursor name...} |
255 |
|
procedure InternalPrepare; override; |
256 |
|
function InternalExecute(aTransaction: ITransaction): IResults; override; |
257 |
|
function InternalOpenCursor(aTransaction: ITransaction): IResultSet; override; |
258 |
+ |
procedure ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; var processedSQL: AnsiString); override; |
259 |
|
procedure FreeHandle; override; |
260 |
|
procedure InternalClose(Force: boolean); override; |
261 |
|
public |
262 |
|
constructor Create(Attachment: TFB25Attachment; Transaction: ITransaction; |
263 |
|
sql: AnsiString; aSQLDialect: integer); |
264 |
|
constructor CreateWithParameterNames(Attachment: TFB25Attachment; |
265 |
< |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean); |
265 |
> |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean; |
266 |
> |
CaseSensitiveParams: boolean=false); |
267 |
|
destructor Destroy; override; |
268 |
|
function FetchNext: boolean; |
269 |
|
|
446 |
|
begin |
447 |
|
inherited Initialize; |
448 |
|
FOwnsSQLData := true; |
449 |
< |
with FirebirdClientAPI, FXSQLVar^ do |
449 |
> |
with FFirebird25ClientAPI, FXSQLVar^ do |
450 |
|
begin |
451 |
|
case sqltype and (not 1) of |
452 |
|
SQL_TEXT, SQL_TYPE_DATE, SQL_TYPE_TIME, SQL_TIMESTAMP, |
531 |
|
if not FOwnsSQLData then |
532 |
|
FXSQLVAR^.sqldata := nil; |
533 |
|
FXSQLVAR^.sqllen := len; |
534 |
< |
with FirebirdClientAPI do |
534 |
> |
with FFirebird25ClientAPI do |
535 |
|
IBAlloc(FXSQLVAR^.sqldata, 0, FXSQLVAR^.sqllen); |
536 |
|
FOwnsSQLData := true; |
537 |
|
Changed; |
563 |
|
begin |
564 |
|
inherited Create(aParent,aIndex); |
565 |
|
FStatement := aParent.Statement; |
566 |
+ |
FFirebird25ClientAPI := aParent.FFirebird25ClientAPI; |
567 |
|
end; |
568 |
|
|
569 |
|
procedure TIBXSQLVAR.FreeSQLData; |
634 |
|
begin |
635 |
|
if Count = 0 then |
636 |
|
Count := 1; |
637 |
< |
with Firebird25ClientAPI do |
637 |
> |
with FFirebird25ClientAPI do |
638 |
|
begin |
639 |
|
if (FXSQLDA <> nil) then |
640 |
|
if isc_dsql_describe_bind(StatusVector, @(FStatement.Handle), FStatement.SQLDialect, |
666 |
|
begin |
667 |
|
{ Allocate an initial output descriptor (with one column) } |
668 |
|
Count := 1; |
669 |
< |
with Firebird25ClientAPI do |
669 |
> |
with FFirebird25ClientAPI do |
670 |
|
begin |
671 |
|
{ Using isc_dsql_describe, get the right size for the columns... } |
672 |
|
if isc_dsql_describe(StatusVector, @(FStatement.Handle), FStatement.SQLDialect, FXSQLDA) > 0 then |
701 |
|
len := sqllen; |
702 |
|
if not IsNull and ((sqltype and (not 1)) = SQL_VARYING) then |
703 |
|
begin |
704 |
< |
with FirebirdClientAPI do |
704 |
> |
with FFirebird25ClientAPI do |
705 |
|
len := DecodeInteger(data,2); |
706 |
|
Inc(data,2); |
707 |
|
end; |
718 |
|
begin |
719 |
|
inherited Create; |
720 |
|
FStatement := aStatement; |
721 |
+ |
FFirebird25ClientAPI := aStatement.FFirebird25ClientAPI; |
722 |
|
FSize := 0; |
723 |
|
// writeln('Creating ',ClassName); |
724 |
|
end; |
805 |
|
OldSize := 0; |
806 |
|
if Count > FSize then |
807 |
|
begin |
808 |
< |
Firebird25ClientAPI.IBAlloc(FXSQLDA, OldSize, XSQLDA_LENGTH(Count)); |
808 |
> |
FFirebird25ClientAPI.IBAlloc(FXSQLDA, OldSize, XSQLDA_LENGTH(Count)); |
809 |
|
SetLength(FColumnList, FCount); |
810 |
|
FXSQLDA^.version := SQLDA_VERSION1; |
811 |
|
p := @FXSQLDA^.sqlvar[0]; |
903 |
|
procedure TFB25Statement.GetDsqlInfo(info_request: byte; buffer: ISQLInfoResults |
904 |
|
); |
905 |
|
begin |
906 |
< |
with Firebird25ClientAPI, buffer as TSQLInfoResultsBuffer do |
906 |
> |
with FFirebird25ClientAPI, buffer as TSQLInfoResultsBuffer do |
907 |
|
if isc_dsql_sql_info(StatusVector, @(FHandle), 1, @info_request, |
908 |
|
GetBufSize, Buffer) > 0 then |
909 |
|
IBDatabaseError; |
920 |
|
IBError(ibxeEmptyQuery, [nil]); |
921 |
|
try |
922 |
|
CheckTransaction(FTransactionIntf); |
923 |
< |
with Firebird25ClientAPI do |
923 |
> |
with FFirebird25ClientAPI do |
924 |
|
begin |
925 |
|
Call(isc_dsql_alloc_statement2(StatusVector, @(FDBHandle), |
926 |
|
@FHandle), True); |
928 |
|
if FHasParamNames then |
929 |
|
begin |
930 |
|
if FProcessedSQL = '' then |
931 |
< |
FSQLParams.PreprocessSQL(FSQL,FGenerateParamNames,FProcessedSQL); |
931 |
> |
ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL); |
932 |
|
Call(isc_dsql_prepare(StatusVector, @(TRHandle), @FHandle, 0, |
933 |
|
PAnsiChar(FProcessedSQL), FSQLDialect, nil), True); |
934 |
|
end |
1014 |
|
|
1015 |
|
try |
1016 |
|
TRHandle := (aTransaction as TFB25Transaction).Handle; |
1017 |
< |
with Firebird25ClientAPI do |
1017 |
> |
with FFirebird25ClientAPI do |
1018 |
|
begin |
1019 |
|
if FCollectStatistics then |
1020 |
|
GetPerfCounters(FBeforeStats); |
1053 |
|
RemoveMonitor(aTransaction as TFB25Transaction); |
1054 |
|
end; |
1055 |
|
FExecTransactionIntf := aTransaction; |
1056 |
+ |
FSQLRecord.FTransaction := aTransaction as TFB25Transaction; |
1057 |
+ |
FSQLRecord.FTransactionSeqNo := FSQLRecord.FTransaction.TransactionSeqNo; |
1058 |
|
Inc(FChangeSeqNo); |
1059 |
|
end; |
1060 |
|
|
1075 |
|
if (FSQLParams.FTransactionSeqNo < (FTransactionIntf as TFB25transaction).TransactionSeqNo) then |
1076 |
|
IBError(ibxeInterfaceOutofDate,[nil]); |
1077 |
|
|
1078 |
< |
with Firebird25ClientAPI do |
1078 |
> |
with FFirebird25ClientAPI do |
1079 |
|
begin |
1080 |
|
if FCollectStatistics then |
1081 |
|
GetPerfCounters(FBeforeStats); |
1114 |
|
Inc(FChangeSeqNo); |
1115 |
|
end; |
1116 |
|
|
1117 |
+ |
procedure TFB25Statement.ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; |
1118 |
+ |
var processedSQL: AnsiString); |
1119 |
+ |
begin |
1120 |
+ |
FSQLParams.PreprocessSQL(sql,GenerateParamNames, processedSQL); |
1121 |
+ |
end; |
1122 |
+ |
|
1123 |
|
procedure TFB25Statement.FreeHandle; |
1124 |
|
var |
1125 |
|
isc_res: ISC_STATUS; |
1128 |
|
ReleaseInterfaces; |
1129 |
|
try |
1130 |
|
if FHandle <> nil then |
1131 |
< |
with Firebird25ClientAPI do |
1131 |
> |
with FFirebird25ClientAPI do |
1132 |
|
begin |
1133 |
|
isc_res := |
1134 |
|
Call(isc_dsql_free_statement(StatusVector, @FHandle, DSQL_drop), False); |
1148 |
|
begin |
1149 |
|
if (FHandle <> nil) and (SQLStatementType = SQLSelect) and FOpen then |
1150 |
|
try |
1151 |
< |
with Firebird25ClientAPI do |
1151 |
> |
with FFirebird25ClientAPI do |
1152 |
|
begin |
1153 |
|
isc_res := Call( |
1154 |
|
isc_dsql_free_statement(StatusVector, @FHandle, DSQL_close), |
1173 |
|
begin |
1174 |
|
inherited Create(Attachment,Transaction,sql,aSQLDialect); |
1175 |
|
FDBHandle := Attachment.Handle; |
1176 |
+ |
FFirebird25ClientAPI := Attachment.Firebird25ClientAPI; |
1177 |
+ |
OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError; |
1178 |
|
FSQLParams := TIBXINPUTSQLDA.Create(self); |
1179 |
|
FSQLRecord := TIBXOUTPUTSQLDA.Create(self); |
1180 |
|
InternalPrepare; |
1181 |
|
end; |
1182 |
|
|
1183 |
< |
constructor TFB25Statement.CreateWithParameterNames(Attachment: TFB25Attachment; |
1184 |
< |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; |
1185 |
< |
GenerateParamNames: boolean); |
1183 |
> |
constructor TFB25Statement.CreateWithParameterNames( |
1184 |
> |
Attachment: TFB25Attachment; Transaction: ITransaction; sql: AnsiString; |
1185 |
> |
aSQLDialect: integer; GenerateParamNames: boolean; |
1186 |
> |
CaseSensitiveParams: boolean); |
1187 |
|
begin |
1188 |
|
inherited CreateWithParameterNames(Attachment,Transaction,sql,aSQLDialect,GenerateParamNames); |
1189 |
|
FDBHandle := Attachment.Handle; |
1190 |
+ |
FFirebird25ClientAPI := Attachment.Firebird25ClientAPI; |
1191 |
+ |
OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError; |
1192 |
|
FSQLParams := TIBXINPUTSQLDA.Create(self); |
1193 |
+ |
FSQLParams.CaseSensitiveParams := CaseSensitiveParams; |
1194 |
|
FSQLRecord := TIBXOUTPUTSQLDA.Create(self); |
1195 |
|
InternalPrepare; |
1196 |
|
end; |
1212 |
|
if FEOF then |
1213 |
|
IBError(ibxeEOF,[nil]); |
1214 |
|
|
1215 |
< |
with Firebird25ClientAPI do |
1215 |
> |
with FFirebird25ClientAPI do |
1216 |
|
begin |
1217 |
|
{ Go to the next record... } |
1218 |
|
fetch_res := |
1238 |
|
FBOF := false; |
1239 |
|
result := true; |
1240 |
|
end; |
1241 |
+ |
if FCollectStatistics then |
1242 |
+ |
begin |
1243 |
+ |
GetPerfCounters(FAfterStats); |
1244 |
+ |
FStatisticsAvailable := true; |
1245 |
+ |
end; |
1246 |
|
end; |
1247 |
|
FSQLRecord.RowChange; |
1248 |
|
if FEOF then |
1275 |
|
result := '' |
1276 |
|
else |
1277 |
|
begin |
1278 |
< |
RB := TSQLInfoResultsBuffer.Create(4*4096); |
1278 |
> |
RB := TSQLInfoResultsBuffer.Create(FFirebird25ClientAPI,4*4096); |
1279 |
|
GetDsqlInfo(isc_info_sql_get_plan,RB); |
1280 |
|
if RB.Count > 0 then |
1281 |
|
Result := RB[0].GetAsString; |