Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poco:Data::ODBC - MSSQL (n)varchar(max) length issue #4324

Open
Tracked by #4230
Spaky opened this issue Dec 6, 2023 · 2 comments
Open
Tracked by #4230

Poco:Data::ODBC - MSSQL (n)varchar(max) length issue #4324

Spaky opened this issue Dec 6, 2023 · 2 comments
Assignees

Comments

@Spaky
Copy link
Contributor

Spaky commented Dec 6, 2023

Describe the bug
The data binding of (n)varchar(max) field in Poco:Data::ODBC seems just to allow max 8000 bytes, but MSSQL Server allow allows up to 2^31-1 bytes.

To Reproduce
Create a table with a varchar(max) or nvarchar(max) field, insert data with more then 8000 byte.

Expected behavior
I should be possible to insert data with more then 8000 bytes when SQL datatype is (n)varchar(max).

Logs
INSERT failed: exception: 'class Poco::Data::LengthExceededException' what: 'Data too long' message: 'Error binding column 6 size=67150, max size=8000)'

Please add relevant environment information:

  • Windows 10, Windows Server 2019
  • POCO Version: 1.12.4
  • MS SQLServer 2019

Additional context
I think the retrieving of the type info of the DB needs a special handling for (n)varchar(max).

@Spaky Spaky added the bug label Dec 6, 2023
@aleks-f aleks-f added feature and removed bug labels Dec 7, 2023
@aleks-f
Copy link
Member

aleks-f commented Dec 7, 2023

From SQLBindParameter:

If the SQL data type passed in is a character type, ColumnSize is the size in characters (not bytes). If the length of the data string in bytes is greater than 8000, ColumnSize should be set to SQL_SS_LENGTH_UNLIMITED, indicating that there is no limit to the size of the SQL type.

For instance, if the SQL data type is SQL_WVARCHAR, ColumnSize should not be greater than 4000. If the actual data length is greater than 4000, then ColumnSize should be set to SQL_SS_LENGTH_UNLIMITED so that nvarchar(max) will be used by driver.

The SQL_SS_LENGTH_UNLIMITED is not standard ODBC. If you want this feature, add the SQLServer-specific session feature like eg. multiActiveResultset:

// SQL Server supports multiple active resultsets
// currently has no effect on other back ends
addFeature("multiActiveResultset",
&SessionImpl::setMultiActiveResultset,
&SessionImpl::getMultiActiveResultset);

and send pull request.

@aleks-f
Copy link
Member

aleks-f commented Dec 7, 2023

See also DataFormat:

SQL Server Native Client uses SQL_SS_LENGTH_UNLIMITED to denote that the size of a column is greater than 8,000 bytes for large object (LOB) types. Beginning with SQL Server 2008, the same value is used for CLR UDTs when their size is greater than 8,000 bytes.

The SQL Server Native Client (often abbreviated SNAC) has been removed from SQL Server 2022 (16.x) and SQL Server Management Studio 19 (SSMS). The SQL Server Native Client (SQLNCLI or SQLNCLI11) and the legacy Microsoft OLE DB Provider for SQL Server (SQLOLEDB) are not recommended for new application development.

@aleks-f aleks-f added this to the Release 1.14.0 milestone Dec 21, 2023
@aleks-f aleks-f self-assigned this Dec 21, 2023
aleks-f added a commit that referenced this issue Oct 15, 2024
@aleks-f aleks-f added the fixed label Oct 16, 2024
aleks-f added a commit that referenced this issue Oct 19, 2024
…#4738)

* fix(ODBC): Poco:Data::ODBC - MSSQL (n)varchar(max) length issue #4324

* chore(ODBC): remove unused vars; fix SQL Server SDK include path #4324

* fix(ODBC): trim UTF16 string #4324

* chore(ODBC): add compile time big string diagnostics #4324

* chore(ODBC): add SQLServer big string vector test case #4324

* fix(ODBC): detect SQLServer header #4324

* chore: add listing msodbdcsql18 folder #4324

* ci: change odbc drivers installation order #4324

* chore(CMake): Add option ENABLE_DATA_SQL_SERVER_BIG_STRINGS, auto-detection of msodbcsql.h on Linux and macOS

* fix(ODBC): detect backend at runtime for string size; add Session::dbmsName() #4324

* fix(ODBC): wrong char to string conversion #4324

---------

Co-authored-by: cunj123 <n.belusic@pta.hr>
Co-authored-by: Matej Kenda <matejken@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants