From 61ae9a8fd3f6204aa8b4edb54463d5590c4eabca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Wed, 27 Feb 2019 20:38:17 +0100 Subject: [PATCH] Add support for SQL_WLONGVARCHAR data type SQL Server, for example, reports - `NTEXT` as `SQL_WLONGVARCHAR` - `TEXT` as `SQL_LONGVARCHAR` Formerly, `SQL_WLONGVARCHAR` column was only recognised by accident due to defined `SQL_NVARCHAR(-10)` but the implementation was broken: - `SQLDescribeCol` returns the column size of 1073741824 characters - The column was not recognised as large variable-length object - The column was also incorrectly recognised as `SQLCHAR`-based data - Binding would attempt to pre-allocate large buffer of size `sizeof(SQLCHAR) * 1073741824` Removal of the `SQL_NVARCHAR` proposed in #210 - which is a requirement of this changeset. --- nanodbc/nanodbc.cpp | 5 +++++ test/mssql_test.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/nanodbc/nanodbc.cpp b/nanodbc/nanodbc.cpp index 2e325dbd..aea1f1aa 100644 --- a/nanodbc/nanodbc.cpp +++ b/nanodbc/nanodbc.cpp @@ -2834,6 +2834,11 @@ class result::result_impl col.blob_ = true; col.clen_ = 0; break; + case SQL_WLONGVARCHAR: + col.ctype_ = sql_ctype::value; + col.blob_ = true; + col.clen_ = 0; + break; case SQL_BINARY: case SQL_VARBINARY: case SQL_LONGVARBINARY: diff --git a/test/mssql_test.cpp b/test/mssql_test.cpp index 321540a7..2162c176 100644 --- a/test/mssql_test.cpp +++ b/test/mssql_test.cpp @@ -517,6 +517,46 @@ TEST_CASE_METHOD(mssql_fixture, "test_string_with_varchar_max", "[mssql][string] test_string_with_varchar_max(); } +TEST_CASE_METHOD(mssql_fixture, "test_string_with_ntext", "[mssql][string][ntext]") +{ + nanodbc::connection connection = connect(); + drop_table(connection, NANODBC_TEXT("test_string_with_ntext")); + execute( + connection, NANODBC_TEXT("create table test_string_with_ntext (s ntext);")); + execute( + connection, + NANODBC_TEXT("insert into test_string_with_ntext(s) ") + NANODBC_TEXT("values (REPLICATE(CAST(\'a\' AS nvarchar(MAX)), 15000))")); + + nanodbc::result results = + execute(connection, NANODBC_TEXT("select s from test_string_with_ntext;")); + REQUIRE(results.next()); + + nanodbc::string select; + results.get_ref(0, select); + REQUIRE(select.size() == 15000); +} + +TEST_CASE_METHOD(mssql_fixture, "test_string_with_text", "[mssql][string][text]") +{ + nanodbc::connection connection = connect(); + drop_table(connection, NANODBC_TEXT("test_string_with_text")); + execute( + connection, NANODBC_TEXT("create table test_string_with_text (s text);")); + execute( + connection, + NANODBC_TEXT("insert into test_string_with_text(s) ") + NANODBC_TEXT("values (REPLICATE(CAST(\'a\' AS varchar(MAX)), 15000))")); + + nanodbc::result results = + execute(connection, NANODBC_TEXT("select s from test_string_with_text;")); + REQUIRE(results.next()); + + nanodbc::string select; + results.get_ref(0, select); + REQUIRE(select.size() == 15000); +} + TEST_CASE_METHOD(mssql_fixture, "test_string_vector", "[mssql][string]") { test_string_vector();