[python-sybase] Sybase module 0.38pre1 released

Sébastien Sablé sable.sungard at gmail.com
Fri Dec 15 03:51:37 EST 2006


Hi Phil,

thanks for your patch.

I applied your correction to CS_BLKDESC_blk_describe (rev 308).

I will investigate further the other problem your reported.

regards

--
Sébastien Sablé

2006/12/14, Phil Porter <phil at philporter.co.uk>:
>
> Hi,
>
> Thanks very much for taking this over.
>
> Like Paul, I posted a patch a while ago that doesn't seem to have made it
> into 0.38.  Any chance you could add the following fix as well?
>
> It looks like there are some missing braces in the implementation of
> blk_describe.  At the moment it always returns (status, None).  Here is a
> patch:
>
> --- blk.c.old   2006-09-09 15:41:49.520844800 +0100
> +++ blk.c.new   2006-09-09 15:42:56.657382400 +0100
> @@ -86,10 +86,11 @@
>          return NULL;
>      }
>
> -    if (status != CS_SUCCEED)
> +    if (status != CS_SUCCEED) {
>         if (self->debug)
>             debug_msg(", None\n");
>         return Py_BuildValue("iO", status, Py_None);
> +    }
>
>      fmt = datafmt_alloc(&datafmt, 0);
>      if (fmt == NULL) {
>
> Another point is that blk_describe doesn't seem to behave in the way that
> the documentation describes.  The alloc_bufs example given in the docs
> doesn't work because blk_describe raises a DatabaseError if the column
> number is greater than the number of columns in the table (rather than
> returning CS_FAIL).  One solution might be to update the example as
> follows...
>
>    def alloc_bufs(self, num):
>        bufs = []
>        try:
>            while 1 :
>                status, ofmt = self.blk.blk_describe(len(bufs) + 1)
>                ofmt.count = num
>                bufs.append(DataBuf(ofmt))
>        except Sybase.DatabaseError:
>            pass
>        self.bufs = bufs
>
> Finally, we found that blk_describe reports the wrong maxlength for
> numeric types.  We resolved this for our purposes by hacking databuf.c as
> follows but I don't think that this is a good solution.  I think it would
> be better to do something to blk_describe itself instead.
>
> --- databuf.c   2002-12-24 03:23:39.000000000 +0000
> +++ /tmp/databuf.c      2006-09-14 11:43:28.000000000 +0100
> @@ -57,14 +57,15 @@
>         self->fmt = ((CS_DATAFMTObj*)obj)->fmt;
>         if (self->fmt.count == 0)
>             self->fmt.count = 1;
> -#ifdef HAVE_FREETDS
> +//#ifdef HAVE_FREETDS
>         /* Seems like FreeTDS reports the wrong maxlength in
>          * ct_describe() - fix this when binding to a buffer.
>          */
> +    /* Seems like Sybase's blk_describe has the same problem - PCP */
>         if (self->fmt.datatype == CS_NUMERIC_TYPE
>             || self->fmt.datatype == CS_DECIMAL_TYPE)
>             self->fmt.maxlength = sizeof(CS_NUMERIC);
> -#endif
> +//#endif
>         if (allocate_buffers(self) == NULL) {
>             Py_DECREF(self);
>             return NULL;
>
> Hope this is of use.
>
> Regards,
>
> Phil
>
> --
> Phil Porter
>
>


More information about the Python-sybase mailing list