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 |
+ |
function GetAttachment: IAttachment; override; |
150 |
+ |
function GetDefaultTextSQLType: cardinal; override; |
151 |
|
procedure SetIsNull(Value: Boolean); override; |
152 |
|
procedure SetIsNullable(Value: Boolean); override; |
153 |
|
procedure SetSQLData(AValue: PByte; len: cardinal); override; |
167 |
|
procedure Initialize; override; |
168 |
|
|
169 |
|
property Statement: TFB25Statement read FStatement; |
170 |
+ |
property SQLType: cardinal read GetSQLType write SetSQLType; |
171 |
|
end; |
172 |
|
|
173 |
|
TIBXINPUTSQLDA = class; |
184 |
|
function GetXSQLDA: PXSQLDA; |
185 |
|
protected |
186 |
|
FStatement: TFB25Statement; |
187 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
188 |
|
function GetTransactionSeqNo: integer; override; |
189 |
|
procedure FreeXSQLDA; |
190 |
|
function GetStatement: IStatement; override; |
249 |
|
private |
250 |
|
FDBHandle: TISC_DB_HANDLE; |
251 |
|
FHandle: TISC_STMT_HANDLE; |
252 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
253 |
|
FSQLParams: TIBXINPUTSQLDA; |
254 |
|
FSQLRecord: TIBXOUTPUTSQLDA; |
255 |
|
FCursor: AnsiString; { Cursor name...} |
261 |
|
procedure InternalPrepare; override; |
262 |
|
function InternalExecute(aTransaction: ITransaction): IResults; override; |
263 |
|
function InternalOpenCursor(aTransaction: ITransaction): IResultSet; override; |
264 |
+ |
procedure ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; var processedSQL: AnsiString); override; |
265 |
|
procedure FreeHandle; override; |
266 |
|
procedure InternalClose(Force: boolean); override; |
267 |
|
public |
268 |
|
constructor Create(Attachment: TFB25Attachment; Transaction: ITransaction; |
269 |
|
sql: AnsiString; aSQLDialect: integer); |
270 |
|
constructor CreateWithParameterNames(Attachment: TFB25Attachment; |
271 |
< |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean); |
271 |
> |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean; |
272 |
> |
CaseSensitiveParams: boolean=false); |
273 |
|
destructor Destroy; override; |
274 |
|
function FetchNext: boolean; |
275 |
|
|
361 |
|
CharSetID2CodePage(GetCharSetID,result); |
362 |
|
end; |
363 |
|
|
364 |
+ |
function TIBXSQLVAR.GetCharSetWidth: integer; |
365 |
+ |
begin |
366 |
+ |
result := 1; |
367 |
+ |
with Statement.GetAttachment DO |
368 |
+ |
CharSetWidth(GetCharSetID,result); |
369 |
+ |
end; |
370 |
+ |
|
371 |
|
function TIBXSQLVAR.GetIsNull: Boolean; |
372 |
|
begin |
373 |
|
result := IsNullable and (FNullIndicator = -1); |
388 |
|
Result := FXSQLVAR^.sqllen; |
389 |
|
end; |
390 |
|
|
391 |
+ |
function TIBXSQLVAR.GetSize: cardinal; |
392 |
+ |
begin |
393 |
+ |
Result := FMetadataSize; |
394 |
+ |
end; |
395 |
+ |
|
396 |
+ |
function TIBXSQLVAR.GetAttachment: IAttachment; |
397 |
+ |
begin |
398 |
+ |
Result := FStatement.GetAttachment; |
399 |
+ |
end; |
400 |
+ |
|
401 |
|
function TIBXSQLVAR.GetArrayMetaData: IArrayMetaData; |
402 |
|
begin |
403 |
|
if GetSQLType <> SQL_ARRAY then |
469 |
|
begin |
470 |
|
inherited Initialize; |
471 |
|
FOwnsSQLData := true; |
472 |
< |
with FirebirdClientAPI, FXSQLVar^ do |
472 |
> |
with FFirebird25ClientAPI, FXSQLVar^ do |
473 |
|
begin |
474 |
+ |
FMetadataSize := sqllen; |
475 |
|
case sqltype and (not 1) of |
476 |
|
SQL_TEXT, SQL_TYPE_DATE, SQL_TYPE_TIME, SQL_TIMESTAMP, |
477 |
|
SQL_BLOB, SQL_ARRAY, SQL_QUAD, SQL_SHORT, SQL_BOOLEAN, |
497 |
|
else |
498 |
|
sqlInd := nil; |
499 |
|
end; |
500 |
+ |
SaveMetaData; |
501 |
|
end; |
502 |
|
|
503 |
|
procedure TIBXSQLVAR.SetIsNull(Value: Boolean); |
556 |
|
if not FOwnsSQLData then |
557 |
|
FXSQLVAR^.sqldata := nil; |
558 |
|
FXSQLVAR^.sqllen := len; |
559 |
< |
with FirebirdClientAPI do |
559 |
> |
with FFirebird25ClientAPI do |
560 |
|
IBAlloc(FXSQLVAR^.sqldata, 0, FXSQLVAR^.sqllen); |
561 |
|
FOwnsSQLData := true; |
562 |
|
Changed; |
584 |
|
end; |
585 |
|
end; |
586 |
|
|
587 |
+ |
function TIBXSQLVAR.GetDefaultTextSQLType: cardinal; |
588 |
+ |
begin |
589 |
+ |
Result := SQL_TEXT; |
590 |
+ |
end; |
591 |
+ |
|
592 |
|
constructor TIBXSQLVAR.Create(aParent: TIBXSQLDA; aIndex: integer); |
593 |
|
begin |
594 |
|
inherited Create(aParent,aIndex); |
595 |
|
FStatement := aParent.Statement; |
596 |
+ |
FFirebird25ClientAPI := aParent.FFirebird25ClientAPI; |
597 |
|
end; |
598 |
|
|
599 |
|
procedure TIBXSQLVAR.FreeSQLData; |
664 |
|
begin |
665 |
|
if Count = 0 then |
666 |
|
Count := 1; |
667 |
< |
with Firebird25ClientAPI do |
667 |
> |
with FFirebird25ClientAPI do |
668 |
|
begin |
669 |
|
if (FXSQLDA <> nil) then |
670 |
|
if isc_dsql_describe_bind(StatusVector, @(FStatement.Handle), FStatement.SQLDialect, |
696 |
|
begin |
697 |
|
{ Allocate an initial output descriptor (with one column) } |
698 |
|
Count := 1; |
699 |
< |
with Firebird25ClientAPI do |
699 |
> |
with FFirebird25ClientAPI do |
700 |
|
begin |
701 |
|
{ Using isc_dsql_describe, get the right size for the columns... } |
702 |
|
if isc_dsql_describe(StatusVector, @(FStatement.Handle), FStatement.SQLDialect, FXSQLDA) > 0 then |
731 |
|
len := sqllen; |
732 |
|
if not IsNull and ((sqltype and (not 1)) = SQL_VARYING) then |
733 |
|
begin |
734 |
< |
with FirebirdClientAPI do |
734 |
> |
with FFirebird25ClientAPI do |
735 |
|
len := DecodeInteger(data,2); |
736 |
|
Inc(data,2); |
737 |
|
end; |
748 |
|
begin |
749 |
|
inherited Create; |
750 |
|
FStatement := aStatement; |
751 |
+ |
FFirebird25ClientAPI := aStatement.FFirebird25ClientAPI; |
752 |
|
FSize := 0; |
753 |
|
// writeln('Creating ',ClassName); |
754 |
|
end; |
835 |
|
OldSize := 0; |
836 |
|
if Count > FSize then |
837 |
|
begin |
838 |
< |
Firebird25ClientAPI.IBAlloc(FXSQLDA, OldSize, XSQLDA_LENGTH(Count)); |
838 |
> |
FFirebird25ClientAPI.IBAlloc(FXSQLDA, OldSize, XSQLDA_LENGTH(Count)); |
839 |
|
SetLength(FColumnList, FCount); |
840 |
|
FXSQLDA^.version := SQLDA_VERSION1; |
841 |
|
p := @FXSQLDA^.sqlvar[0]; |
933 |
|
procedure TFB25Statement.GetDsqlInfo(info_request: byte; buffer: ISQLInfoResults |
934 |
|
); |
935 |
|
begin |
936 |
< |
with Firebird25ClientAPI, buffer as TSQLInfoResultsBuffer do |
936 |
> |
with FFirebird25ClientAPI, buffer as TSQLInfoResultsBuffer do |
937 |
|
if isc_dsql_sql_info(StatusVector, @(FHandle), 1, @info_request, |
938 |
|
GetBufSize, Buffer) > 0 then |
939 |
|
IBDatabaseError; |
950 |
|
IBError(ibxeEmptyQuery, [nil]); |
951 |
|
try |
952 |
|
CheckTransaction(FTransactionIntf); |
953 |
< |
with Firebird25ClientAPI do |
953 |
> |
with FFirebird25ClientAPI do |
954 |
|
begin |
955 |
|
Call(isc_dsql_alloc_statement2(StatusVector, @(FDBHandle), |
956 |
|
@FHandle), True); |
958 |
|
if FHasParamNames then |
959 |
|
begin |
960 |
|
if FProcessedSQL = '' then |
961 |
< |
FSQLParams.PreprocessSQL(FSQL,FGenerateParamNames,FProcessedSQL); |
961 |
> |
ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL); |
962 |
|
Call(isc_dsql_prepare(StatusVector, @(TRHandle), @FHandle, 0, |
963 |
|
PAnsiChar(FProcessedSQL), FSQLDialect, nil), True); |
964 |
|
end |
1002 |
|
if (FHandle <> nil) then |
1003 |
|
FreeHandle; |
1004 |
|
if E is EIBInterBaseError then |
1005 |
< |
raise EIBInterBaseError.Create(EIBInterBaseError(E).SQLCode, |
1006 |
< |
EIBInterBaseError(E).IBErrorCode, |
970 |
< |
EIBInterBaseError(E).Message + |
971 |
< |
sSQLErrorSeparator + FSQL) |
972 |
< |
else |
973 |
< |
raise; |
1005 |
> |
E.Message := E.Message + sSQLErrorSeparator + FSQL; |
1006 |
> |
raise; |
1007 |
|
end; |
1008 |
|
end; |
1009 |
|
FPrepared := true; |
1035 |
|
CheckHandle; |
1036 |
|
if aTransaction <> FTransactionIntf then |
1037 |
|
AddMonitor(aTransaction as TFB25Transaction); |
1038 |
< |
if (FSQLParams.FTransactionSeqNo < (FTransactionIntf as TFB25transaction).TransactionSeqNo) then |
1038 |
> |
if FStaleReferenceChecks and (FSQLParams.FTransactionSeqNo < (FTransactionIntf as TFB25transaction).TransactionSeqNo) then |
1039 |
|
IBError(ibxeInterfaceOutofDate,[nil]); |
1040 |
|
|
1041 |
|
try |
1042 |
|
TRHandle := (aTransaction as TFB25Transaction).Handle; |
1043 |
< |
with Firebird25ClientAPI do |
1043 |
> |
with FFirebird25ClientAPI do |
1044 |
|
begin |
1045 |
|
if FCollectStatistics then |
1046 |
|
GetPerfCounters(FBeforeStats); |
1098 |
|
CheckHandle; |
1099 |
|
if aTransaction <> FTransactionIntf then |
1100 |
|
AddMonitor(aTransaction as TFB25Transaction); |
1101 |
< |
if (FSQLParams.FTransactionSeqNo < (FTransactionIntf as TFB25transaction).TransactionSeqNo) then |
1101 |
> |
if FStaleReferenceChecks and (FSQLParams.FTransactionSeqNo < (FTransactionIntf as TFB25transaction).TransactionSeqNo) then |
1102 |
|
IBError(ibxeInterfaceOutofDate,[nil]); |
1103 |
|
|
1104 |
< |
with Firebird25ClientAPI do |
1104 |
> |
with FFirebird25ClientAPI do |
1105 |
|
begin |
1106 |
|
if FCollectStatistics then |
1107 |
|
GetPerfCounters(FBeforeStats); |
1140 |
|
Inc(FChangeSeqNo); |
1141 |
|
end; |
1142 |
|
|
1143 |
+ |
procedure TFB25Statement.ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; |
1144 |
+ |
var processedSQL: AnsiString); |
1145 |
+ |
begin |
1146 |
+ |
FSQLParams.PreprocessSQL(sql,GenerateParamNames, processedSQL); |
1147 |
+ |
end; |
1148 |
+ |
|
1149 |
|
procedure TFB25Statement.FreeHandle; |
1150 |
|
var |
1151 |
|
isc_res: ISC_STATUS; |
1154 |
|
ReleaseInterfaces; |
1155 |
|
try |
1156 |
|
if FHandle <> nil then |
1157 |
< |
with Firebird25ClientAPI do |
1157 |
> |
with FFirebird25ClientAPI do |
1158 |
|
begin |
1159 |
|
isc_res := |
1160 |
|
Call(isc_dsql_free_statement(StatusVector, @FHandle, DSQL_drop), False); |
1174 |
|
begin |
1175 |
|
if (FHandle <> nil) and (SQLStatementType = SQLSelect) and FOpen then |
1176 |
|
try |
1177 |
< |
with Firebird25ClientAPI do |
1177 |
> |
with FFirebird25ClientAPI do |
1178 |
|
begin |
1179 |
|
isc_res := Call( |
1180 |
|
isc_dsql_free_statement(StatusVector, @FHandle, DSQL_close), |
1199 |
|
begin |
1200 |
|
inherited Create(Attachment,Transaction,sql,aSQLDialect); |
1201 |
|
FDBHandle := Attachment.Handle; |
1202 |
+ |
FFirebird25ClientAPI := Attachment.Firebird25ClientAPI; |
1203 |
+ |
OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError; |
1204 |
|
FSQLParams := TIBXINPUTSQLDA.Create(self); |
1205 |
|
FSQLRecord := TIBXOUTPUTSQLDA.Create(self); |
1206 |
|
InternalPrepare; |
1207 |
|
end; |
1208 |
|
|
1209 |
< |
constructor TFB25Statement.CreateWithParameterNames(Attachment: TFB25Attachment; |
1210 |
< |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; |
1211 |
< |
GenerateParamNames: boolean); |
1209 |
> |
constructor TFB25Statement.CreateWithParameterNames( |
1210 |
> |
Attachment: TFB25Attachment; Transaction: ITransaction; sql: AnsiString; |
1211 |
> |
aSQLDialect: integer; GenerateParamNames: boolean; |
1212 |
> |
CaseSensitiveParams: boolean); |
1213 |
|
begin |
1214 |
|
inherited CreateWithParameterNames(Attachment,Transaction,sql,aSQLDialect,GenerateParamNames); |
1215 |
|
FDBHandle := Attachment.Handle; |
1216 |
+ |
FFirebird25ClientAPI := Attachment.Firebird25ClientAPI; |
1217 |
+ |
OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError; |
1218 |
|
FSQLParams := TIBXINPUTSQLDA.Create(self); |
1219 |
+ |
FSQLParams.CaseSensitiveParams := CaseSensitiveParams; |
1220 |
|
FSQLRecord := TIBXOUTPUTSQLDA.Create(self); |
1221 |
|
InternalPrepare; |
1222 |
|
end; |
1238 |
|
if FEOF then |
1239 |
|
IBError(ibxeEOF,[nil]); |
1240 |
|
|
1241 |
< |
with Firebird25ClientAPI do |
1241 |
> |
with FFirebird25ClientAPI do |
1242 |
|
begin |
1243 |
|
{ Go to the next record... } |
1244 |
|
fetch_res := |
1301 |
|
result := '' |
1302 |
|
else |
1303 |
|
begin |
1304 |
< |
RB := TSQLInfoResultsBuffer.Create(4*4096); |
1304 |
> |
RB := TSQLInfoResultsBuffer.Create(FFirebird25ClientAPI,4*4096); |
1305 |
|
GetDsqlInfo(isc_info_sql_get_plan,RB); |
1306 |
|
if RB.Count > 0 then |
1307 |
|
Result := RB[0].GetAsString; |