Skip to content

Commit 960edef

Browse files
committed
resolved comments
1 parent daab245 commit 960edef

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

mssql_python/pybind/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ target_compile_definitions(ddbc_bindings PRIVATE
272272

273273
# Add warning level flags for MSVC
274274
if(MSVC)
275-
target_compile_options(ddbc_bindings PRIVATE /W4 )
275+
target_compile_options(ddbc_bindings PRIVATE /W4 /WX)
276276
endif()
277277

278278
# Add macOS-specific string conversion fix

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,11 +1875,15 @@ SQLRETURN SQLGetData_wrap(SqlHandlePtr StatementHandle, SQLUSMALLINT colCount, p
18751875
row.append(py::none());
18761876
} else if (dataLen == 0) {
18771877
row.append(py::str(""));
1878-
} else {
1879-
assert(dataLen == SQL_NO_TOTAL);
1878+
} else if (dataLen == SQL_NO_TOTAL) {
18801879
LOG("SQLGetData couldn't determine the length of the data. "
1881-
"Returning NULL value instead. Column ID - {}", i);
1880+
"Returning NULL value instead. Column ID - {}, Data Type - {}", i, dataType);
18821881
row.append(py::none());
1882+
} else if (dataLen < 0) {
1883+
LOG("SQLGetData returned an unexpected negative data length. "
1884+
"Raising exception. Column ID - {}, Data Type - {}, Data Length - {}",
1885+
i, dataType, dataLen);
1886+
ThrowStdException("SQLGetData returned an unexpected negative data length");
18831887
}
18841888
} else {
18851889
LOG("Error retrieving data for column - {}, data type - {}, SQLGetData return "

tests/test_004_cursor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5307,6 +5307,8 @@ def test_empty_string_chunk(cursor, db_connection):
53075307

53085308

53095309
def test_varcharmax_short(cursor, db_connection):
5310+
"""Test inserting and retrieving a small string well below any size thresholds.
5311+
# Verifies basic functionality for VARCHAR(MAX) with typical input size."""
53105312
try:
53115313
cursor.execute("DROP TABLE IF EXISTS #pytest_varcharmax")
53125314
cursor.execute("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))")
@@ -5323,6 +5325,9 @@ def test_varcharmax_short(cursor, db_connection):
53235325

53245326

53255327
def test_varcharmax_boundary(cursor, db_connection):
5328+
"""Test inserting and retrieving a string at the boundary size (8000 characters),
5329+
which is the largest size supported without switching to streaming or large object handling.
5330+
Ensures proper handling at this edge case."""
53265331
try:
53275332
cursor.execute("DROP TABLE IF EXISTS #pytest_varcharmax")
53285333
cursor.execute("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))")
@@ -5339,6 +5344,9 @@ def test_varcharmax_boundary(cursor, db_connection):
53395344

53405345

53415346
def test_varcharmax_streaming(cursor, db_connection):
5347+
"""Test inserting and retrieving a string just above the boundary size (8100 characters),
5348+
which requires streaming mechanisms to handle data efficiently.
5349+
Validates that larger data triggers correct processing without truncation."""
53425350
try:
53435351
cursor.execute("DROP TABLE IF EXISTS #pytest_varcharmax")
53445352
cursor.execute("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))")
@@ -5355,6 +5363,8 @@ def test_varcharmax_streaming(cursor, db_connection):
53555363

53565364

53575365
def test_varcharmax_large(cursor, db_connection):
5366+
"""Test inserting and retrieving a very large string (100,000 characters),
5367+
which is well beyond typical sizes and ensures that the system can handle large VARCHAR(MAX) values."""
53585368
try:
53595369
cursor.execute("DROP TABLE IF EXISTS #pytest_varcharmax")
53605370
cursor.execute("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))")
@@ -5371,6 +5381,7 @@ def test_varcharmax_large(cursor, db_connection):
53715381

53725382

53735383
def test_varcharmax_empty_string(cursor, db_connection):
5384+
"""Test inserting and retrieving an empty string to verify correct handling of zero-length data."""
53745385
try:
53755386
cursor.execute("DROP TABLE IF EXISTS #pytest_varcharmax")
53765387
cursor.execute("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))")
@@ -5386,6 +5397,7 @@ def test_varcharmax_empty_string(cursor, db_connection):
53865397

53875398

53885399
def test_varcharmax_null(cursor, db_connection):
5400+
"""Test inserting and retrieving a NULL value to ensure proper handling of SQL NULLs."""
53895401
try:
53905402
cursor.execute("DROP TABLE IF EXISTS #pytest_varcharmax")
53915403
cursor.execute("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))")
@@ -5401,6 +5413,8 @@ def test_varcharmax_null(cursor, db_connection):
54015413

54025414

54035415
def test_varcharmax_transaction_rollback(cursor, db_connection):
5416+
"""Test that inserting a large VARCHAR(MAX) within a transaction that is rolled back
5417+
does not persist the data, ensuring transactional integrity."""
54045418
try:
54055419
cursor.execute("DROP TABLE IF EXISTS #pytest_varcharmax")
54065420
cursor.execute("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))")

0 commit comments

Comments
 (0)