ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBStoredProc.pas
(Generate patch)

Comparing ibx/trunk/runtime/IBStoredProc.pas (file contents):
Revision 17 by tony, Sat Dec 28 19:22:24 2013 UTC vs.
Revision 27 by tony, Tue Apr 14 13:10:23 2015 UTC

# Line 67 | Line 67 | type
67  
68      procedure DefineProperties(Filer: TFiler); override;
69      procedure SetFiltered(Value: Boolean); override;
70 +    procedure InitFieldDefs; override;
71      function GetParamsCount: Word;
72      procedure SetPrepared(Value: Boolean);
73      procedure SetPrepare(Value: Boolean);
# Line 199 | Line 200 | begin
200      inherited SetFiltered(value);
201   end;
202  
203 + procedure TIBStoredProc.InitFieldDefs;
204 + begin
205 +  if SelectSQL.Text = '' then
206 +     GenerateSQL;
207 +  inherited InitFieldDefs;
208 + end;
209 +
210   procedure TIBStoredProc.GenerateSQL;
211 +
212 + var Params: TStringList;
213 +
214 +  function FormatParameter(Dialect: Integer; Value: String): String;
215 +  var j: integer;
216 +  begin
217 +    Value := Trim(Value);
218 +    if Dialect = 1 then
219 +       Result := AnsiUpperCase(Value)
220 +    else
221 +    begin
222 +      j := 1;
223 +      Value := Space2Underscore(AnsiUpperCase(Value));
224 +      Result := Value;
225 +      while Params.IndexOf(Result) <> -1 do
226 +      begin
227 +        Result := Value + IntToStr(j);
228 +        Inc(j)
229 +      end;
230 +      Params.Add(Result)
231 +    end;
232 +  end;
233 +
234   var
235    Query : TIBSQL;
236    input : string;
237   begin
238 +  input := '';
239 +  if FProcName = '' then
240 +     IBError(ibxeNoStoredProcName,[nil]);
241    ActivateConnection;
242    Database.InternalTransaction.StartTransaction;
243 +  Params := TStringList.Create;
244    Query := TIBSQL.Create(self);
245    try
246      Query.Database := DataBase;
# Line 222 | Line 257 | begin
257        if (Query.Current.ByName('RDB$PARAMETER_TYPE').AsInteger = 0) then begin {do not localize}
258          if (input <> '') then
259            input := input + ', :' +
260 <            FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString) else {do not localize}
260 >            FormatParameter(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString) else {do not localize}
261            input := ':' +
262 <            FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString); {do not localize}
262 >            FormatParameter(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString); {do not localize}
263        end
264      end;
265      SelectSQL.Text := 'Execute Procedure ' + {do not localize}
266 <                FormatIdentifier(Database.SQLDialect, FProcName) + ' ' + input;
266 >                FormatParameter(Database.SQLDialect, FProcName) + ' ' + input;
267 > {   writeln(SelectSQL.Text);}
268    finally
269      Query.Free;
270 +    Params.Free;
271      Database.InternalTransaction.Commit;
272    end;
273   end;
# Line 266 | Line 303 | begin
303        else
304          DataType := ftFloat;
305      SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT: DataType := ftFloat;
306 +    SQL_BOOLEAN:
307 +      DataType := ftBoolean;
308      SQL_TEXT: DataType := ftString;
309      SQL_VARYING:
310        if ((QSelect.Fields[i].AsXSQLVar)^.sqllen < 1024) then
# Line 300 | Line 339 | begin
339          DataType := ftBCD
340        else DataType := ftFloat;
341      SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT: DataType := ftFloat;
342 +    SQL_BOOLEAN:
343 +      DataType := ftBoolean;
344      SQL_TEXT: DataType := ftString;
345      SQL_VARYING:
346        if ((QSelect.Params[i].AsXSQLVar)^.sqllen < 1024) then
# Line 378 | Line 419 | end;
419  
420   function TIBStoredProc.ParamByName(const Value: string): TParam;
421   begin
422 +  Prepare;
423    Result := FParams.ParamByName(Value);
424   end;
425  
# Line 423 | Line 465 | begin
465      if (Params[j].ParamType <> ptInput) then
466        continue;
467      if not Params[j].Bound then
468 <      IBError(ibxeRequiredParamNotSet, [nil]);
468 >      IBError(ibxeRequiredParamNotSet, [Params[j].Name]);
469      if Params[j].IsNull then
470        SQLParams[i].IsNull := True
471      else begin
# Line 431 | Line 473 | begin
473        case Params[j].DataType of
474          ftString:
475            SQLParams[i].AsString := Params[j].AsString;
476 <        ftBoolean, ftSmallint, ftWord:
476 >        ftSmallint, ftWord:
477            SQLParams[i].AsShort := Params[j].AsSmallInt;
478 +        ftBoolean:
479 +           SQLParams[i].AsBoolean := Params[j].AsBoolean;
480          ftInteger:
481            SQLParams[i].AsLong := Params[j].AsInteger;
482 < {        ftLargeInt:
483 <          SQLParams[i].AsInt64 := Params[j].AsLargeInt; }
482 >        ftLargeInt:
483 >          SQLParams[i].AsInt64 := Params[j].AsLargeInt;
484          ftFloat, ftCurrency:
485           SQLParams[i].AsDouble := Params[j].AsFloat;
486          ftBCD:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines