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 1 by tony, Mon Jul 31 16:43:00 2000 UTC vs.
Revision 33 by tony, Sat Jul 18 12:30:52 2015 UTC

# Line 24 | Line 24
24   {       Corporation. All Rights Reserved.                                }
25   {    Contributor(s): Jeff Overcash                                       }
26   {                                                                        }
27 + {    IBX For Lazarus (Firebird Express)                                  }
28 + {    Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
29 + {    Portions created by MWA Software are copyright McCallum Whyman      }
30 + {    Associates Ltd 2011                                                 }
31 + {                                                                        }
32   {************************************************************************}
33  
34   unit IBStoredProc;
35  
36 < interface
36 > {$Mode Delphi}
37  
38 < uses Windows, SysUtils, Graphics, Classes, Controls, Db, StdVCL, IB,
34 <  IBDatabase, IBCustomDataSet, IBHeader, IBSQL, IBUtils;
38 > interface
39  
40 + uses SysUtils, Classes, DB, IB, IBDatabase, IBCustomDataSet,
41 +     IBHeader, IBSQL, IBUtils;
42 +    
43   { TIBStoredProc }
44   type
45  
# Line 57 | Line 64 | type
64      procedure WriteParamData(Writer: TWriter);
65  
66    protected
60    { IProviderSupport }
61    procedure PSExecute; override;
62    function PSGetTableName: string; override;
63    function PSGetParams: TParams; override;
64    procedure PSSetCommandText(const CommandText: string); override;
65    procedure PSSetParams(AParams: TParams); override;
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 198 | 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 221 | 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 265 | 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 299 | 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 377 | 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 422 | 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 430 | 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:
# Line 519 | Line 564 | begin
564    Reader.ReadCollection(Params);
565   end;
566  
522 { TIBStoredProc IProviderSupport }
523
524 function TIBStoredProc.PSGetParams: TParams;
525 begin
526  Result := Params;
527 end;
528
529 procedure TIBStoredProc.PSSetParams(AParams: TParams);
530 begin
531  if AParams.Count > 0 then
532    Params.Assign(AParams);
533  Close;
534 end;
535
536 function TIBStoredProc.PSGetTableName: string;
537 begin
538  { ! }
539 end;
540
541 procedure TIBStoredProc.PSExecute;
542 begin
543  ExecProc;
544 end;
545
546 procedure TIBStoredProc.PSSetCommandText(const CommandText: string);
547 begin
548  if CommandText <> '' then
549    StoredProcName := CommandText;
550 end;
551
567   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines