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 7 by tony, Sun Aug 5 18:28:19 2012 UTC vs.
Revision 39 by tony, Tue May 17 08:14:52 2016 UTC

# Line 35 | Line 35 | unit IBStoredProc;
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,
# Line 67 | Line 71 | type
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);
# Line 199 | Line 204 | begin
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;
# Line 222 | Line 261 | begin
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;
# Line 266 | Line 307 | begin
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
# Line 300 | Line 343 | begin
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
# Line 378 | Line 423 | end;
423  
424   function TIBStoredProc.ParamByName(const Value: string): TParam;
425   begin
426 +  Prepare;
427    Result := FParams.ParamByName(Value);
428   end;
429  
# Line 423 | Line 469 | begin
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
# Line 431 | Line 477 | 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:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines