From: <sab...@gm...> - 2006-12-15 11:51:41
|
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=E9bastien Sabl=E9 2006/12/14, Phil Porter <ph...@ph...>: > > 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 !=3D CS_SUCCEED) > + if (status !=3D CS_SUCCEED) { > if (self->debug) > debug_msg(", None\n"); > return Py_BuildValue("iO", status, Py_None); > + } > > fmt =3D datafmt_alloc(&datafmt, 0); > if (fmt =3D=3D 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 =3D [] > try: > while 1 : > status, ofmt =3D self.blk.blk_describe(len(bufs) + 1) > ofmt.count =3D num > bufs.append(DataBuf(ofmt)) > except Sybase.DatabaseError: > pass > self.bufs =3D 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 =3D ((CS_DATAFMTObj*)obj)->fmt; > if (self->fmt.count =3D=3D 0) > self->fmt.count =3D 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 =3D=3D CS_NUMERIC_TYPE > || self->fmt.datatype =3D=3D CS_DECIMAL_TYPE) > self->fmt.maxlength =3D sizeof(CS_NUMERIC); > -#endif > +//#endif > if (allocate_buffers(self) =3D=3D NULL) { > Py_DECREF(self); > return NULL; > > Hope this is of use. > > Regards, > > Phil > > -- > Phil Porter > > |