[DB-SIG] ctsybasemodule problem and dbi question

Cameron Mellor Cameron Mellor" <cameron@easynet.co.uk
Thu, 25 Feb 1999 12:00:03 -0000


Background:

I'm toying with Sybase, Python, and ctsybasemodule, and looking at the idea
of writing some date- and calendar*-related functions using dbiDates as my
"standard" dates. Unfortunately, I'm having problems with arithmetic
operations:

  [cameron@localhost ~]$ python
  Python 1.5.1 (#16, Feb 12 1999, 20:22:16)  [GCC 2.7.2.3] on
  linux2
  Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
  >>> import ctsybase, dbi, time
  >>> d = dbi.dbiDate(time.time())
  >>> d.value
  919939624.244
  >>> d + 86400   # fails
  919939624.244
  >>> 86400 + d   # also fails
  135310552

But wait, there's more!:

  >>> d * 2
  Segmentation fault (core dumped)

Eek! OK, what happened?

  [cameron@localhost ~]$ gdb python core
[... startup; some reformatting ...]
  (gdb) where
  #0  0x0 in ?? ()
  #1  0x80630dd in PyNumber_Multiply (v=0x80d13a0, w=0x80f4a88)
  at abstract.c:372
  #2  0x8075ac8 in eval_code2 (co=0x80f5f80, globals=0x80c27b8,
  locals=0x80c27b8, args=0x0, argcount=0, kws=0x0, kwcount=0,
[... rest of the stack ...]
  (gdb) up
  #1  0x80630dd in PyNumber_Multiply (v=0x80d13a0, w=0x80f4a88)
  at abstract.c:372
  372                     x = (*v->ob_type->tp_as_number->
  nb_multiply)(v, w);
  (gdb) print v->ob_type->tp_as_number->nb_multiply
  $5 = (PyObject *(*)()) 0

Hmmmm. That would probably do it.

Being somewhat new to Python, and especially the Python C API, I'm not
really sure where to go to find the problem. Any ideas? Should I just go
a-steppin' through PyNumber_Coerce and the rest?

On a related note, ctsybase doesn't actually seem to be returning dbiDates:
if I do a "select getdate()", I get [[[<int>]]]. That's fine(-ish) for
smalldatetimes, but I was expecting at least a [[[<float>]]], or better yet,
[[[<dbiDate>]]]. Is this correct or have I misunderstood DBI completely?

(Caveat: this might not be quite right since I have to mail from Windows and
can't try this stuff out as I go. Apologies for errors.)

On another related note, is anyone thinking about standardising the DBI
helper implementations? I've got both ctsybasemodule and DCOracle (tho' it's
not much use to me :-/) and the implementations are different (umm, C vs.
Python). Is there some fundamental problem with providing a single version
and having the DB module translate native format to DBI-standard format? Or
is it just inertia? :-)

Any help appreciated!

TIA,


Cam

* Not Mayan calendars or anything like that. Just standard "three working
days"-type calculations, with a "little language" (hmmm, maybe Python) for
defining holidays, weekends, etc. A little something to keep me busy for a
while ...