Skip to content

Commit fe97e5b

Browse files
committed
cleanup
1 parent fe57f23 commit fe97e5b

File tree

2 files changed

+11
-75
lines changed

2 files changed

+11
-75
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,11 +3516,10 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
35163516
dataType == SQL_VARCHAR || dataType == SQL_LONGVARCHAR ||
35173517
dataType == SQL_VARBINARY || dataType == SQL_LONGVARBINARY || dataType == SQL_SS_XML) &&
35183518
(columnSize == 0 || columnSize == SQL_NO_TOTAL || columnSize > SQL_MAX_LOB_SIZE)) {
3519-
std::cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
35203519
lobColumns.push_back(i + 1); // 1-based
35213520
}
35223521
}
3523-
std::cout<<"lobColumns.size()="<<lobColumns.size()<<std::endl;
3522+
35243523
// If we have LOBs → fall back to row-by-row fetch + SQLGetData_wrap
35253524
if (!lobColumns.empty()) {
35263525
LOG("LOB columns detected, using per-row SQLGetData path");
@@ -3535,7 +3534,7 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
35353534
}
35363535
return SQL_SUCCESS;
35373536
}
3538-
std::cout<<"No LOB columns, using batch fetch path"<<std::endl;
3537+
35393538
// Initialize column buffers
35403539
ColumnBuffers buffers(numCols, fetchSize);
35413540

0 commit comments

Comments
 (0)