Skip to content

Commit 327ee42

Browse files
Sync SQL Server ODBC constants between Python and C++
- Add SQL_SS_XML (-152) constant to Python constants.py (was incorrectly using SQL_XML = 241) - Add SQL_SS_TIME2 (-154) constant for SQL Server TIME(n) type - Update cursor type map to use SQL_SS_XML and add SQL_SS_TIME2 mapping - Add sync comment in C++ to prevent future constant drift Constants verified against Microsoft Learn ODBC documentation: - SQL_SS_TIME2: -154 (SQLNCLI.h) - SQL_SS_TIMESTAMPOFFSET: -155 (SQLNCLI.h) - SQL_SS_XML: -152 (SQL Server ODBC driver) - SQL_SS_UDT: -151 (SQL Server ODBC driver) Addresses Copilot review feedback on PR microsoft#355
1 parent 6eb43ea commit 327ee42

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

mssql_python/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ class ConstantsDDBC(Enum):
115115
SQL_FETCH_RELATIVE = 6
116116
SQL_FETCH_BOOKMARK = 8
117117
SQL_DATETIMEOFFSET = -155
118+
SQL_SS_TIME2 = -154 # SQL Server TIME(n) type
118119
SQL_SS_UDT = -151 # SQL Server User-Defined Types (geometry, geography, hierarchyid)
120+
SQL_SS_XML = -152 # SQL Server XML type
119121
SQL_C_SS_TIMESTAMPOFFSET = 0x4001
120122
SQL_SCOPE_CURROW = 0
121123
SQL_BEST_ROWID = 1

mssql_python/cursor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def _get_type_map(cls):
9696
ddbc_sql_const.SQL_DATE.value: datetime.date,
9797
ddbc_sql_const.SQL_TIMESTAMP.value: datetime.datetime,
9898
ddbc_sql_const.SQL_TIME.value: datetime.time,
99+
ddbc_sql_const.SQL_SS_TIME2.value: datetime.time, # SQL Server TIME(n)
99100
ddbc_sql_const.SQL_BIT.value: bool,
100101
ddbc_sql_const.SQL_TINYINT.value: int,
101102
ddbc_sql_const.SQL_SMALLINT.value: int,
@@ -105,7 +106,7 @@ def _get_type_map(cls):
105106
ddbc_sql_const.SQL_LONGVARBINARY.value: bytes,
106107
ddbc_sql_const.SQL_GUID.value: uuid.UUID,
107108
ddbc_sql_const.SQL_SS_UDT.value: bytes,
108-
ddbc_sql_const.SQL_XML.value: str,
109+
ddbc_sql_const.SQL_SS_XML.value: str, # SQL Server XML type (-152)
109110
ddbc_sql_const.SQL_DATETIME2.value: datetime.datetime,
110111
ddbc_sql_const.SQL_SMALLDATETIME.value: datetime.datetime,
111112
ddbc_sql_const.SQL_DATETIMEOFFSET.value: datetime.datetime,

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#define SQL_DATETIME2 (42)
3232
#define SQL_SMALLDATETIME (58)
3333

34+
// NOTE: The following SQL Server-specific type constants MUST stay in sync with
35+
// the corresponding values in mssql_python/constants.py (ConstantsDDBC enum):
36+
// SQL_SS_TIME2, SQL_SS_XML, SQL_SS_UDT, SQL_DATETIME2, SQL_SMALLDATETIME, SQL_DATETIMEOFFSET
37+
3438
#define STRINGIFY_FOR_CASE(x) \
3539
case x: \
3640
return #x

0 commit comments

Comments
 (0)