Skip to content

Commit d654a3b

Browse files
Ed Avisramiro
authored andcommitted
Added support for date, time, and datetime2.
1 parent 267f725 commit d654a3b

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/_mssql.pyx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ SQLVARBINARY = SYBVARBINARY
132132
SQLVARCHAR = SYBVARCHAR
133133
SQLUUID = 36
134134

135+
SQLDATE = 40
136+
SQLTIME = 41
137+
SQLDATETIME2 = 42
138+
135139
#######################
136140
## Exception classes ##
137141
#######################
@@ -800,13 +804,25 @@ cdef class MSSQLConnection:
800804
ctx.prec = precision if precision > 0 else 1
801805
return decimal.Decimal(_remove_locale(buf, converted_length).decode(self._charset))
802806

803-
elif dbtype == SQLDATETIM4:
807+
elif dbtype in (SQLDATETIM4, SQLDATETIME2):
804808
dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,
805809
<BYTE *>&dt, -1)
806810
dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
807811
return datetime.datetime(di.year, di.month, di.day,
808812
di.hour, di.minute, di.second, di.millisecond * 1000)
809813

814+
elif dbtype == SQLDATE:
815+
dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,
816+
<BYTE *>&dt, -1)
817+
dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
818+
return datetime.date(di.year, di.month, di.day)
819+
820+
elif dbtype == SQLTIME:
821+
dbconvert(self.dbproc, dbtype, data, -1, SQLDATETIME,
822+
<BYTE *>&dt, -1)
823+
dbdatecrack(self.dbproc, &di, <DBDATETIME *><BYTE *>&dt)
824+
return datetime.time(di.hour, di.minute, di.second, di.millisecond * 1000)
825+
810826
elif dbtype == SQLDATETIME:
811827
dbdatecrack(self.dbproc, &di, <DBDATETIME *>data)
812828
return datetime.datetime(di.year, di.month, di.day,

tests/test_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def typeeq(v1, v2):
4444
decimal_no decimal(38,2),
4545
decimal_no2 decimal(38,10),
4646
numeric_no numeric(38,8),
47-
stamp_time timestamp,
47+
stamp_timestamp timestamp,
4848
uuid uniqueidentifier
4949
)
5050
"""

0 commit comments

Comments
 (0)