Commits

Anonymous committed 63423c1

Now maps returned values into Python types; bigint, decimal and date(time)

  • Participants
  • Parent commits 7af675e

Comments (0)

Files changed (2)

File dbapi/dbapi/generic.py

 # 2010-12-31 clach04 Added preliminary Cursor.callproc() support for database procedures. Does not support parameters, or results (return codes, rows, etc.)
 # 2010-12-31 clach04 Added input parameters support to Cursor.callproc().
 # 2010-12-31 clach04 Added input/output parameters support to Cursor.callproc().
+# 2011-01-04 clach04 Map returned .NET (DBMS) types into Python types; date(time), decimal, bigint
 
 import clr
 clr.AddReference('System.Data')
             #result = (,)  # IronPython 2.6 seems to have problems with empty Tuples
             result = []  # IronPython 2.6 seems to have problems with empty Tuples
             for x in command.Parameters:
-                result.append(x.Value)
+                result.append(_to_python(x.Value))
             result = tuple(result)
         
         self.description = None
         schema = self.reader.GetSchemaTable()
         self.description = map(_schema_row_to_tuple, schema.Rows)
 
-    def _dbnull_to_none(self, x):
-        if x == DBNull.Value: return None
-        else: return x
-
     def _row_to_tuple(self):
         reader = self.reader
         values = Array.CreateInstance(Object, reader.FieldCount)
         reader.GetValues(values)
-        return tuple(self._dbnull_to_none(x) for x in values)
+        return tuple(_to_python(x) for x in values)
 
     def fetchone(self):
         '''Fetch a single row from the cursor'''
 
 _to_python_mappings = {
     System.DateTime: datetime.datetime,
-    System.Int64: long
+    System.Int64: long,
+    System.Decimal: lambda d: decimal.Decimal(str(d)),
 }
 
 def _add_to_python_mapping(t, f):
     _to_python_mappings[t] = f
 
 def _to_python(nval):
-    if type(nval) in _to_python_mappings:
+    if nval == DBNull.Value:
+        return None
+    elif type(nval) in _to_python_mappings:
         return _to_python_mappings[type(nval)](nval)
     else:
         return nval

File dbapi/demo_ingres_dbproc.py

 dbproc_result = c.callproc(dbproc_name, bind_params)
 print 'dbproc_result ', dbproc_result 
 
+sql_query = "insert into tbl_test_dbp (col1) values (NULL)"
+print sql_query
+c.execute(sql_query)
+
 simple_select(c, 'select * from tbl_test_dbp')