|
From: Christian S. <cm...@ce...> - 2004-07-29 12:42:07
|
Hello. I belive this is a short comming of the libdbi-drivers as it looks today. By reading dbi-dev.h you will find this row part of dbi_row_t struct.: unsigned long long *field_sizes; /* NULL field = 0, string field = len, anything else = -1 */ But the drivers does not implemet it this way. I'll suggest that we change it so that: NULL field = -1, string field = len, anything else = 0 That way we will have distinction between NULL and a string of 0 chars (which is not the same as NULL). It would then be easy to implement a couple of funtions like: dbi_result_field_isnull(result, "fieldname"); or dbi_result_field_isnull_idx(result, 2); Regards, //Christian On Wednesday 28 July 2004 15.45, m.e...@ls... wrote: > Hi, > > I have been running some queries that return NULLs at times (in fields > that contain doubles). > > It looks as if you use dbi_result_get_double() you get 0 whenever the > query returned a NULL. > > How can I distinguish between a NULL and 0? It looks like I might have > missed something obvious here... > > Thanks, > > Max > > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click > _______________________________________________ > libdbi-users mailing list > lib...@li... > https://lists.sourceforge.net/lists/listinfo/libdbi-users |
|
From: Christian S. <chr...@ce...> - 2004-07-29 17:43:24
|
Hello again, Guess you are using the function dbi_result_get_field_length( ) which today return size-1 for some reason. You could use: dbi_result_get_field_size( ) which returns the accual value. But I guess these functions would need to be tweaked to fit in with this new behaviour. The right (clean) way of doing things would be to implement dbi_result_field_isnull() or simular to check if a field is null. That way we could change the internals of libdbi without changing all applications that was hacked to check if size was -1. It will also make it more obvious what happens. Regards, //Christian On Thursday 29 July 2004 15.14, m.e...@ls... wrote: > Thanks Christian! I didn't even think of looking at the length... > > I only have pqsql, but it looks as if for this one at least the length > is always 0 except for strings, where it is equal to the length of the > string (as you say it does not seem to implement what's in the comment). > > I tried implementing your suggestion myself in dbd_pgsql.c, and got as > far as > > 512a513 > > > row->field_sizes[curfield] = -1; > > Unfortunately, now I get a length of -2 for NULLs??? > > Maybe someone familiar with the driver could have a look at this? It > would be neat to be able to distinguish between NULL, "" and 0... > > Max > > On Thu, 2004-07-29 at 12:41, Christian Stamgren wrote: > > Hello. > > > > I belive this is a short comming of the libdbi-drivers as it looks today. > > > > By reading dbi-dev.h you will find this row part of dbi_row_t struct.: > > > > unsigned long long *field_sizes; /* NULL field = 0, string field = len, > > anything else = -1 */ > > > > But the drivers does not implemet it this way. > > > > > > I'll suggest that we change it so that: > > NULL field = -1, string field = len, anything else = 0 > > > > That way we will have distinction between NULL and a string of 0 chars > > (which is not the same as NULL). > > > > It would then be easy to implement a couple of funtions like: > > > > dbi_result_field_isnull(result, "fieldname"); > > or > > dbi_result_field_isnull_idx(result, 2); > > > > > > > > Regards, > > > > //Christian > > > > On Wednesday 28 July 2004 15.45, m.e...@ls... wrote: > > > Hi, > > > > > > I have been running some queries that return NULLs at times (in fields > > > that contain doubles). > > > > > > It looks as if you use dbi_result_get_double() you get 0 whenever the > > > query returned a NULL. > > > > > > How can I distinguish between a NULL and 0? It looks like I might have > > > missed something obvious here... > > > > > > Thanks, > > > > > > Max > > > > > > > > > ------------------------------------------------------- > > > This SF.Net email is sponsored by BEA Weblogic Workshop > > > FREE Java Enterprise J2EE developer tools! > > > Get your free copy of BEA WebLogic Workshop 8.1 today. > > > http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click > > > _______________________________________________ > > > libdbi-users mailing list > > > lib...@li... > > > https://lists.sourceforge.net/lists/listinfo/libdbi-users |
|
From: <m.e...@ls...> - 2004-07-30 08:53:19
Attachments:
dbi_result.c.patch
dbd_pgsql.c.patch
|
Like this? This seems to work for me, but I find it vaguely troubling
that the field size, which is an unsigned long long, is meant to be
negative...
dbd_pgsql.c.patch:
512a513
> row->field_sizes[curfield] = -1;
dbi_result.c.patch:
334a335,344
> unsigned short dbi_result_isnull(dbi_result Result, const char*
fieldname) {
> unsigned long long size = dbi_result_get_field_size(Result,
fieldname);
> return (size == -1) ? 1 : 0;
> }
>
> unsigned short dbi_result_isnull_idx(dbi_result Result, unsigned short
idx) {
> unsigned long long size = dbi_result_get_field_size_idx(Result,
idx);
> return (size == -1) ? 1 : 0;
> }
>
On Thu, 2004-07-29 at 17:43, Christian Stamgren wrote:
> Hello again,
>
> Guess you are using the function
> dbi_result_get_field_length( ) which today return size-1 for some reason.
>
> You could use:
> dbi_result_get_field_size( ) which returns the accual value.
>
> But I guess these functions would need to be tweaked to fit in with this new
> behaviour.
> The right (clean) way of doing things would be to implement
> dbi_result_field_isnull() or simular to check if a field is null.
> That way we could change the internals of libdbi without changing all
> applications that was hacked to check if size was -1. It will also make it
> more obvious what happens.
>
> Regards,
>
> //Christian
>
>
> On Thursday 29 July 2004 15.14, m.e...@ls... wrote:
> > Thanks Christian! I didn't even think of looking at the length...
> >
> > I only have pqsql, but it looks as if for this one at least the length
> > is always 0 except for strings, where it is equal to the length of the
> > string (as you say it does not seem to implement what's in the comment).
> >
> > I tried implementing your suggestion myself in dbd_pgsql.c, and got as
> > far as
> >
> > 512a513
> >
> > > row->field_sizes[curfield] = -1;
> >
> > Unfortunately, now I get a length of -2 for NULLs???
> >
> > Maybe someone familiar with the driver could have a look at this? It
> > would be neat to be able to distinguish between NULL, "" and 0...
> >
> > Max
> >
> > On Thu, 2004-07-29 at 12:41, Christian Stamgren wrote:
> > > Hello.
> > >
> > > I belive this is a short comming of the libdbi-drivers as it looks today.
> > >
> > > By reading dbi-dev.h you will find this row part of dbi_row_t struct.:
> > >
> > > unsigned long long *field_sizes; /* NULL field = 0, string field = len,
> > > anything else = -1 */
> > >
> > > But the drivers does not implemet it this way.
> > >
> > >
> > > I'll suggest that we change it so that:
> > > NULL field = -1, string field = len, anything else = 0
> > >
> > > That way we will have distinction between NULL and a string of 0 chars
> > > (which is not the same as NULL).
> > >
> > > It would then be easy to implement a couple of funtions like:
> > >
> > > dbi_result_field_isnull(result, "fieldname");
> > > or
> > > dbi_result_field_isnull_idx(result, 2);
> > >
> > >
> > >
> > > Regards,
> > >
> > > //Christian
> > >
> > > On Wednesday 28 July 2004 15.45, m.e...@ls... wrote:
> > > > Hi,
> > > >
> > > > I have been running some queries that return NULLs at times (in fields
> > > > that contain doubles).
> > > >
> > > > It looks as if you use dbi_result_get_double() you get 0 whenever the
> > > > query returned a NULL.
> > > >
> > > > How can I distinguish between a NULL and 0? It looks like I might have
> > > > missed something obvious here...
> > > >
> > > > Thanks,
> > > >
> > > > Max
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > This SF.Net email is sponsored by BEA Weblogic Workshop
> > > > FREE Java Enterprise J2EE developer tools!
> > > > Get your free copy of BEA WebLogic Workshop 8.1 today.
> > > > http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
> > > > _______________________________________________
> > > > libdbi-users mailing list
> > > > lib...@li...
> > > > https://lists.sourceforge.net/lists/listinfo/libdbi-users
>
|
|
From: Christian S. <chr...@ce...> - 2004-07-30 10:40:14
|
Hmm yes, it was something like that I haved in mind ....
But you are right. The unsigned'ness doesn't make this idea kosher. I didn't
see that coming, my bad.
I guess it was when the unsigned'ness of field_sizes got in, the problem
with distinguish NULL fields got to the surface.
The right way to fix this problem might accually be to add an extra variable
in dbi_row_t. And use that in dbi_result_field_isnull() to track down if a
field is null or not.
That variable could be make into a bitfield in case there is some more
meta-data that could be added to a column in the future. The drivers could
then bitwise adding on values define in libdbi. say DBI_FIELD_ISNULL and
more....
regards,
//Christian
On Friday 30 July 2004 11.52, m.e...@ls... wrote:
> Like this? This seems to work for me, but I find it vaguely troubling
> that the field size, which is an unsigned long long, is meant to be
> negative...
>
> dbd_pgsql.c.patch:
> 512a513
>
> > row->field_sizes[curfield] = -1;
>
> dbi_result.c.patch:
> 334a335,344
>
> > unsigned short dbi_result_isnull(dbi_result Result, const char*
>
> fieldname) {
>
> > unsigned long long size = dbi_result_get_field_size(Result,
>
> fieldname);
>
> > return (size == -1) ? 1 : 0;
> > }
> >
> > unsigned short dbi_result_isnull_idx(dbi_result Result, unsigned short
>
> idx) {
>
> > unsigned long long size = dbi_result_get_field_size_idx(Result,
>
> idx);
>
> > return (size == -1) ? 1 : 0;
> > }
>
> On Thu, 2004-07-29 at 17:43, Christian Stamgren wrote:
> > Hello again,
> >
> > Guess you are using the function
> > dbi_result_get_field_length( ) which today return size-1 for some
> > reason.
> >
> > You could use:
> > dbi_result_get_field_size( ) which returns the accual value.
> >
> > But I guess these functions would need to be tweaked to fit in with this
> > new behaviour.
> > The right (clean) way of doing things would be to implement
> > dbi_result_field_isnull() or simular to check if a field is null.
> > That way we could change the internals of libdbi without changing all
> > applications that was hacked to check if size was -1. It will also make
> > it more obvious what happens.
> >
> > Regards,
> >
> > //Christian
> >
> > On Thursday 29 July 2004 15.14, m.e...@ls... wrote:
> > > Thanks Christian! I didn't even think of looking at the length...
> > >
> > > I only have pqsql, but it looks as if for this one at least the length
> > > is always 0 except for strings, where it is equal to the length of the
> > > string (as you say it does not seem to implement what's in the
> > > comment).
> > >
> > > I tried implementing your suggestion myself in dbd_pgsql.c, and got as
> > > far as
> > >
> > > 512a513
> > >
> > > > row->field_sizes[curfield] = -1;
> > >
> > > Unfortunately, now I get a length of -2 for NULLs???
> > >
> > > Maybe someone familiar with the driver could have a look at this? It
> > > would be neat to be able to distinguish between NULL, "" and 0...
> > >
> > > Max
> > >
> > > On Thu, 2004-07-29 at 12:41, Christian Stamgren wrote:
> > > > Hello.
> > > >
> > > > I belive this is a short comming of the libdbi-drivers as it looks
> > > > today.
> > > >
> > > > By reading dbi-dev.h you will find this row part of dbi_row_t
> > > > struct.:
> > > >
> > > > unsigned long long *field_sizes; /* NULL field = 0, string field =
> > > > len, anything else = -1 */
> > > >
> > > > But the drivers does not implemet it this way.
> > > >
> > > >
> > > > I'll suggest that we change it so that:
> > > > NULL field = -1, string field = len, anything else = 0
> > > >
> > > > That way we will have distinction between NULL and a string of 0
> > > > chars (which is not the same as NULL).
> > > >
> > > > It would then be easy to implement a couple of funtions like:
> > > >
> > > > dbi_result_field_isnull(result, "fieldname");
> > > > or
> > > > dbi_result_field_isnull_idx(result, 2);
> > > >
> > > >
> > > >
> > > > Regards,
> > > >
> > > > //Christian
> > > >
> > > > On Wednesday 28 July 2004 15.45, m.e...@ls... wrote:
> > > > > Hi,
> > > > >
> > > > > I have been running some queries that return NULLs at times (in
> > > > > fields that contain doubles).
> > > > >
> > > > > It looks as if you use dbi_result_get_double() you get 0 whenever
> > > > > the query returned a NULL.
> > > > >
> > > > > How can I distinguish between a NULL and 0? It looks like I might
> > > > > have missed something obvious here...
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Max
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > This SF.Net email is sponsored by BEA Weblogic Workshop
> > > > > FREE Java Enterprise J2EE developer tools!
> > > > > Get your free copy of BEA WebLogic Workshop 8.1 today.
> > > > > http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
> > > > > _______________________________________________
> > > > > libdbi-users mailing list
> > > > > lib...@li...
> > > > > https://lists.sourceforge.net/lists/listinfo/libdbi-users
|
|
From: Christian S. <cm...@ce...> - 2004-07-30 14:11:04
|
Hi list, I have beem fiddling with some code to make handling of NULL values correct. I have created a flags variable inside dbi_row_t struct that is a bitfield that can be used for other meta-data as well, if we find something in the future ..... I'm attaching patches for libdbi: I also attach a patch with a fix for my firebird driver as a reference case. tgt.c is a test program to test that the patch creates the wanted behaviour. If this is something that the libdbi project managers like, could someone please apply this patch agains libdbi cvs so that we can start the update of the libdbi-drivers. All the best, //Christian |
|
From: Christian S. <chr...@ce...> - 2004-07-30 17:55:34
Attachments:
libdbi2.diff
|
Hmm, Hmm, There was an error with my previous patch, I forgot to free the newly created flags variable. Attached is a new patch which also free'es the allocated memory.... Sorry about that, //Christian On Friday 30 July 2004 16.10, Christian Stamgren wrote: > Hi list, > > I have beem fiddling with some code to make handling of NULL values > correct. I have created a flags variable inside dbi_row_t struct that is a > bitfield that can be used for other meta-data as well, if we find something > in the future ..... > > I'm attaching patches for libdbi: > I also attach a patch with a fix for my firebird driver as a reference > case. tgt.c is a test program to test that the patch creates the wanted > behaviour. > > > If this is something that the libdbi project managers like, could someone > please apply this patch agains libdbi cvs so that we can start the update > of the libdbi-drivers. > > > > All the best, > > //Christian |
|
From: <m.e...@ls...> - 2004-07-29 13:33:33
|
Thanks Christian! I didn't even think of looking at the length... I only have pqsql, but it looks as if for this one at least the length is always 0 except for strings, where it is equal to the length of the string (as you say it does not seem to implement what's in the comment). I tried implementing your suggestion myself in dbd_pgsql.c, and got as far as 512a513 > row->field_sizes[curfield] = -1; Unfortunately, now I get a length of -2 for NULLs??? Maybe someone familiar with the driver could have a look at this? It would be neat to be able to distinguish between NULL, "" and 0... Max On Thu, 2004-07-29 at 12:41, Christian Stamgren wrote: > Hello. > > I belive this is a short comming of the libdbi-drivers as it looks today. > > By reading dbi-dev.h you will find this row part of dbi_row_t struct.: > > unsigned long long *field_sizes; /* NULL field = 0, string field = len, > anything else = -1 */ > > But the drivers does not implemet it this way. > > > I'll suggest that we change it so that: > NULL field = -1, string field = len, anything else = 0 > > That way we will have distinction between NULL and a string of 0 chars (which > is not the same as NULL). > > It would then be easy to implement a couple of funtions like: > > dbi_result_field_isnull(result, "fieldname"); > or > dbi_result_field_isnull_idx(result, 2); > > > > Regards, > > //Christian > > > > On Wednesday 28 July 2004 15.45, m.e...@ls... wrote: > > Hi, > > > > I have been running some queries that return NULLs at times (in fields > > that contain doubles). > > > > It looks as if you use dbi_result_get_double() you get 0 whenever the > > query returned a NULL. > > > > How can I distinguish between a NULL and 0? It looks like I might have > > missed something obvious here... > > > > Thanks, > > > > Max > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by BEA Weblogic Workshop > > FREE Java Enterprise J2EE developer tools! > > Get your free copy of BEA WebLogic Workshop 8.1 today. > > http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click > > _______________________________________________ > > libdbi-users mailing list > > lib...@li... > > https://lists.sourceforge.net/lists/listinfo/libdbi-users > |