Invalid Blob Length Error Message

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Invalid Blob Length Error Message

Casey Rodarmor
Hi all,

I wrote an erroneous update statement:

```
UPDATE foo SET bar = x'01234';
```

The error message was:

```
unrecognized token: "x'01234'
```

I know now that the problem was that the blob's length was not a
multiple of two. However, the error message didn't give me an
indication of that. Would it be possible to make the error message
more explicit, to help users debug this error?

Thanks!

Cordially,
Casey Rodarmor
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Invalid Blob Length Error Message

Tim Streater-3
On 17 Aug 2018, at 01:24, Casey Rodarmor <[hidden email]> wrote:

> I wrote an erroneous update statement:
>
> ```
> UPDATE foo SET bar = x'01234';
> ```
>
> The error message was:
>
> ```
> unrecognized token: "x'01234'
> ```
>
> I know now that the problem was that the blob's length was not a
> multiple of two. However, the error message didn't give me an
> indication of that. Would it be possible to make the error message
> more explicit, to help users debug this error?

I expect the error message is correct, and that what you meant to write was:

update foo set bar = 0x1234;


See:

<https://www.sqlite.org/lang_expr.html>

and scroll down to the part about Literal Values (Constants).




--
Cheers  --  Tim
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Invalid Blob Length Error Message

J Decker
On Fri, Aug 17, 2018 at 5:14 AM Tim Streater <[hidden email]> wrote:

> On 17 Aug 2018, at 01:24, Casey Rodarmor <[hidden email]> wrote:
>
> > I wrote an erroneous update statement:
> >
> > ```
> > UPDATE foo SET bar = x'01234';
> > ```
> >
> > The error message was:
> >
> > ```
> > unrecognized token: "x'01234'
> > ```
> >
> > *I know now *that the problem was that the blob's length was not a
> > multiple of two. However, the error message didn't give me an
> > indication of that. Would it be possible to make the error message
> > more explicit, to help users debug this error?
>
> I expect the error message is correct, and that what you meant to write
> was:
>
> while 'correct' it's not meaningful is what the OP meant, I beleive.
something like

bad encoding: "x'01234'

would be much more meaningful(?)


> update foo set bar = 0x1234;
>
>
> See:
>
> <https://www.sqlite.org/lang_expr.html>
>
> and scroll down to the part about Literal Values (Constants).
>
>
>
>
> --
> Cheers  --  Tim
> _______________________________________________
> 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
|

Re: Invalid Blob Length Error Message

Clemens Ladisch
In reply to this post by Casey Rodarmor
Casey Rodarmor wrote:> Hi all,
> unrecognized token: "x'01234'
>
> I know now that the problem was that the blob's length was not a
> multiple of two. However, the error message didn't give me an
> indication of that. Would it be possible to make the error message
> more explicit, to help users debug this error?

Blob literals are parsed in sqlite3GetToken():

    case CC_X: {
#ifndef SQLITE_OMIT_BLOB_LITERAL
      testcase( z[0]=='x' ); testcase( z[0]=='X' );
      if( z[1]=='\'' ){
        *tokenType = TK_BLOB;
        for(i=2; sqlite3Isxdigit(z[i]); i++){}
        if( z[i]!='\'' || i%2 ){
          *tokenType = TK_ILLEGAL;
          while( z[i] && z[i]!='\'' ){ i++; }
        }
        if( z[i] ) i++;
        return i;
      }
#endif

At the moment, this function has no mechanism to return an error message;
the only return value is TK_ILLEGAL (resulting in "unrecognized token").

It would be possible to add another parameter, or to introduce several
different TK_ILLEGAL_xxx codes.  However, blob literals are almost never
written by hand, so I doubt that the additional code and maintenance
effort are deemed worth the effort.


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users