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 18 by tony, Sat Dec 28 19:22:24 2013 UTC vs.
Revision 19 by tony, Mon Jul 7 13:00:15 2014 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 +  if FProcName = '' then
239 +     IBError(ibxeNoStoredProcName,[nil]);
240    ActivateConnection;
241    Database.InternalTransaction.StartTransaction;
242 +  Params := TStringList.Create;
243    Query := TIBSQL.Create(self);
244    try
245      Query.Database := DataBase;
# Line 222 | Line 256 | begin
256        if (Query.Current.ByName('RDB$PARAMETER_TYPE').AsInteger = 0) then begin {do not localize}
257          if (input <> '') then
258            input := input + ', :' +
259 <            FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString) else {do not localize}
259 >            FormatParameter(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString) else {do not localize}
260            input := ':' +
261 <            FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString); {do not localize}
261 >            FormatParameter(Database.SQLDialect, Query.Current.ByName('RDB$PARAMETER_NAME').AsString); {do not localize}
262        end
263      end;
264      SelectSQL.Text := 'Execute Procedure ' + {do not localize}
265 <                FormatIdentifier(Database.SQLDialect, FProcName) + ' ' + input;
265 >                FormatParameter(Database.SQLDialect, FProcName) + ' ' + input;
266 > {   writeln(SelectSQL.Text);}
267    finally
268      Query.Free;
269 +    Params.Free;
270      Database.InternalTransaction.Commit;
271    end;
272   end;
# Line 435 | Line 471 | begin
471            SQLParams[i].AsShort := Params[j].AsSmallInt;
472          ftInteger:
473            SQLParams[i].AsLong := Params[j].AsInteger;
474 < {        ftLargeInt:
475 <          SQLParams[i].AsInt64 := Params[j].AsLargeInt; }
474 >        ftLargeInt:
475 >          SQLParams[i].AsInt64 := Params[j].AsLargeInt;
476          ftFloat, ftCurrency:
477           SQLParams[i].AsDouble := Params[j].AsFloat;
478          ftBCD:
# Line 520 | Line 556 | begin
556    Reader.ReadCollection(Params);
557   end;
558  
559 < end.
559 > end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines