Commits

clach04  committed 394c687

Added decimal bind parameter support.

  • Participants
  • Parent commits 3aa2036

Comments (0)

Files changed (2)

File dbapi/dbapi/generic.py

 # 2006-09-18 mark    Explicitly set .Transaction attribute
 # 2006-09-19 orichter Iterable cursor
 # 2007-10-11 carsten Added DBNull handling
-# 2009-12-09 clach04 Added date support (date only, not just datetime)
+# 2009-12-09 clach04 Added date support; date only, not just datetime (for input bind parameters)
+# 2010-12-31 clach04 Added decimal support (for input bind parameters)
 
 import clr
 clr.AddReference('System.Data')
 
 import System
 import datetime, time
+import decimal
 
 _from_python_mappings = {
     datetime.datetime: ( (lambda d: System.DateTime.Parse(time.strftime('%Y-%m-%d %H:%M:%S', d.timetuple()))), None),
     datetime.date: ( (lambda d: System.DateTime.Parse(time.strftime('%Y-%m-%d %H:%M:%S', d.timetuple()))), System.Data.DbType.Date),
+    decimal.Decimal: ( (lambda d: System.Decimal.Parse(str(d))), System.Data.DbType.Decimal),
 }
 
 def _add_from_python_mapping(t, f):

File dbapi/demo_ingres.py

 """
 
 import datetime
+from decimal import Decimal
 
 import dbapi
 
 bind_params = (datetime.datetime(2001, 02, 03, 04, 05, 06),)
 simple_select(c, 'select ? from iidbconstants', bind_params)
 
+simple_select(c, 'select decimal(123.45, 30, 4) from iidbconstants')
+
+bind_params = (Decimal('1234567891234567891234567891.234'),)  # SQL type: decimal(31, 3)
+sql_text = "select ? from iidbconstants"
+simple_select(c, sql_text, bind_params)