Documentation bug. Detecting NULL extension arguments.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Documentation bug. Detecting NULL extension arguments.

petern
Is this the recommended way for any argument type?

  zCol = (const char*)sqlite3_value_text(argv[i]);
  if( 0==zCol ) return;

Docs say protected_sqlite3_value can represent NULL but how is not
explained anywhere.

https://www.sqlite.org/c3ref/value_blob.html
https://www.sqlite.org/c3ref/value.html

To detect NULL arguments is it normal to test with sqlite3_value_text on
every type of argument including BLOB, double, int,..?   Or, are there some
special sentinel values {MAX_INT,DBL_MAX,...} for those other types?

I'd be happily corrected if wrong, but it seems C API NULL value
representation is not explained anywhere in the SQLite docs. The short
answer to this question would make a well needed addition to one of those
doc pages.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Documentation bug. Detecting NULL extension arguments.

Richard Hipp-3
On 6/30/17, petern <[hidden email]> wrote:
> Is this the recommended way for any argument type?
>
>   zCol = (const char*)sqlite3_value_text(argv[i]);
>   if( 0==zCol ) return;

No.  What you have above detects out-of-memory errors when trying to
convert an argument in some non-TEXT type in to TEXT, or when
converting a UTF-16 text string into the requested UTF-8.

To get the argument type, use:

   sqlite3_value_type(argv[i])


>
> Docs say protected_sqlite3_value can represent NULL but how is not
> explained anywhere.
>
> https://www.sqlite.org/c3ref/value_blob.html
> https://www.sqlite.org/c3ref/value.html
>
> To detect NULL arguments is it normal to test with sqlite3_value_text on
> every type of argument including BLOB, double, int,..?   Or, are there some
> special sentinel values {MAX_INT,DBL_MAX,...} for those other types?
>
> I'd be happily corrected if wrong, but it seems C API NULL value
> representation is not explained anywhere in the SQLite docs. The short
> answer to this question would make a well needed addition to one of those
> doc pages.
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Documentation bug. Detecting NULL extension arguments.

petern
Thank you for the quick reply.

After reading your reply and grepping around for more examples containing
sqlite3_type_value I see now the documentation gives the impression that
return types only apply to  sqlite3_value_numeric_type().   Had I clicked
randomly on the link to https://sqlite.org/c3ref/c_blob.html in that
unrelated paragraph I would have seen this wonderful exhibit:

#define SQLITE_INTEGER  1
#define SQLITE_FLOAT    2
#define SQLITE_BLOB     4
#define SQLITE_NULL     5
#ifdef SQLITE_TEXT
# undef SQLITE_TEXT
#else
# define SQLITE_TEXT     3
#endif
#define SQLITE3_TEXT     3


sqlite3_value_type() definitely deserves at least one document sentence
within https://sqlite.org/c3ref/value_blob.html containing the link to
https://sqlite.org/c3ref/c_blob.html



On Fri, Jun 30, 2017 at 10:26 AM, Richard Hipp <[hidden email]> wrote:

> On 6/30/17, petern <[hidden email]> wrote:
> > Is this the recommended way for any argument type?
> >
> >   zCol = (const char*)sqlite3_value_text(argv[i]);
> >   if( 0==zCol ) return;
>
> No.  What you have above detects out-of-memory errors when trying to
> convert an argument in some non-TEXT type in to TEXT, or when
> converting a UTF-16 text string into the requested UTF-8.
>
> To get the argument type, use:
>
>    sqlite3_value_type(argv[i])
>
>
> >
> > Docs say protected_sqlite3_value can represent NULL but how is not
> > explained anywhere.
> >
> > https://www.sqlite.org/c3ref/value_blob.html
> > https://www.sqlite.org/c3ref/value.html
> >
> > To detect NULL arguments is it normal to test with sqlite3_value_text on
> > every type of argument including BLOB, double, int,..?   Or, are there
> some
> > special sentinel values {MAX_INT,DBL_MAX,...} for those other types?
> >
> > I'd be happily corrected if wrong, but it seems C API NULL value
> > representation is not explained anywhere in the SQLite docs. The short
> > answer to this question would make a well needed addition to one of those
> > doc pages.
> > _______________________________________________
> > sqlite-users mailing list
> > [hidden email]
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
>
>
> --
> D. Richard Hipp
> [hidden email]
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Documentation bug. Detecting NULL extension arguments.

Richard Hipp-3
On 6/30/17, petern <[hidden email]> wrote:
> sqlite3_value_type() definitely deserves at least one document sentence

The change at https://www.sqlite.org/src/info/0db20efe201736b3 will
appear in the next release.


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...