ADODB Currency type broken in Python win32?

Tim Roberts timr at probo.com
Wed Apr 27 02:48:24 EDT 2005


It looks to me like the handling of the currency type in an ADODB
connecction from Python is broken.  Currency data in an Access database is
stored as a 64-bit integer, scaled by 10000.  In an ADODB recordset, this
is returned as a 2-tuple, where the second element is the currency value,
but the value is stored as a normal integer, not a lont integer.  Thus, it
fails for values greater than about $214,700 (2**32 / 10**4).

Here is an example:

  import win32com.client
  conn = win32com.client.Dispatch("ADODB.Connection")
  conn.Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=anydatabase.mdb")
  cmd = win32com.client.Dispatch("ADODB.Command")
  cmd.ActiveConnection = conn
  cmd.CommandText = "SELECT CCur(250000) AS myMoney;"
  rs = cmd.Execute()[0]
  for f in rs.Fields:
    print f.Name
    print f.Type
    print f.Value

One would expect

  myMoney
  6
  (0, 2500000000L)

Instead, we get:

  myMoney
  6
  (0, -1794967296)

The value has wrapped at 2**31.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list