-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is this a bug in the database/sql layer? Panic on Exec of empty string #963
Comments
It panics when attempting to get the last insert ID, because a private variable in the SQL layer is still |
This is a similar issue to #950. This library currently makes the (unsafe) assumption that the loop in Lines 830 to 832 in d33341f
Note that this is possible for any query that does nothing, not just the empty string. For example, you'd get similar results with Clearly it should not panic. However, the question is, what exactly should this do instead? Should it return an error? Should it return some vacuous |
Thanks for the info. Looking at the function signature -- and trying to keep breaking changes to a minimum -- I would like a &SQLiteResult{
id: 0,
changes:0,
} It seems the most reasonable option to me. I hacked up my local copy of your driver, and my system no longer panics when returning such a result. For Query, I suggest an non-nil object, where Alternatively some sort of function, a bit like Readonly which would allow me to check a statement before I pass it to the sql/database layer, but that could be a perf hit for big statements? I wouldn't like this, but might consider it. More info: I hit this issue quite a while ago, but coded around it somewhat. Moving to the I cope with one case by simply checking for empty queries. But you tell me any query that does nothing could cause this -- so the space of possible queries is very large! I can't check them all. I'm surprised no-one hit this yet. For rqlite I would be fine with the system doing nothing. In other just returning an empty response to the user -- perhaps HTTP 204 to be pedanctic. What I don't want is the panic! Basically a query that does nothing crashes rqlite. :-( |
My hack: if tail == "" {
if res == nil {
res = &SQLiteResult{
id: 0,
changes:0,
}
}
return res, nil
} |
I'm thinking it might be best to have both |
Error works for me too -- I just don't want the code to panic. No one really wants to run meaningless queries, but a crashing system makes it difficult for them to understand what has happened. An error makes it much clearer. |
I'm going to patch my own fork for now, until upstream fixes.. |
Passing an empty to a string causes a panic in the database/sql layer. Is there some initialization I'm missing? I see nothing in the docs that state this should panic.
The text was updated successfully, but these errors were encountered: