memsql / singlestore-odbc-connector

8 stars 2 forks source link

For variable-length text columns, SQLColAttribute SQL_DESC_LENGTH returns incorrect values #13

Closed vkr-ayx closed 1 month ago

vkr-ayx commented 4 months ago

I'm using SingleStore driver 1.1.5. When calling SQLColAttributefunction on variable-length text column (TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT) with FieldIdentifier SQL_DESC_LENGTH , the value returned does not correspond to the longest Unicode string that can be possibly stored. Calling SQLColAttribute with FieldIdentifier SQL_COLUMN_LENGTH yields correct results.

For TINYTEXT column, when only ASCII characters are stored, the maximum length of the string that can be stored is 255 characters. Yet the value of SQL_DESC_LENGTH is 63 for a column with utf8mb4 encoding and 85 for a column with utf8mb3 character encoding. This corresponds to maximum length of a Unicode string taking up the most space possible (4B per character and 3B, respectively). The expected value for SQL_DESC_LENGTH is thus 255.

The situation is similar for other variable-length text columns.

TINYTEXT:

utf8mb4 SQL_COLUMN_LENGTH 255 SQL_DESC_LENGTH 63

utf8mb3 SQL_COLUMN_LENGTH 255 SQL_DESC_LENGTH 85

TEXT:

utf8mb4 SQL_COLUMN_LENGTH 65535 SQL_DESC_LENGTH 16383

utf8mb3 SQL_COLUMN_LENGTH 65535 SQL_DESC_LENGTH 21845

MEDIUMTEXT:

utf8mb4 SQL_COLUMN_LENGTH 16777215 SQL_DESC_LENGTH 4194303

utf8mb3 SQL_COLUMN_LENGTH 16777215 SQL_DESC_LENGTH 5592405

LONGTEXT:

utf8mb4 SQL_COLUMN_LENGTH 2147483647 SQL_DESC_LENGTH 1073741823

utf8mb3 SQL_COLUMN_LENGTH 2147483647 SQL_DESC_LENGTH 1431655765

DDL statement used for creating the table being used:

CREATE TABLE platform_tests.read_datatypes_text(
   TINYTEXT1 TINYTEXT CHARACTER SET utf8mb4, 
   TINYTEXT2 TINYTEXT CHARACTER SET utf8mb3, 
   TEXT1 TEXT CHARACTER SET utf8mb4,
   TEXT2 TEXT CHARACTER SET utf8mb3,
   MEDIUMTEXT1 MEDIUMTEXT CHARACTER SET utf8mb4,
   MEDIUMTEXT2 MEDIUMTEXT CHARACTER SET utf8mb3,
   LONGTEXT1 LONGTEXT CHARACTER SET utf8mb4,
   LONGTEXT2 LONGTEXT CHARACTER SET utf8mb3
);