--- ibx/trunk/runtime/IBQuery.pas 2014/07/07 13:00:15 19 +++ ibx/trunk/runtime/IBQuery.pas 2015/02/26 10:33:34 21 @@ -44,13 +44,13 @@ uses unix, {$ENDIF} SysUtils, Graphics, Classes, Controls, Db, - IBHeader, IB, IBCustomDataSet, IBSQL; + IBHeader, IB, IBCustomDataSet, IBSQL, IBSQLParser; type { TIBQuery } - TIBQuery = class(TIBCustomDataSet) + TIBQuery = class(TIBParserDataSet) private FSQL: TStrings; FPrepared: Boolean; @@ -58,6 +58,7 @@ type FText: string; FRowsAffected: Integer; FCheckRowsAffected: Boolean; + FSQLUpdating: boolean; function GetRowsAffected: Integer; procedure PrepareSQL(Value: PChar); procedure QueryChanged(Sender: TObject); @@ -79,6 +80,7 @@ type procedure PSSetCommandText(const CommandText: string); override; procedure PSSetParams(AParams: TParams); override; *) + function CreateParser: TSelectSQLParser; override; procedure DefineProperties(Filer: TFiler); override; procedure InitFieldDefs; override; procedure InternalOpen; override; @@ -104,6 +106,7 @@ type property Text: string read FText; property RowsAffected: Integer read GetRowsAffected; // property Params: TParams read FParams write SetParamsList; + property BaseSQLSelect; published property Active; @@ -214,6 +217,15 @@ begin if not (csReading in ComponentState) then begin Disconnect; + if HasParser and not FSQLUpdating then + begin + FSQLUpdating := true; + try + SQL.Text := Parser.SQLText; + finally + FSQLUpdating := false + end; + end; if ParamCheck or (csDesigning in ComponentState) then begin List := TParams.Create(Self); @@ -259,6 +271,7 @@ begin Filer.DefineProperty('ParamData', ReadParamData, WriteParamData, WriteData); {do not localize} end; + procedure TIBQuery.ReadParamData(Reader: TReader); begin FParams.Clear; @@ -379,45 +392,47 @@ procedure TIBQuery.SetParams; var i : integer; Buffer: Pointer; +SQLParam: TIBXSQLVAR; begin for I := 0 to FParams.Count - 1 do begin + SQLParam := SQLParams.ByName(Params[i].Name); if Params[i].IsNull then - SQLParams[i].IsNull := True + SQLParam.IsNull := True else begin - SQLParams[i].IsNull := False; + SQLParam.IsNull := False; case Params[i].DataType of ftBytes: begin GetMem(Buffer,Params[i].GetDataSize); try Params[i].GetData(Buffer); - SQLParams[i].AsPointer := Buffer; + SQLParam.AsPointer := Buffer; finally FreeMem(Buffer); end; end; ftString: - SQLParams[i].AsString := Params[i].AsString; + SQLParam.AsString := Params[i].AsString; ftBoolean, ftSmallint, ftWord: - SQLParams[i].AsShort := Params[i].AsSmallInt; + SQLParam.AsShort := Params[i].AsSmallInt; ftInteger: - SQLParams[i].AsLong := Params[i].AsInteger; + SQLParam.AsLong := Params[i].AsInteger; ftLargeInt: - SQLParams[i].AsInt64 := Params[i].AsLargeInt; + SQLParam.AsInt64 := Params[i].AsLargeInt; ftFloat: - SQLParams[i].AsDouble := Params[i].AsFloat; + SQLParam.AsDouble := Params[i].AsFloat; ftBCD, ftCurrency: - SQLParams[i].AsCurrency := Params[i].AsCurrency; + SQLParam.AsCurrency := Params[i].AsCurrency; ftDate: - SQLParams[i].AsDate := Params[i].AsDateTime; + SQLParam.AsDate := Params[i].AsDateTime; ftTime: - SQLParams[i].AsTime := Params[i].AsDateTime; + SQLParam.AsTime := Params[i].AsDateTime; ftDateTime: - SQLParams[i].AsDateTime := Params[i].AsDateTime; + SQLParam.AsDateTime := Params[i].AsDateTime; ftBlob, ftMemo: - SQLParams[i].AsString := Params[i].AsString; + SQLParam.AsString := Params[i].AsString; else IBError(ibxeNotSupported, [nil]); end; @@ -469,6 +484,12 @@ begin Result := SelectStmtHandle; end; +function TIBQuery.CreateParser: TSelectSQLParser; +begin + Result := inherited CreateParser; + Result.OnSQLChanging := QueryChanged; +end; + function TIBQuery.GenerateQueryForLiveUpdate : Boolean; begin Result := False;