Skip to content

Commit a86a2aa

Browse files
committed
cleanup
1 parent fe57f23 commit a86a2aa

File tree

2 files changed

+11
-80
lines changed

2 files changed

+11
-80
lines changed

main.py

Lines changed: 9 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,17 @@
55

66
setup_logging('stdout')
77

8-
# conn_str = os.getenv("DB_CONNECTION_STRING")
9-
# conn = connect(conn_str)
10-
11-
# # conn.autocommit = True
12-
13-
# cursor = conn.cursor()
14-
# cursor.execute("SELECT database_id, name from sys.databases;")
15-
# rows = cursor.fetchall()
16-
17-
# for row in rows:
18-
# print(f"Database ID: {row[0]}, Name: {row[1]}")
19-
20-
# cursor.close()
21-
# conn.close()
22-
23-
# import pyodbc
24-
25-
# --- Connection ---
26-
conn_str = "DRIVER={ODBC Driver 18 for SQL Server};Server=Saumya;DATABASE=master;UID=sa;PWD=HappyPass1234;Trust_Connection=yes;TrustServerCertificate=yes;"
8+
conn_str = os.getenv("DB_CONNECTION_STRING")
279
conn = connect(conn_str)
28-
cursor = conn.cursor()
29-
30-
# --- Create a test table ---
31-
# cursor.execute("""
32-
# IF OBJECT_ID('dbo.TestXML', 'U') IS NOT NULL DROP TABLE dbo.TestXML;
33-
# CREATE TABLE dbo.TestXML (
34-
# id INT IDENTITY PRIMARY KEY,
35-
# xml_col XML
36-
# )
37-
# """)
38-
# conn.commit()
39-
40-
# # --- Test short XML insertion ---
41-
# short_xml = "<root><item>123</item></root>"
42-
# cursor.execute("INSERT INTO dbo.TestXML (xml_col) VALUES (?)", short_xml)
43-
# conn.commit()
4410

45-
# # --- Test long XML insertion (simulate DAE / large XML) ---
46-
# long_xml = "<root>" + "".join(f"<item>{i}</item>" for i in range(10000)) + "</root>"
47-
# cursor.execute("INSERT INTO dbo.TestXML (xml_col) VALUES (?)", long_xml)
48-
# conn.commit()
11+
# conn.autocommit = True
4912

50-
# # --- Fetch and verify ---
51-
# cursor.execute("SELECT id, xml_col FROM dbo.TestXML ORDER BY id")
52-
# rows = cursor.fetchall()
53-
54-
# for row in rows:
55-
# print(f"ID: {row.id}, XML Length: {len(str(row.xml_col))}")
56-
57-
# --- Clean up ---
58-
# cursor.execute("DROP TABLE dbo.TestXML")
59-
# conn.commit()
60-
# cursor.close()
61-
# conn.close()
62-
63-
64-
65-
SMALL_XML = "<root><item>1</item></root>"
66-
LARGE_XML = "<root>" + "".join(f"<item>{i}</item>" for i in range(10000)) + "</root>"
67-
EMPTY_XML = ""
68-
INVALID_XML = "<root><item></root>" # malformed
69-
70-
71-
cursor.execute("CREATE TABLE #pytest_xml_empty_null (id INT PRIMARY KEY IDENTITY(1,1), xml_col XML NULL);")
72-
conn.commit()
73-
74-
cursor.execute("INSERT INTO #pytest_xml_empty_null (xml_col) VALUES (?);", EMPTY_XML)
75-
cursor.execute("INSERT INTO #pytest_xml_empty_null (xml_col) VALUES (?);", None)
76-
conn.commit()
13+
cursor = conn.cursor()
14+
cursor.execute("SELECT database_id, name from sys.databases;")
15+
rows = cursor.fetchall()
7716

78-
rows = [r[0] for r in cursor.execute("SELECT xml_col FROM #pytest_xml_empty_null ORDER BY id;").fetchall()]
79-
print(rows)
80-
assert rows[0] == EMPTY_XML
81-
assert rows[1] is None
17+
for row in rows:
18+
print(f"Database ID: {row[0]}, Name: {row[1]}")
8219

83-
cursor.execute("DROP TABLE IF EXISTS #pytest_xml_empty_null;")
84-
conn.commit()
20+
cursor.close()
21+
conn.close()

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,7 +2989,6 @@ SQLRETURN SQLBindColums(SQLHSTMT hStmt, ColumnBuffers& buffers, py::list& column
29892989
buffers.indicators[col - 1].data());
29902990
break;
29912991
}
2992-
case SQL_SS_XML:
29932992
case SQL_WCHAR:
29942993
case SQL_WVARCHAR:
29952994
case SQL_WLONGVARCHAR: {
@@ -3192,10 +3191,6 @@ SQLRETURN FetchBatchData(SQLHSTMT hStmt, ColumnBuffers& buffers, py::list& colum
31923191
}
31933192
break;
31943193
}
3195-
case SQL_SS_XML: {
3196-
row.append(FetchLobColumnData(hStmt, col, SQL_C_WCHAR, true, false));
3197-
break;
3198-
}
31993194
case SQL_WCHAR:
32003195
case SQL_WVARCHAR:
32013196
case SQL_WLONGVARCHAR: {
@@ -3516,11 +3511,10 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
35163511
dataType == SQL_VARCHAR || dataType == SQL_LONGVARCHAR ||
35173512
dataType == SQL_VARBINARY || dataType == SQL_LONGVARBINARY || dataType == SQL_SS_XML) &&
35183513
(columnSize == 0 || columnSize == SQL_NO_TOTAL || columnSize > SQL_MAX_LOB_SIZE)) {
3519-
std::cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
35203514
lobColumns.push_back(i + 1); // 1-based
35213515
}
35223516
}
3523-
std::cout<<"lobColumns.size()="<<lobColumns.size()<<std::endl;
3517+
35243518
// If we have LOBs → fall back to row-by-row fetch + SQLGetData_wrap
35253519
if (!lobColumns.empty()) {
35263520
LOG("LOB columns detected, using per-row SQLGetData path");
@@ -3535,7 +3529,7 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
35353529
}
35363530
return SQL_SUCCESS;
35373531
}
3538-
std::cout<<"No LOB columns, using batch fetch path"<<std::endl;
3532+
35393533
// Initialize column buffers
35403534
ColumnBuffers buffers(numCols, fetchSize);
35413535

0 commit comments

Comments
 (0)