35 |
|
|
36 |
|
{$Mode Delphi} |
37 |
|
|
38 |
+ |
{$IF FPC_FULLVERSION >= 20700 } |
39 |
+ |
{$codepage UTF8} |
40 |
+ |
{$ENDIF} |
41 |
+ |
|
42 |
|
interface |
43 |
|
|
44 |
|
uses SysUtils, Classes, DB, IB, IBDatabase, IBCustomDataSet, |
71 |
|
|
72 |
|
procedure DefineProperties(Filer: TFiler); override; |
73 |
|
procedure SetFiltered(Value: Boolean); override; |
74 |
+ |
procedure InitFieldDefs; override; |
75 |
|
function GetParamsCount: Word; |
76 |
|
procedure SetPrepared(Value: Boolean); |
77 |
|
procedure SetPrepare(Value: Boolean); |
204 |
|
inherited SetFiltered(value); |
205 |
|
end; |
206 |
|
|
207 |
+ |
procedure TIBStoredProc.InitFieldDefs; |
208 |
+ |
begin |
209 |
+ |
if SelectSQL.Text = '' then |
210 |
+ |
GenerateSQL; |
211 |
+ |
inherited InitFieldDefs; |
212 |
+ |
end; |
213 |
+ |
|
214 |
|
procedure TIBStoredProc.GenerateSQL; |
215 |
+ |
|
216 |
+ |
var Params: TStringList; |
217 |
+ |
|
218 |
+ |
function FormatParameter(Dialect: Integer; Value: String): String; |
219 |
+ |
var j: integer; |
220 |
+ |
begin |
221 |
+ |
Value := Trim(Value); |
222 |
+ |
if Dialect = 1 then |
223 |
+ |
Result := AnsiUpperCase(Value) |
224 |
+ |
else |
225 |
+ |
begin |
226 |
+ |
j := 1; |
227 |
+ |
Value := Space2Underscore(AnsiUpperCase(Value)); |
228 |
+ |
Result := Value; |
229 |
+ |
while Params.IndexOf(Result) <> -1 do |
230 |
+ |
begin |
231 |
+ |
Result := Value + IntToStr(j); |
232 |
+ |
Inc(j) |
233 |
+ |
end; |
234 |
+ |
Params.Add(Result) |
235 |
+ |
end; |
236 |
+ |
end; |
237 |
+ |
|
238 |
|
var |
239 |
|
Query : TIBSQL; |
240 |
|
input : string; |
241 |
|
begin |
242 |
+ |
input := ''; |
243 |
+ |
if FProcName = '' then |
244 |
+ |
IBError(ibxeNoStoredProcName,[nil]); |
245 |
|
ActivateConnection; |
246 |
|
Database.InternalTransaction.StartTransaction; |
247 |
+ |
Params := TStringList.Create; |
248 |
|
Query := TIBSQL.Create(self); |
249 |
|
try |
250 |
|
Query.Database := DataBase; |
261 |
|
if (Query.Current.ByName('RDB$PARAMETER_TYPE').AsInteger = 0) then begin {do not localize} |
262 |
|
if (input <> '') then |
263 |
|
input := input + ', :' + |
264 |
< |
FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString) else {do not localize} |
264 |
> |
FormatParameter(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString) else {do not localize} |
265 |
|
input := ':' + |
266 |
< |
FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString); {do not localize} |
266 |
> |
FormatParameter(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString); {do not localize} |
267 |
|
end |
268 |
|
end; |
269 |
|
SelectSQL.Text := 'Execute Procedure ' + {do not localize} |
270 |
< |
FormatIdentifier(Database.SQLDialect, FProcName) + ' ' + input; |
270 |
> |
FormatParameter(Database.SQLDialect, FProcName) + ' ' + input; |
271 |
> |
{ writeln(SelectSQL.Text);} |
272 |
|
finally |
273 |
|
Query.Free; |
274 |
+ |
Params.Free; |
275 |
|
Database.InternalTransaction.Commit; |
276 |
|
end; |
277 |
|
end; |
307 |
|
else |
308 |
|
DataType := ftFloat; |
309 |
|
SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT: DataType := ftFloat; |
310 |
+ |
SQL_BOOLEAN: |
311 |
+ |
DataType := ftBoolean; |
312 |
|
SQL_TEXT: DataType := ftString; |
313 |
|
SQL_VARYING: |
314 |
|
if ((QSelect.Fields[i].AsXSQLVar)^.sqllen < 1024) then |
343 |
|
DataType := ftBCD |
344 |
|
else DataType := ftFloat; |
345 |
|
SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT: DataType := ftFloat; |
346 |
+ |
SQL_BOOLEAN: |
347 |
+ |
DataType := ftBoolean; |
348 |
|
SQL_TEXT: DataType := ftString; |
349 |
|
SQL_VARYING: |
350 |
|
if ((QSelect.Params[i].AsXSQLVar)^.sqllen < 1024) then |
423 |
|
|
424 |
|
function TIBStoredProc.ParamByName(const Value: string): TParam; |
425 |
|
begin |
426 |
+ |
Prepare; |
427 |
|
Result := FParams.ParamByName(Value); |
428 |
|
end; |
429 |
|
|
469 |
|
if (Params[j].ParamType <> ptInput) then |
470 |
|
continue; |
471 |
|
if not Params[j].Bound then |
472 |
< |
IBError(ibxeRequiredParamNotSet, [nil]); |
472 |
> |
IBError(ibxeRequiredParamNotSet, [Params[j].Name]); |
473 |
|
if Params[j].IsNull then |
474 |
|
SQLParams[i].IsNull := True |
475 |
|
else begin |
477 |
|
case Params[j].DataType of |
478 |
|
ftString: |
479 |
|
SQLParams[i].AsString := Params[j].AsString; |
480 |
< |
ftBoolean, ftSmallint, ftWord: |
480 |
> |
ftSmallint, ftWord: |
481 |
|
SQLParams[i].AsShort := Params[j].AsSmallInt; |
482 |
+ |
ftBoolean: |
483 |
+ |
SQLParams[i].AsBoolean := Params[j].AsBoolean; |
484 |
|
ftInteger: |
485 |
|
SQLParams[i].AsLong := Params[j].AsInteger; |
486 |
< |
{ ftLargeInt: |
487 |
< |
SQLParams[i].AsInt64 := Params[j].AsLargeInt; } |
486 |
> |
ftLargeInt: |
487 |
> |
SQLParams[i].AsInt64 := Params[j].AsLargeInt; |
488 |
|
ftFloat, ftCurrency: |
489 |
|
SQLParams[i].AsDouble := Params[j].AsFloat; |
490 |
|
ftBCD: |