From: Skip M. <sk...@po...> - 2004-05-28 12:34:52
|
I'm trying to get the Object Craft Sybase module used at work instead of a homegrown hack. Based upon a lot of use of the homegrown module, one requirement is that dates be represented as floating point seconds since the Unix epoch. It appears that Sybase returns some sort of DateTime object. Given a DateTime object, d, both int(d) and float(d) fail for me with this sort of message: >>> float(d) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/titan/skipm/local/lib/python2.3/site-packages/Sybase.py", line 154, in _cslib_cb raise Error(_fmt_client(msg)) Error: Layer: 2, Origin: 1 cs_convert: cslib user api layer: external error: Conversion between 12 and 10 datatypes is not supported. Can I cleanly get from a DateTime object to a float or do I have to inject a new version of _column_value() into Sybase.py? ('Twould be nice if there was a standard way to establish type converters on a per-connection basis.) Thanks, -- Skip Montanaro Got gigs? http://www.musi-cal.com/submit.html Got spam? http://www.spambayes.org/ sk...@po... |
From: Dave C. <dj...@ob...> - 2004-05-28 18:19:40
|
Skip Montanaro wrote: >I'm trying to get the Object Craft Sybase module used at work instead of a >homegrown hack. Based upon a lot of use of the homegrown module, one >requirement is that dates be represented as floating point seconds since the >Unix epoch. It appears that Sybase returns some sort of DateTime object. >Given a DateTime object, d, both int(d) and float(d) fail for me with this >sort of message: > > >>> float(d) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "/home/titan/skipm/local/lib/python2.3/site-packages/Sybase.py", line 154, in _cslib_cb > raise Error(_fmt_client(msg)) > Error: Layer: 2, Origin: 1 > cs_convert: cslib user api layer: external error: Conversion between 12 and 10 datatypes is not supported. > >Can I cleanly get from a DateTime object to a float or do I have to inject a >new version of _column_value() into Sybase.py? ('Twould be nice if there >was a standard way to establish type converters on a per-connection basis.) > > That is strange. Looking into the Sybase include files this seems to be saying that it will not convert from CS_DATETIME_TYPE to CS_FLOAT_TYPE. I am fairly sure that this should work. What version of the Sybase client libraries are you using? - Dave -- http://www.object-craft.com.au |
From: Skip M. <sk...@po...> - 2004-05-29 06:59:55
Attachments:
Sybase.py.diff
|
>> I'm trying to get the Object Craft Sybase module used at work instead >> of a homegrown hack. Based upon a lot of use of the homegrown >> module, one requirement is that dates be represented as floating >> point seconds since the Unix epoch. It appears that Sybase returns >> some sort of DateTime object.... >> Can I cleanly get from a DateTime object to a float or do I have to >> inject a new version of _column_value() into Sybase.py? ('Twould be >> nice if there was a standard way to establish type converters on a >> per-connection basis.) ... >> Error: Layer: 2, Origin: 1 >> cs_convert: cslib user api layer: external error: Conversion between 12 and 10 datatypes is not supported. Dave> That is strange. Looking into the Sybase include files this seems Dave> to be saying that it will not convert from CS_DATETIME_TYPE to Dave> CS_FLOAT_TYPE. I am fairly sure that this should work. What Dave> version of the Sybase client libraries are you using? We're using 12.5 I believe. At least SYBASE refers to 12.5: >>> os.environ.get("SYBASE") '/opt/sybase-12.5' Our current environment is a bit weird though. We're running mostly Solaris on Intel. The most recent update from Sybase included libraries but no include files. (Sybase indicated this was intentional - apparently you're not supposed to be able to write clients which run on Solaris/Intel!) One of the admins copied the include files from the SPARC platform. There were mismatches between the features the include files announced and those the .so files actually implemented, so I wound up writing a Makefile based upon the output of the distutils build and started stripping off -DHAVE_... flags until it would compile, link and import without failure. I'm left with these CPPFLAGS: CPPFLAGS = -fno-strict-aliasing -DNDEBUG -DHAVE_CT_CURSOR \ -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA \ -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP \ -I$(SYBDIR)/include -I$(PYTHONDIR)/include/python2.3 Would any of those -DHAVE... options be related to the error I saw? (Thankfully we are moving toward Linux, so will hopefully get marginally better support from Sybase in the future.) At any rate, I took a first stab yesterday afternoon at adding type converters to Sybase.py. The attached context diff against 0.36 is the current state. It adds an optional converters argument to the Connection() call. If given, it should be a mapping object of some sort which maps a given Sybase type to a converter function. I'm hopeful the only slightly controversial aspect is my inclusion of the standard library's datetime type at the head of the list of possible date/time types and that the notion of type converters per se is uncontroversial. In our environment I'll simply initalize Connection objects in a wrapper library with a converter like this: >>> import Sybase >>> import time >>> def dt_as_float(dt): ... return time.mktime(Sybase._convert_datetime(dt).timetuple()) ... >>> db = Sybase.Connection(..., converters={ ... Sybase.DateTimeType: dt_as_float}) >>> c = db.cursor() >>> c.execute("""select date from ... where ...""") >>> c.fetchone() (919317600.0,) Skip |