Skip to content
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

rusqlite::Connection::execute successfully accepts multiple statements but only the first one is actually executed #397

Open
frp opened this issue Sep 9, 2018 · 7 comments

Comments

@frp
Copy link

frp commented Sep 9, 2018

This reproduces with the following code:

let conn = ::rusqlite::Connection::open_in_memory().unwrap();
conn.execute(r#"
    CREATE TABLE t1 ( id integer primary key, f1 text );
    CREATE TABLE t2 ( id integer primary key, f1 text );
"#, &[]).unwrap();
conn.execute("SELECT * FROM t2;", &[]).unwrap();

The first execute succeeds, and the table t1 is created and is accessible. However, the table t2 is not, meaning the second statement was actually never executed. So the second execute fails with SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("no such table: t2"))

The correct outcome would be to either execute both statements or return an error when asked to do so.

@gwenn
Copy link
Collaborator

gwenn commented Sep 9, 2018

Right now, you should use execute_batch.
https://docs.rs/rusqlite/0.14.0/rusqlite/struct.Connection.html#method.execute

Convenience method to prepare and execute a single SQL statement.

But execute can be fixed by checking the prepared statement tail.
We will have to decide if we fail or not.

gwenn added a commit to gwenn/rusqlite that referenced this issue Sep 9, 2018
Connection.execute
Connection.execute_named
Connection.quer_row
Connection.quer_row_named
@gwenn
Copy link
Collaborator

gwenn commented Sep 9, 2018

Could you please give this https://github.com/jgallagher/rusqlite/pull/399 PR a try ?

@gwenn
Copy link
Collaborator

gwenn commented Sep 15, 2018

@frp Would you mind replying ?

@frp
Copy link
Author

frp commented Sep 16, 2018

Sorry, was busy. Tried, this produces error if I pass multiple statements, as expected. Thanks.
Also thanks for the hint to use execute_batch().

gwenn added a commit to gwenn/rusqlite that referenced this issue Oct 28, 2018
Connection.execute
Connection.execute_named
Connection.quer_row
Connection.quer_row_named
gwenn added a commit that referenced this issue Aug 31, 2019
Check that only one statement is provided (#397)
@gwenn
Copy link
Collaborator

gwenn commented Dec 13, 2019

Partially fixed in 0.21

@xmo-odoo
Copy link

xmo-odoo commented May 25, 2022

I've hit a similar issue trying to create a database in an execute then getting quite flummoxed when I couldn't find my tables, had no errors and it worked fine in sqlite itself.

Maybe a warning box in the documentation of execute (and possibly prepare as well) would be a good idea, at least until this is fixed for good?

Also I didn't get any error, despite being on 0.27.0, is there a feature to enable or something?

@gwenn
Copy link
Collaborator

gwenn commented May 25, 2022

had no errors

https://github.com/rusqlite/rusqlite/blob/master/src/statement.rs#L859-L874
If you don't use the extra_check feature, you should expect no error...

it worked fine in sqlite itself

There is no such method (like execute) in SQLite ! sqlite3_exec does not return the number of rows that were changed or inserted or deleted...

Maybe a warning box in the documentation

https://docs.rs/rusqlite/latest/rusqlite/struct.Connection.html#method.execute
"Convenience method to prepare and execute a single SQL statement."

and possibly prepare as well

Are you really sure ?

@thomcc thomcc changed the title ruqalite::Connection::execute successfully accepts multiple statements but only the first one is actually executed rusqlite::Connection::execute successfully accepts multiple statements but only the first one is actually executed Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants