#1 2015-06-16 22:06:43

mike76
Member
Registered: 2015-06-16
Posts: 18

Field size issue DBGrid in 17 - TClientDataset use sample

Hi,

First thanks for this powerful framework, just found it yesterday.

I've found a possible bug or maybe you can let me know what I'm doing wrong, steps to reproduce the problem:
run the application and enter a Firstname longer than 24 chars. Once you are exiting the editor the text gets cut off after 24 chars. Same happens to the other TEXT field LastName, it has a different maximum length.
What I discovered is that DBGrid somehow sets the length of the field based on the longest string for that column, when loading the database and everything that is larger is cut off.
The only way to fix this is to enter long strings in some dummy row and all dbgrid columns will have "unlimited" length.

Could you please look into this.
Thanks

Offline

#2 2015-06-17 06:52:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,203
Website

Re: Field size issue DBGrid in 17 - TClientDataset use sample

AFAIR TSQLDBProxyStatementRandomAccess will indeed compute the current maximum size if it is not supplied by the statement.
So I guess this would depend on the database you are running on. For Sqlite3, it may not have any value set, since there is no size limitation for Sqlite3 TEXT fields.

I've added a TSynDBDataSet.IgnoreColumnDataSize property to force ftWideMemo kind of field, which may allow any length, if needed.
See http://synopse.info/fossil/info/e2150f6528

Offline

#3 2015-06-17 14:33:51

mike76
Member
Registered: 2015-06-16
Posts: 18

Re: Field size issue DBGrid in 17 - TClientDataset use sample

Thanks ab, for your reply. Unfortunately this still doesn't work.

I've just compiled the project (under Delphi 7) and use the default database backupbackground.db3. I select "SQLite3 SQL TDataset" and "check Via TClientDataset". I can enter only 24 chars in FirstName column and 12 in Last Name.

I've tested another partial free/commercial component that uses a UniDirQuery which had an event (InitFieldDef) where you can set/override the default values of a field before creating the dataset. There I could set the width to 300 (or other value) for ftWideString and change datatype if I want for other fields.

Offline

#4 2015-06-18 16:16:09

mike76
Member
Registered: 2015-06-16
Posts: 18

Re: Field size issue DBGrid in 17 - TClientDataset use sample

Did you had time to check the field size issue?

Also in this project I use the :
TSynDBDataSet(ds1.DataSet).CommandText which is defined as string, so under Delphi 7 does not support UTF8 statements. I've tried to change the source to widestring, but have problem with PSSetCommandText which on compilation triggers an error. Is there a way to fix this to support UTF8 under Delphi 7 ?

Thanks

Offline

#5 2016-07-01 00:10:21

BLADEXP
Member
Registered: 2016-06-30
Posts: 3

Re: Field size issue DBGrid in 17 - TClientDataset use sample

My solution:

TSynBinaryDataSet = class(TSynVirtualDataSet)
  protected
    fData: RawByteString;
    fDataAccess: TSQLDBProxyStatementRandomAccess;
    fTemp64: Int64;
    fColWSDataSize:TIntegerDynArray;
    .....

procedure TSynBinaryDataSet.InternalInitFieldDefs;
var F: integer;
    DBType: TFieldType;
    NumWS: integer;
begin
  NumWS:=0;
  FieldDefs.Clear;
  if fDataAccess=nil then
    exit;
  for F := 0 to fDataAccess.ColumnCount-1 do
    with fDataAccess.Columns[F] do begin
    case ColumnType of
    SynCommons.ftInt64: DBType := ftLargeint;
    SynCommons.ftDate:  DBType := ftDateTime;
    SynCommons.ftUTF8:
     begin
      if length(fColWSDataSize) > 0 then
        begin
         DBType := ftWideString;
         inc(NumWS);
        end
         else
      if ColumnDataSize=0 then
        DBType := ftDefaultMemo else DBType := ftWideString; // means UnicodeString for Delphi 2009+
     end;
    SynCommons.ftBlob:  DBType := ftBlob;
    SynCommons.ftDouble, SynCommons.ftCurrency: DBType := ftFloat;
    else raise EDatabaseError.CreateFmt('GetFieldData ColumnType=%d',[ord(ColumnType)]);
    end;
    if (DBType = ftWideString) and (length(fColWSDataSize) >= NumWS) then
     FieldDefs.Add(UTF8ToString(ColumnName),DBType,fColWSDataSize[NumWS-1]) else
       FieldDefs.Add(UTF8ToString(ColumnName),DBType,ColumnDataSize);
  end;
end;

TSynDBDataSet = class(TCustomClientDataSet)
  protected
    fDataSet: TSynDBSQLDataSet;
    fProvider: TDataSetProvider;
    fIgnoreColumnDataSize: boolean;
    function GetConnection: TSQLDBConnectionProperties; virtual;
    procedure SetConnection(Value: TSQLDBConnectionProperties); virtual;
    // from TDataSet
    procedure OpenCursor(InfoQuery: Boolean); override;
    {$ifdef ISDELPHI2007ANDUP}
    // from IProviderSupport
    function PSGetCommandText: string; override;
    {$endif}
  public
    /// initialize the instance
    constructor Create(AOwner: TComponent); overload; override;   
    constructor Create(AOwner: TComponent; ColWSDataSize:TIntegerDynArray); overload;
    ..........

Offline

Board footer

Powered by FluxBB