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

Comparing ibx/trunk/runtime/IBCustomDataSet.pas (file contents):
Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
Revision 80 by tony, Mon Jan 1 11:31:07 2018 UTC

# Line 74 | Line 74 | type
74      procedure SetDataSet(ADataSet: TIBCustomDataSet); virtual; abstract;
75      procedure Apply(UpdateKind: TUpdateKind; buff: PChar); virtual; abstract;
76      function GetSQL(UpdateKind: TUpdateKind): TStrings; virtual; abstract;
77 <    procedure InternalSetParams(Query: TIBSQL; buff: PChar);
77 >    procedure InternalSetParams(Params: ISQLParams; buff: PChar); overload;
78 >    procedure InternalSetParams(Query: TIBSQL; buff: PChar); overload;
79      property DataSet: TIBCustomDataSet read GetDataSet write SetDataSet;
80    public
81      constructor Create(AOwner: TComponent); override;
# Line 181 | Line 182 | type
182      FCharacterSetSize: integer;
183      FAutoFieldSize: boolean;
184      FCodePage: TSystemCodePage;
185 +    FDataSize: integer;
186    protected
187      procedure Bind(Binding: Boolean); override;
188      function GetDataSize: Integer; override;
# Line 434 | Line 436 | type
436      procedure SetDatabase(Value: TIBDatabase);
437      procedure SetDeleteSQL(Value: TStrings);
438      procedure SetInsertSQL(Value: TStrings);
439 <    procedure SetInternalSQLParams(Qry: TIBSQL; Buffer: Pointer);
439 >    procedure SetInternalSQLParams(Params: ISQLParams; Buffer: Pointer);
440      procedure SetRefreshSQL(Value: TStrings);
441      procedure SetSelectSQL(Value: TStrings);
442      procedure SetModifySQL(Value: TStrings);
# Line 790 | Line 792 | type
792      FCharacterSetSize: integer;
793      FCodePage: TSystemCodePage;
794      FRelationName: string;
795 +    FDataSize: integer;
796    published
797      property CharacterSetName: RawByteString read FCharacterSetName write FCharacterSetName;
798      property CharacterSetSize: integer read FCharacterSetSize write FCharacterSetSize;
799      property CodePage: TSystemCodePage read FCodePage write FCodePage;
800 +    property DataSize: integer read FDataSize write FDataSize;
801      property RelationName: string read FRelationName write FRelationName;
802      property ArrayDimensions: integer read FArrayDimensions write FArrayDimensions;
803      property ArrayBounds: TArrayBounds read FArrayBounds write FArrayBounds;
# Line 1089 | Line 1093 | procedure TIBMemoField.SetAsString(const
1093   var s: RawByteString;
1094   begin
1095    s := AValue;
1096 <  if StringCodePage(Value) <> CodePage then
1096 >  if StringCodePage(s) <> CodePage then
1097      SetCodePage(s,CodePage,CodePage<>CP_NONE);
1098    inherited SetAsString(s);
1099   end;
# Line 1141 | Line 1145 | begin
1145      IBFieldDef := FieldDef as TIBFieldDef;
1146      CharacterSetSize := IBFieldDef.CharacterSetSize;
1147      CharacterSetName := IBFieldDef.CharacterSetName;
1148 +    FDataSize := IBFieldDef.DataSize + 1;
1149      if AutoFieldSize then
1150        Size := IBFieldDef.Size;
1151      CodePage := IBFieldDef.CodePage;
# Line 1149 | Line 1154 | end;
1154  
1155   function TIBStringField.GetDataSize: Integer;
1156   begin
1157 <  Result := Size * CharacterSetSize + 1;
1157 >  Result := FDataSize;
1158   end;
1159  
1160   constructor TIBStringField.Create(aOwner: TComponent);
# Line 1208 | Line 1213 | var
1213    s: RawByteString;
1214   begin
1215    Buffer := nil;
1216 <  IBAlloc(Buffer, 0, Size + 1);
1216 >  IBAlloc(Buffer, 0, DataSize);
1217    try
1218      s := Value;
1219      if StringCodePage(s) <> CodePage then
1220        SetCodePage(s,CodePage,CodePage<>CP_NONE);
1221 <    StrLCopy(Buffer, PChar(s), Size);
1221 >    StrLCopy(Buffer, PChar(s), DataSize-1);
1222      if Transliterate then
1223        DataSet.Translate(Buffer, Buffer, True);
1224      SetData(Buffer);
# Line 1849 | Line 1854 | begin
1854      FQModify.FreeHandle;
1855    if FQRefresh <> nil then
1856      FQRefresh.FreeHandle;
1857 +  InternalUnPrepare;
1858    if Assigned(FBeforeTransactionEnd) then
1859      FBeforeTransactionEnd(Sender);
1860   end;
# Line 1962 | Line 1968 | var
1968    pbd: PBlobDataArray;
1969    pda: PArrayDataArray;
1970    i, j: Integer;
1971 <  LocalData: PChar;
1971 >  LocalData: PByte;
1972    LocalDate, LocalDouble: Double;
1973    LocalInt: Integer;
1974    LocalBool: wordBool;
# Line 2029 | Line 2035 | begin
2035              SQL_TIMESTAMP:
2036              begin
2037                LocalDate := TimeStampToMSecs(DateTimeToTimeStamp(Qry[i].AsDateTime));
2038 <              LocalData := PChar(@LocalDate);
2038 >              LocalData := PByte(@LocalDate);
2039              end;
2040              SQL_TYPE_DATE:
2041              begin
2042                LocalInt := DateTimeToTimeStamp(Qry[i].AsDateTime).Date;
2043 <              LocalData := PChar(@LocalInt);
2043 >              LocalData := PByte(@LocalInt);
2044              end;
2045              SQL_TYPE_TIME:
2046              begin
2047                LocalInt := DateTimeToTimeStamp(Qry[i].AsDateTime).Time;
2048 <              LocalData := PChar(@LocalInt);
2048 >              LocalData := PByte(@LocalInt);
2049              end;
2050              SQL_SHORT, SQL_LONG:
2051              begin
2052                if (fdDataScale = 0) then
2053                begin
2054                  LocalInt := Qry[i].AsLong;
2055 <                LocalData := PChar(@LocalInt);
2055 >                LocalData := PByte(@LocalInt);
2056                end
2057                else
2058                if (fdDataScale >= (-4)) then
2059                begin
2060                  LocalCurrency := Qry[i].AsCurrency;
2061 <                LocalData := PChar(@LocalCurrency);
2061 >                LocalData := PByte(@LocalCurrency);
2062                end
2063                else
2064                begin
2065                 LocalDouble := Qry[i].AsDouble;
2066 <               LocalData := PChar(@LocalDouble);
2066 >               LocalData := PByte(@LocalDouble);
2067                end;
2068              end;
2069              SQL_INT64:
# Line 2065 | Line 2071 | begin
2071                if (fdDataScale = 0) then
2072                begin
2073                  LocalInt64 := Qry[i].AsInt64;
2074 <                LocalData := PChar(@LocalInt64);
2074 >                LocalData := PByte(@LocalInt64);
2075                end
2076                else
2077                if (fdDataScale >= (-4)) then
2078                begin
2079                  LocalCurrency := Qry[i].AsCurrency;
2080 <                LocalData := PChar(@LocalCurrency);
2080 >                LocalData := PByte(@LocalCurrency);
2081                  end
2082                  else
2083                  begin
2084                    LocalDouble := Qry[i].AsDouble;
2085 <                  LocalData := PChar(@LocalDouble);
2085 >                  LocalData := PByte(@LocalDouble);
2086                  end
2087              end;
2088              SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT:
2089              begin
2090                LocalDouble := Qry[i].AsDouble;
2091 <              LocalData := PChar(@LocalDouble);
2091 >              LocalData := PByte(@LocalDouble);
2092              end;
2093              SQL_BOOLEAN:
2094              begin
2095                LocalBool := Qry[i].AsBoolean;
2096 <              LocalData := PChar(@LocalBool);
2096 >              LocalData := PByte(@LocalBool);
2097              end;
2098            end;
2099  
# Line 2197 | Line 2203 | begin
2203      FUpdateObject.Apply(ukDelete,Buff)
2204    else
2205    begin
2206 <    SetInternalSQLParams(FQDelete, Buff);
2206 >    SetInternalSQLParams(FQDelete.Params, Buff);
2207      FQDelete.ExecQuery;
2208    end;
2209    with PRecordData(Buff)^ do
# Line 2346 | Line 2352 | begin
2352        FUpdateObject.Apply(ukModify,Buff);
2353    end
2354    else begin
2355 <    SetInternalSQLParams(Qry, Buff);
2355 >    SetInternalSQLParams(Qry.Params, Buff);
2356      Qry.ExecQuery;
2357    end;
2358    PRecordData(Buff)^.rdUpdateStatus := usUnmodified;
# Line 2380 | Line 2386 | begin
2386          end
2387          else
2388            Qry := FQRefresh;
2389 <        SetInternalSQLParams(Qry, Buff);
2389 >        SetInternalSQLParams(Qry.Params, Buff);
2390          Qry.ExecQuery;
2391          try
2392            if (Qry.SQLStatementType = SQLExecProcedure) or Qry.Next then
# Line 2592 | Line 2598 | begin
2598    if (FBase.Database <> Value) then
2599    begin
2600      CheckDatasetClosed;
2601 +    InternalUnPrepare;
2602      FBase.Database := Value;
2603      FQDelete.Database := Value;
2604      FQInsert.Database := Value;
# Line 2619 | Line 2626 | begin
2626    end;
2627   end;
2628  
2629 < procedure TIBCustomDataSet.SetInternalSQLParams(Qry: TIBSQL; Buffer: Pointer);
2629 > procedure TIBCustomDataSet.SetInternalSQLParams(Params: ISQLParams; Buffer: Pointer);
2630   var
2631    i, j: Integer;
2632    cr, data: PChar;
# Line 2635 | Line 2642 | begin
2642      InternalPrepare;
2643    OldBuffer := nil;
2644    try
2645 <    for i := 0 to Qry.Params.GetCount - 1 do
2645 >    for i := 0 to Params.GetCount - 1 do
2646      begin
2647 <      Param := Qry.Params[i];
2647 >      Param := Params[i];
2648        fn := Param.Name;
2649        if (Pos('OLD_', fn) = 1) then {mbcs ok}
2650        begin
# Line 3670 | Line 3677 | const
3677   var
3678    FieldType: TFieldType;
3679    FieldSize: Word;
3680 +  FieldDataSize: integer;
3681    charSetID: short;
3682    CharSetSize: integer;
3683    CharSetName: RawByteString;
# Line 3806 | Line 3814 | begin
3814          FieldName := getSQLName;
3815          FAliasNameList[i] := DBAliasName;
3816          FieldSize := 0;
3817 +        FieldDataSize := GetSize;
3818          FieldPrecision := 0;
3819          FieldNullable := IsNullable;
3820          CharSetSize := 0;
# Line 3818 | Line 3827 | begin
3827             their values }
3828            SQL_VARYING, SQL_TEXT:
3829            begin
3830 <            FirebirdAPI.CharSetWidth(getCharSetID,CharSetSize);
3831 <            CharSetName := FirebirdAPI.GetCharsetName(getCharSetID);
3832 <            FirebirdAPI.CharSetID2CodePage(getCharSetID,FieldCodePage);
3833 <            FieldSize := GetSize div CharSetSize;
3830 >            if not Database.Attachment.CharSetWidth(getCharSetID,CharSetSize) then
3831 >              CharSetSize := 1;
3832 >            CharSetName := Database.Attachment.GetCharsetName(getCharSetID);
3833 >            Database.Attachment.CharSetID2CodePage(getCharSetID,FieldCodePage);
3834 >            FieldSize := FieldDataSize div CharSetSize;
3835              FieldType := ftString;
3836            end;
3837            { All Doubles/Floats should be cast to doubles }
# Line 3872 | Line 3882 | begin
3882                FieldSize := -getScale;
3883              end
3884              else
3885 <              FieldType := ftFloat
3885 >              FieldType := ftFloat;
3886            end;
3887            SQL_TIMESTAMP: FieldType := ftDateTime;
3888            SQL_TYPE_TIME: FieldType := ftTime;
# Line 3882 | Line 3892 | begin
3892              FieldSize := sizeof (TISC_QUAD);
3893              if (getSubtype = 1) then
3894              begin
3895 <              FirebirdAPI.CharSetWidth(getCharSetID,CharSetSize);
3896 <              CharSetName := FirebirdAPI.GetCharsetName(getCharSetID);
3897 <              FirebirdAPI.CharSetID2CodePage(getCharSetID,FieldCodePage);
3895 >              if not Database.Attachment.CharSetWidth(getCharSetID,CharSetSize) then
3896 >                CharSetSize := 1;
3897 >              CharSetName := Database.Attachment.GetCharsetName(getCharSetID);
3898 >              Database.Attachment.CharSetID2CodePage(getCharSetID,FieldCodePage);
3899                FieldType := ftMemo;
3900              end
3901              else
# Line 3916 | Line 3927 | begin
3927              Name := FieldAliasName;
3928              FAliasNameMap[FieldNo-1] := DBAliasName;
3929              Size := FieldSize;
3930 +            DataSize := FieldDataSize;
3931              Precision := FieldPrecision;
3932              Required := not FieldNullable;
3933              RelationName := aRelationName;
# Line 4671 | Line 4683 | begin
4683    Transaction.StartTransaction;
4684   end;
4685  
4686 < function TIBCustomDataSet.PSGetTableName: string;
4686 > function TIBCustomDataSet.PsGetTableName: string;
4687   begin
4688   //  if not FInternalPrepared then
4689   //    InternalPrepare;
# Line 4812 | Line 4824 | begin
4824    inherited Destroy;
4825   end;
4826  
4827 < procedure TIBDataSetUpdateObject.SetRefreshSQL(Value: TStrings);
4827 > procedure TIBDataSetUpdateObject.SetRefreshSQL(value: TStrings);
4828   begin
4829    FRefreshSQL.Assign(Value);
4830   end;
4831  
4832 < procedure TIBDataSetUpdateObject.InternalSetParams(Query: TIBSQL; buff: PChar);
4832 > procedure TIBDataSetUpdateObject.InternalSetParams(Params: ISQLParams;
4833 >  buff: PChar);
4834   begin
4835    if not Assigned(DataSet) then Exit;
4836 <  DataSet.SetInternalSQLParams(Query, buff);
4836 >  DataSet.SetInternalSQLParams(Params, buff);
4837 > end;
4838 >
4839 > procedure TIBDataSetUpdateObject.InternalSetParams(Query: TIBSQL; buff: PChar);
4840 > begin
4841 >  InternalSetParams(Query.Params,buff);
4842   end;
4843  
4844   function TIBDSBlobStream.GetSize: Int64;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines