Fixed issue where a timezone-aware ``datetime`` value being converted to
string for use as a parameter value of a :class:`.mssql.DATETIMEOFFSET`
column was omitting the fractional seconds.
Fixes: #5045
Closes: #5046
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5046
Pull-request-sha:
99dc7b23f69b7b068795a02d20b88bf352c7dcd7
Change-Id: I971629466fe0675536bbdf55693f0c1821dfb3cc
(cherry picked from commit
0d316e42f0645283c222f050c403c9c8d20463ec)
--- /dev/null
+.. change::
+ :tags: bug, mssql
+ :tickets: 5045
+
+ Fixed issue where a timezone-aware ``datetime`` value being converted to
+ string for use as a parameter value of a :class:`.mssql.DATETIMEOFFSET`
+ column was omitting the fractional seconds.
def bind_processor(self, dialect):
def process(value):
"""Convert to string format required by T-SQL."""
- dto_string = value.strftime("%Y-%m-%d %H:%M:%S %z")
+ dto_string = value.strftime("%Y-%m-%d %H:%M:%S.%f %z")
# offset needs a colon, e.g., -0700 -> -07:00
- return dto_string[:23] + ":" + dto_string[23:]
+ return dto_string[:30] + ":" + dto_string[30:]
return process
11,
2,
32,
- 0,
+ 123456,
util.timezone(datetime.timedelta(hours=1)),
)
t.insert().execute(