Skip to content

Commit

Permalink
Add support for SQL_WLONGVARCHAR data type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mloskot committed Feb 27, 2019
1 parent 53fc161 commit 61ae9a8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nanodbc/nanodbc.cpp
Expand Up @@ -2834,6 +2834,11 @@ class result::result_impl
col.blob_ = true;
col.clen_ = 0;
break;
case SQL_WLONGVARCHAR:
col.ctype_ = sql_ctype<wide_string>::value;
col.blob_ = true;
col.clen_ = 0;
break;
case SQL_BINARY:
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
Expand Down
40 changes: 40 additions & 0 deletions test/mssql_test.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 61ae9a8

Please sign in to comment.