Page 1 of 1

SELECT 'very loooooong literal' - result is truncated to 126 characters

Posted: 14.03.2016, 13:42
by jaco
Hi.

Code: Select all

 
  String literal = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  int literalLen = literal.Length(); // 130
  ZQuery1->SQL->Text = "select '" + literal + "'";
  ZQuery1->Active = true;
  String string = ZQuery1->Fields->FieldByNumber(1)->AsString; // { u"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456" }
  int strLen = string.Length(); // 126
  int size = ZQuery1->Fields->FieldByNumber(1)->Size; // 126
  ZQuery1->Active = false;
Why result string is truncated?
How to solve my problem without changing query sql text?

db: Postgresql 9.3

Re: SELECT 'very loooooong literal' - result is truncated to 126 characters

Posted: 16.03.2016, 20:59
by marsupilami
Hello Jaco,

in my test environment (Delphi XE7, PostgreSQL 9.4, Zeos 7.2) this works as expected. Which Version of Zeos and C++ Builder do you use?

My test:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  Teststring: String;
begin
  Teststring := '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';
  ZQuery1.SQL.Text := 'select ''' + Teststring + '''';
  ZQuery1.Open;
  ShowMessage(IntToStr(Length(ZQuery1.Fields[0].AsString))); // Shows 130
end;
With best regards,

Jan

Re: SELECT 'very loooooong literal' - result is truncated to 126 characters

Posted: 17.03.2016, 13:25
by jaco
Hi all.

I use C++Builder XE8 and ZEOS rev. 3628 from branch testing-7.2... with small (very old, I forgot about it) own modification.
This modification is cause of truncation... so sorry for confusing you.

Primary problem is unicode literals handling.
In TZPostgreSQLResultSet.DefinePostgreSQLToSQLType procedure we have:

Code: Select all

  if SQLType <> stUnknown then
    ColumnInfo.ColumnType := SQLType
  else
  begin
    ColumnInfo.ColumnType := stString;
    ColumnInfo.Precision := 255;
    ColumnInfo.ReadOnly := True;
  end;
Literal has unknown SQLType... and then... ColumnInfo.ColumnType := stString;... :?:

Code: Select all

  if SQLType <> stUnknown then
    ColumnInfo.ColumnType := SQLType
  else
  begin
    if (Connection.GetConSettings.CPType = cCP_UTF16) then
      ColumnInfo.ColumnType := stUnicodeString
    else
      ColumnInfo.ColumnType := stString;
    ColumnInfo.Precision := 255;
    ColumnInfo.ReadOnly := True;
  end;
Will this fix resolve my problem with unicode literals?
Thanks for any help.

Re: SELECT 'very loooooong literal' - result is truncated to 126 characters

Posted: 19.03.2016, 22:41
by marsupilami
Hello Jaco,

I suggest you try it. If you don't get the expected result, let's solve the problems.
With best regards,

Jan