Page 1 of 1

VARCHAR over 256 characters return always 256?

Posted: 28.07.2011, 08:13
by noctrex
I have a database in which there are many VARCHAR(1000) fields, but it seems that zeos 6.6.6 always returns only the first 256 charaters.
Is there a solution for this problem?
I cannot alter the database, so I must find a solution within delphi.

Posted: 28.07.2011, 08:47
by jeremicm
varchar(1000) holds only 1000 bytes, not 1000 characters... try using varchar(max) instead....

Posted: 28.07.2011, 08:52
by Wild_Pointer
hello noctrex,

I don't know how it is with ms sql, but with postgresql I use text datatype in DB for fields that are more than 255 char long. That way I get memofield instead of stringfield and it may contain more than 255 chars.

Maybe someone here with experience using ms sql will add some new ideas...

Good luck!

Posted: 28.07.2011, 09:05
by noctrex
Thanks for your answer, I've tried the following on a test database:

when using a nvarchar(max) field (I need an N* type field for encoding greek charaters) I get this error:
"General SQL Server error: Check messages from the SQL Server. Unicode data in a Unicode-only collation or ntext data cannot br sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier."

And when I try to get a ntext field I get the following:
"General SQL Server error: Check messages from the SQL Server. Argument data type ntext is invalid for argument 1 of replace function."

Only setting the field to a nvarchar(N) works, but always only getting the first 256 characters :/

For the record, I'm using Delphi 7 with Zeos 6.6.6

Posted: 28.07.2011, 09:54
by noctrex
Small quick'n'dirty workaround for this issue:

I just split, inside the sql query, the long varchar into pieces of 250 chars like this:

SUBSTRING(ISNULL(Ap_Memo, ''''), 0, 250) AS Ap_Memo01,
SUBSTRING(ISNULL(Ap_Memo, ''''), 250, 250) AS Ap_Memo02,
SUBSTRING(ISNULL(Ap_Memo, ''''), 500, 250) AS Ap_Memo03,
SUBSTRING(ISNULL(Ap_Memo, ''''), 750, 250) AS Ap_Memo04,
SUBSTRING(ISNULL(Ap_Memo, ''''), 1000, 250) AS Ap_Memo05,
.. and so on...

and concatenate them back together into one large string inside Delphi.
I know it's not optimal, but at least it works.

256 chars limit

Posted: 22.05.2012, 10:10
by rautgigi
Hi,

Using ntwdblib from microsoft it will limit the varchar to 256. This is a driver limitation. You can use ADO, or freeTDS in order to use varchar with more than 256 chars. It should work also with unicode data ....

Bogdan