25 |
|
* |
26 |
|
*) |
27 |
|
unit FB30Statement; |
28 |
+ |
{$IFDEF MSWINDOWS} |
29 |
+ |
{$DEFINE WINDOWS} |
30 |
+ |
{$ENDIF} |
31 |
|
|
32 |
|
{$IFDEF FPC} |
33 |
< |
{$mode objfpc}{$H+} |
33 |
> |
{$mode delphi} |
34 |
|
{$codepage UTF8} |
35 |
|
{$interfaces COM} |
36 |
|
{$ENDIF} |
97 |
|
{SQL Var Type Data} |
98 |
|
FSQLType: cardinal; |
99 |
|
FSQLSubType: integer; |
100 |
< |
FSQLData: PChar; {Address of SQL Data in Message Buffer} |
100 |
> |
FSQLData: PByte; {Address of SQL Data in Message Buffer} |
101 |
|
FSQLNullIndicator: PShort; {Address of null indicator} |
102 |
|
FDataLength: integer; |
103 |
|
FNullable: boolean; |
104 |
|
FScale: integer; |
105 |
|
FCharSetID: cardinal; |
106 |
< |
FRelationName: string; |
107 |
< |
FFieldName: string; |
106 |
> |
FRelationName: AnsiString; |
107 |
> |
FFieldName: AnsiString; |
108 |
|
|
109 |
|
protected |
110 |
|
function GetSQLType: cardinal; override; |
111 |
|
function GetSubtype: integer; override; |
112 |
< |
function GetAliasName: string; override; |
113 |
< |
function GetFieldName: string; override; |
114 |
< |
function GetOwnerName: string; override; |
115 |
< |
function GetRelationName: string; override; |
112 |
> |
function GetAliasName: AnsiString; override; |
113 |
> |
function GetFieldName: AnsiString; override; |
114 |
> |
function GetOwnerName: AnsiString; override; |
115 |
> |
function GetRelationName: AnsiString; override; |
116 |
|
function GetScale: integer; override; |
117 |
|
function GetCharSetID: cardinal; override; |
118 |
|
function GetCodePage: TSystemCodePage; override; |
119 |
|
function GetIsNull: Boolean; override; |
120 |
|
function GetIsNullable: boolean; override; |
121 |
< |
function GetSQLData: PChar; override; |
121 |
> |
function GetSQLData: PByte; override; |
122 |
|
function GetDataLength: cardinal; override; |
123 |
|
procedure SetIsNull(Value: Boolean); override; |
124 |
|
procedure SetIsNullable(Value: Boolean); override; |
125 |
< |
procedure SetSQLData(AValue: PChar; len: cardinal); override; |
125 |
> |
procedure SetSQLData(AValue: PByte; len: cardinal); override; |
126 |
|
procedure SetScale(aValue: integer); override; |
127 |
|
procedure SetDataLength(len: cardinal); override; |
128 |
|
procedure SetSQLType(aValue: cardinal); override; |
173 |
|
|
174 |
|
TIBXINPUTSQLDA = class(TIBXSQLDA) |
175 |
|
private |
176 |
< |
FMessageBuffer: PChar; {Message Buffer} |
176 |
> |
FMessageBuffer: PByte; {Message Buffer} |
177 |
|
FMsgLength: integer; {Message Buffer length} |
178 |
|
FCurMetaData: Firebird.IMessageMetadata; |
179 |
|
procedure FreeMessageBuffer; |
180 |
< |
function GetMessageBuffer: PChar; |
180 |
> |
function GetMessageBuffer: PByte; |
181 |
|
function GetMetaData: Firebird.IMessageMetadata; |
182 |
|
function GetModified: Boolean; |
183 |
|
function GetMsgLength: integer; |
191 |
|
procedure Changed; override; |
192 |
|
function IsInputDataArea: boolean; override; |
193 |
|
property MetaData: Firebird.IMessageMetadata read GetMetaData; |
194 |
< |
property MessageBuffer: PChar read GetMessageBuffer; |
194 |
> |
property MessageBuffer: PByte read GetMessageBuffer; |
195 |
|
property MsgLength: integer read GetMsgLength; |
196 |
|
end; |
197 |
|
|
200 |
|
TIBXOUTPUTSQLDA = class(TIBXSQLDA) |
201 |
|
private |
202 |
|
FTransaction: TFB30Transaction; {transaction used to execute the statement} |
203 |
< |
FMessageBuffer: PChar; {Message Buffer} |
203 |
> |
FMessageBuffer: PByte; {Message Buffer} |
204 |
|
FMsgLength: integer; {Message Buffer length} |
205 |
|
protected |
206 |
|
procedure FreeXSQLDA; override; |
207 |
|
public |
208 |
|
procedure Bind(aMetaData: Firebird.IMessageMetadata); |
209 |
|
procedure GetData(index: integer; var aIsNull: boolean; var len: short; |
210 |
< |
var data: PChar); override; |
210 |
> |
var data: PByte); override; |
211 |
|
function IsInputDataArea: boolean; override; |
212 |
< |
property MessageBuffer: PChar read FMessageBuffer; |
212 |
> |
property MessageBuffer: PByte read FMessageBuffer; |
213 |
|
property MsgLength: integer read FMsgLength; |
214 |
|
end; |
215 |
|
|
224 |
|
destructor Destroy; override; |
225 |
|
{IResultSet} |
226 |
|
function FetchNext: boolean; |
227 |
< |
function GetCursorName: string; |
227 |
> |
function GetCursorName: AnsiString; |
228 |
|
function GetTransaction: ITransaction; override; |
229 |
|
function IsEof: boolean; |
230 |
|
procedure Close; |
249 |
|
procedure InternalClose(Force: boolean); override; |
250 |
|
public |
251 |
|
constructor Create(Attachment: TFB30Attachment; Transaction: ITransaction; |
252 |
< |
sql: string; aSQLDialect: integer); |
252 |
> |
sql: AnsiString; aSQLDialect: integer); |
253 |
|
constructor CreateWithParameterNames(Attachment: TFB30Attachment; Transaction: ITransaction; |
254 |
< |
sql: string; aSQLDialect: integer; GenerateParamNames: boolean =false); |
254 |
> |
sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean =false); |
255 |
|
destructor Destroy; override; |
256 |
|
function FetchNext: boolean; |
257 |
|
property StatementIntf: Firebird.IStatement read FStatementIntf; |
260 |
|
{IStatement} |
261 |
|
function GetSQLParams: ISQLParams; override; |
262 |
|
function GetMetaData: IMetaData; override; |
263 |
< |
function GetPlan: String; |
263 |
> |
function GetPlan: AnsiString; |
264 |
|
function IsPrepared: boolean; |
265 |
|
function CreateBlob(column: TColumnMetaData): IBlob; override; |
266 |
|
function CreateArray(column: TColumnMetaData): IArray; override; |
270 |
|
|
271 |
|
implementation |
272 |
|
|
273 |
< |
uses IBUtils, FBMessages, FB30Blob, variants, FBArray, FB30Array; |
273 |
> |
uses IBUtils, FBMessages, FBBLob, FB30Blob, variants, FBArray, FB30Array; |
274 |
> |
|
275 |
> |
const |
276 |
> |
ISQL_COUNTERS = 'CurrentMemory, MaxMemory, RealTime, UserTime, Buffers, Reads, Writes, Fetches'; |
277 |
|
|
278 |
|
{ TIBXSQLVAR } |
279 |
|
|
293 |
|
Result := FSQLSubType; |
294 |
|
end; |
295 |
|
|
296 |
< |
function TIBXSQLVAR.GetAliasName: string; |
296 |
> |
function TIBXSQLVAR.GetAliasName: AnsiString; |
297 |
|
begin |
298 |
|
with Firebird30ClientAPI do |
299 |
|
begin |
302 |
|
end; |
303 |
|
end; |
304 |
|
|
305 |
< |
function TIBXSQLVAR.GetFieldName: string; |
305 |
> |
function TIBXSQLVAR.GetFieldName: AnsiString; |
306 |
|
begin |
307 |
|
Result := FFieldName; |
308 |
|
end; |
309 |
|
|
310 |
< |
function TIBXSQLVAR.GetOwnerName: string; |
310 |
> |
function TIBXSQLVAR.GetOwnerName: AnsiString; |
311 |
|
begin |
312 |
|
with Firebird30ClientAPI do |
313 |
|
begin |
316 |
|
end; |
317 |
|
end; |
318 |
|
|
319 |
< |
function TIBXSQLVAR.GetRelationName: string; |
319 |
> |
function TIBXSQLVAR.GetRelationName: AnsiString; |
320 |
|
begin |
321 |
|
Result := FRelationName; |
322 |
|
end; |
362 |
|
Result := FSQLNullIndicator <> nil; |
363 |
|
end; |
364 |
|
|
365 |
< |
function TIBXSQLVAR.GetSQLData: PChar; |
365 |
> |
function TIBXSQLVAR.GetSQLData: PByte; |
366 |
|
begin |
367 |
|
Result := FSQLData; |
368 |
|
end; |
394 |
|
FStatement.GetTransaction as TFB30Transaction, |
395 |
|
GetRelationName,GetFieldName, |
396 |
|
GetSubType); |
397 |
+ |
(FBlobMetaData as TFBBlobMetaData).SetCharSetID(GetCharSetID); |
398 |
|
Result := FBlobMetaData; |
399 |
|
end; |
400 |
|
|
408 |
|
else |
409 |
|
if IsNullable then |
410 |
|
FNullIndicator := 0; |
411 |
+ |
Changed; |
412 |
|
end; |
413 |
|
|
414 |
|
procedure TIBXSQLVAR.SetIsNullable(Value: Boolean); |
423 |
|
FSQLNullIndicator := nil; |
424 |
|
end; |
425 |
|
|
426 |
< |
procedure TIBXSQLVAR.SetSQLData(AValue: PChar; len: cardinal); |
426 |
> |
procedure TIBXSQLVAR.SetSQLData(AValue: PByte; len: cardinal); |
427 |
|
begin |
428 |
|
if FOwnsSQLData then |
429 |
|
FreeMem(FSQLData); |
546 |
|
FResults.Column[i].RowChange; |
547 |
|
end; |
548 |
|
|
549 |
< |
function TResultSet.GetCursorName: string; |
549 |
> |
function TResultSet.GetCursorName: AnsiString; |
550 |
|
begin |
551 |
|
IBError(ibxeNotSupported,[nil]); |
552 |
|
Result := ''; |
598 |
|
FMsgLength := 0; |
599 |
|
end; |
600 |
|
|
601 |
< |
function TIBXINPUTSQLDA.GetMessageBuffer: PChar; |
601 |
> |
function TIBXINPUTSQLDA.GetMessageBuffer: PByte; |
602 |
|
begin |
603 |
|
PackBuffer; |
604 |
|
Result := FMessageBuffer; |
655 |
|
for i := 0 to Count - 1 do |
656 |
|
with TIBXSQLVar(Column[i]) do |
657 |
|
begin |
658 |
< |
Move(FSQLData^,(FMessageBuffer + FCurMetaData.getOffset(StatusIntf,i))^,FDataLength); |
658 |
> |
if IsNull then |
659 |
> |
FillChar((FMessageBuffer + FCurMetaData.getOffset(StatusIntf,i))^,FDataLength,0) |
660 |
> |
else |
661 |
> |
Move(FSQLData^,(FMessageBuffer + FCurMetaData.getOffset(StatusIntf,i))^,FDataLength); |
662 |
|
Check4DataBaseError; |
663 |
|
if IsNullable then |
664 |
|
begin |
723 |
|
else |
724 |
|
IBAlloc(FSQLData, 0, FDataLength) |
725 |
|
end; |
726 |
< |
SQL_VARYING: begin |
726 |
> |
SQL_VARYING: |
727 |
|
IBAlloc(FSQLData, 0, FDataLength + 2); |
717 |
– |
end; |
728 |
|
else |
729 |
|
IBError(ibxeUnknownSQLDataType, [sqltype and (not 1)]) |
730 |
|
end; |
820 |
|
end; |
821 |
|
|
822 |
|
procedure TIBXOUTPUTSQLDA.GetData(index: integer; var aIsNull: boolean; |
823 |
< |
var len: short; var data: PChar); |
823 |
> |
var len: short; var data: PByte); |
824 |
|
begin |
825 |
|
with TIBXSQLVAR(Column[index]) do |
826 |
|
begin |
987 |
|
FStatementIntf := (GetAttachment as TFB30Attachment).AttachmentIntf.prepare(StatusIntf, |
988 |
|
(FTransactionIntf as TFB30Transaction).TransactionIntf, |
989 |
|
Length(FProcessedSQL), |
990 |
< |
PChar(FProcessedSQL), |
990 |
> |
PAnsiChar(FProcessedSQL), |
991 |
|
FSQLDialect, |
992 |
|
Firebird.IStatement.PREPARE_PREFETCH_METADATA); |
993 |
|
end |
995 |
|
FStatementIntf := (GetAttachment as TFB30Attachment).AttachmentIntf.prepare(StatusIntf, |
996 |
|
(FTransactionIntf as TFB30Transaction).TransactionIntf, |
997 |
|
Length(FSQL), |
998 |
< |
PChar(FSQL), |
998 |
> |
PAnsiChar(FSQL), |
999 |
|
FSQLDialect, |
1000 |
|
Firebird.IStatement.PREPARE_PREFETCH_METADATA); |
1001 |
|
Check4DataBaseError; |
1076 |
|
|
1077 |
|
try |
1078 |
|
with Firebird30ClientAPI do |
1069 |
– |
case FSQLStatementType of |
1070 |
– |
SQLSelect: |
1071 |
– |
IBError(ibxeIsAExecuteProcedure,[]); |
1072 |
– |
|
1073 |
– |
SQLExecProcedure: |
1079 |
|
begin |
1080 |
< |
FStatementIntf.execute(StatusIntf, |
1081 |
< |
(aTransaction as TFB30Transaction).TransactionIntf, |
1082 |
< |
FSQLParams.MetaData, |
1083 |
< |
FSQLParams.MessageBuffer, |
1084 |
< |
FSQLRecord.MetaData, |
1085 |
< |
FSQLRecord.MessageBuffer); |
1086 |
< |
Check4DataBaseError; |
1080 |
> |
if FCollectStatistics then |
1081 |
> |
begin |
1082 |
> |
UtilIntf.getPerfCounters(StatusIntf, |
1083 |
> |
(GetAttachment as TFB30Attachment).AttachmentIntf, |
1084 |
> |
ISQL_COUNTERS,@FBeforeStats); |
1085 |
> |
Check4DataBaseError; |
1086 |
> |
end; |
1087 |
|
|
1088 |
< |
Result := TResults.Create(FSQLRecord); |
1089 |
< |
FSingleResults := true; |
1090 |
< |
end |
1091 |
< |
else |
1092 |
< |
FStatementIntf.execute(StatusIntf, |
1093 |
< |
(aTransaction as TFB30Transaction).TransactionIntf, |
1094 |
< |
FSQLParams.MetaData, |
1095 |
< |
FSQLParams.MessageBuffer, |
1096 |
< |
nil, |
1097 |
< |
nil); |
1098 |
< |
Check4DataBaseError; |
1088 |
> |
case FSQLStatementType of |
1089 |
> |
SQLSelect: |
1090 |
> |
IBError(ibxeIsAExecuteProcedure,[]); |
1091 |
> |
|
1092 |
> |
SQLExecProcedure: |
1093 |
> |
begin |
1094 |
> |
FStatementIntf.execute(StatusIntf, |
1095 |
> |
(aTransaction as TFB30Transaction).TransactionIntf, |
1096 |
> |
FSQLParams.MetaData, |
1097 |
> |
FSQLParams.MessageBuffer, |
1098 |
> |
FSQLRecord.MetaData, |
1099 |
> |
FSQLRecord.MessageBuffer); |
1100 |
> |
Check4DataBaseError; |
1101 |
> |
|
1102 |
> |
Result := TResults.Create(FSQLRecord); |
1103 |
> |
FSingleResults := true; |
1104 |
> |
end |
1105 |
> |
else |
1106 |
> |
FStatementIntf.execute(StatusIntf, |
1107 |
> |
(aTransaction as TFB30Transaction).TransactionIntf, |
1108 |
> |
FSQLParams.MetaData, |
1109 |
> |
FSQLParams.MessageBuffer, |
1110 |
> |
nil, |
1111 |
> |
nil); |
1112 |
> |
Check4DataBaseError; |
1113 |
> |
end; |
1114 |
> |
if FCollectStatistics then |
1115 |
> |
begin |
1116 |
> |
UtilIntf.getPerfCounters(StatusIntf, |
1117 |
> |
(GetAttachment as TFB30Attachment).AttachmentIntf, |
1118 |
> |
ISQL_COUNTERS, @FAfterStats); |
1119 |
> |
Check4DataBaseError; |
1120 |
> |
FStatisticsAvailable := true; |
1121 |
> |
end; |
1122 |
|
end; |
1123 |
|
finally |
1124 |
|
if aTransaction <> FTransactionIntf then |
1146 |
|
|
1147 |
|
with Firebird30ClientAPI do |
1148 |
|
begin |
1149 |
+ |
if FCollectStatistics then |
1150 |
+ |
begin |
1151 |
+ |
UtilIntf.getPerfCounters(StatusIntf, |
1152 |
+ |
(GetAttachment as TFB30Attachment).AttachmentIntf, |
1153 |
+ |
ISQL_COUNTERS, @FBeforeStats); |
1154 |
+ |
Check4DataBaseError; |
1155 |
+ |
end; |
1156 |
+ |
|
1157 |
|
FResultSet := FStatementIntf.openCursor(StatusIntf, |
1158 |
|
(aTransaction as TFB30Transaction).TransactionIntf, |
1159 |
|
FSQLParams.MetaData, |
1161 |
|
FSQLRecord.MetaData, |
1162 |
|
0); |
1163 |
|
Check4DataBaseError; |
1164 |
+ |
|
1165 |
+ |
if FCollectStatistics then |
1166 |
+ |
begin |
1167 |
+ |
UtilIntf.getPerfCounters(StatusIntf, |
1168 |
+ |
(GetAttachment as TFB30Attachment).AttachmentIntf, |
1169 |
+ |
ISQL_COUNTERS,@FAfterStats); |
1170 |
+ |
Check4DataBaseError; |
1171 |
+ |
FStatisticsAvailable := true; |
1172 |
+ |
end; |
1173 |
|
end; |
1174 |
|
Inc(FCursorSeqNo); |
1175 |
|
FSingleResults := false; |
1214 |
|
if not Force then Check4DataBaseError; |
1215 |
|
end; |
1216 |
|
finally |
1217 |
< |
if (FSQLRecord.FTransaction <> nil) and (FSQLRecord.FTransaction <> FTransactionIntf) then |
1217 |
> |
if (FSQLRecord.FTransaction <> nil) and (FSQLRecord.FTransaction <> (FTransactionIntf as TFB30Transaction)) then |
1218 |
|
RemoveMonitor(FSQLRecord.FTransaction); |
1219 |
|
FOpen := False; |
1220 |
|
FExecTransactionIntf := nil; |
1225 |
|
end; |
1226 |
|
|
1227 |
|
constructor TFB30Statement.Create(Attachment: TFB30Attachment; |
1228 |
< |
Transaction: ITransaction; sql: string; aSQLDialect: integer); |
1228 |
> |
Transaction: ITransaction; sql: AnsiString; aSQLDialect: integer); |
1229 |
|
begin |
1230 |
|
inherited Create(Attachment,Transaction,sql,aSQLDialect); |
1231 |
|
FSQLParams := TIBXINPUTSQLDA.Create(self); |
1234 |
|
end; |
1235 |
|
|
1236 |
|
constructor TFB30Statement.CreateWithParameterNames( |
1237 |
< |
Attachment: TFB30Attachment; Transaction: ITransaction; sql: string; |
1237 |
> |
Attachment: TFB30Attachment; Transaction: ITransaction; sql: AnsiString; |
1238 |
|
aSQLDialect: integer; GenerateParamNames: boolean); |
1239 |
|
begin |
1240 |
|
inherited CreateWithParameterNames(Attachment,Transaction,sql,aSQLDialect,GenerateParamNames); |
1307 |
|
Result := TMetaData(GetInterface(1)); |
1308 |
|
end; |
1309 |
|
|
1310 |
< |
function TFB30Statement.GetPlan: String; |
1310 |
> |
function TFB30Statement.GetPlan: AnsiString; |
1311 |
|
begin |
1312 |
|
CheckHandle; |
1313 |
|
if (not (FSQLStatementType in [SQLSelect, SQLSelectForUpdate, |