Location of error in SQL statements ?

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

Location of error in SQL statements ?

Eric Grange-3
Hi,

Is there are way to get more information about an SQL syntax error message ?
For example on a largish SQL query I got the following error message

        near "on": syntax error

but as the query is basically a long list of joins, this is not too helpful
;)

Having a character offset, a line number or a larger code snippet would be
enough.

Best regards,
Eric
_______________________________________________
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: Location of error in SQL statements ?

Rowan Worth-2
On Tue, 7 May 2019 at 16:00, Eric Grange <[hidden email]> wrote:

> Is there are way to get more information about an SQL syntax error message
> ?
> For example on a largish SQL query I got the following error message
>
>         near "on": syntax error
>
> but as the query is basically a long list of joins, this is not too helpful
> ;)
>

It's not clear from the docs whether this is guaranteed, but a quick look
at the code suggests that the pzTail argument (if provided to
sqlite3_prepare_v2) is also updated when there's a parse error. You might
be able to rely on that to infer how far through the statement the problem
lies.

-Rowan
_______________________________________________
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: Location of error in SQL statements ?

curmudgeon
I think pzTail just points to the trailing ‘/0’ of zSql if an error occurs.



________________________________
From: sqlite-users <[hidden email]> on behalf of Rowan Worth <[hidden email]>
Sent: Tuesday, May 7, 2019 9:07:34 AM
To: SQLite mailing list
Subject: Re: [sqlite] Location of error in SQL statements ?

On Tue, 7 May 2019 at 16:00, Eric Grange <[hidden email]> wrote:

> Is there are way to get more information about an SQL syntax error message
> ?
> For example on a largish SQL query I got the following error message
>
>         near "on": syntax error
>
> but as the query is basically a long list of joins, this is not too helpful
> ;)
>

It's not clear from the docs whether this is guaranteed, but a quick look
at the code suggests that the pzTail argument (if provided to
sqlite3_prepare_v2) is also updated when there's a parse error. You might
be able to rely on that to infer how far through the statement the problem
lies.

-Rowan
_______________________________________________
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