Open firebird-automations opened 7 years ago
Commented by: @asfernandes
Cannot reproduce in Linux.
Commented by: Holger Klemt (klemmo)
changed original tracker entry to a more detailed version
Commented by: @asfernandes
I saw it and still cannot reproduce even in 3.02 in w64 as you reported.
Commented by: Holger Klemt (klemmo)
changed original tracker entry to a more detailed version
Commented by: Holger Klemt (klemmo)
at least now we know the problem, but not the reason, when doing a prepare for the statement, we get a value for
XSQLVAR.sqllen
of -32765 which is in fact a stupid value to allocate memory.
Anyone have any idea why this can happen with a stored function used and not when a udf is used?
Commented by: Holger Klemt (klemmo)
Easy way to reproduce (except in isql, which still does not create this error, but almost any other app will):
SELECT cast('any text' as varchar(32765)) || 'abcd' FROM rdb$database
Firebird returns value of lenght which is greater than max value of sqllen defined as shortint in ibase.pas (signed short in ibase.h). This makes it negative. From my point of view Firebird should give 'implementation limit exceeded' error like for following:
SELECT cast('any text' as varchar(32766)) || 'abcd' FROM rdb$database
Maybe in the new API (AFAIK, isql uses new API) something is different and therefore isql doesn't give an error, but for old API it also should return positive length anyway or 'implementation limit exceeded' error instead.
Commented by: Holger Klemt (klemmo)
one easy way to reproduce the error with firebirds own tools:
create the database on fb3 and use a isql version from firebird 2.5 with fb3 client lib and execute again
SELECT cast('any text' as varchar(32765)) || 'abcd' FROM rdb$database
Result:
Statement failed, SQLSTATE = HY001 unable to allocate memory from operating system
Commented by: @asfernandes
Maybe we should change sqllen to USHORT?
Commented by: @dyemanov
MAX_COLUMN_SIZE is 32767, so SSHORT should be enough. No string value should exceed this limit during concatenation, so there should be a bug somewhere.
Commented by: @dyemanov
FB 2.5 operates with MAX_COLUMN_SIZE = 32767 as string length limit, while FB 3.0 defines MAX_STR_SIZE = 65535 for the same goal. This explains the issue.
Commented by: @asfernandes
It's CORE4881 and there is discussion about it in devel.
Main reason to extend it was 32K / 4 was too limited for UTF-8 AFAIR.
Submitted by: Holger Klemt (klemmo)
create the database on fb3 and use a isql version from firebird 2.5 with fb3 client lib and execute
SELECT cast('any text' as varchar(32765)) || 'abcd' FROM rdb$database
Result:
Statement failed, SQLSTATE = HY001 unable to allocate memory from operating system