Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.

Cannot execute multi-statement query #47

Open
jonhoo opened this issue Feb 27, 2018 · 4 comments
Open

Cannot execute multi-statement query #47

jonhoo opened this issue Feb 27, 2018 · 4 comments
Milestone

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Feb 27, 2018

It's currently not possible to use simple_exec to execute multiple ;-separated statements. The following code fails with "ExecResult received more than 1 resultset":

let mut lp = Core::new().unwrap();
let conn = "server=tcp:127.0.0.1,1433".to_owned();
let future = tiberius::SqlConnection::connect(lp.handle(), conn.as_str());
let mut c1 = lp.run(future).unwrap();

lp.run(c1.simple_exec("\
     SET NUMERIC_ROUNDABORT OFF; \
     SET ANSI_PADDING, ANSI_WARNINGS ON;")).unwrap();
@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 27, 2018

(this is on master)

jonhoo added a commit to mit-pdos/noria that referenced this issue Feb 27, 2018
@steffengy
Copy link
Owner

Yeah you can do something like simple_exec(...).into_stream().and_then(|f| f).collect() to handle multiple resultsets.

The original intent of this is that you do not unintentionally execute multiple statements and handle the wrong resultset.

Alternatively simple_exec/exec could take the first result and silently ignore others, but I'm not sure that behavior is desirable, since you won't easily find when something unintentionally goes wrong (e.g. a statement returns a empty result first, which you handle and then the results you wanted to handle and now you assume that they do not exist).
So I think this is still the best approach, but maybe currently not documented enough.

@jonhoo
Copy link
Contributor Author

jonhoo commented Feb 27, 2018

Yeah, those are good points. Documentation would help, so would modifying the error message to point you to the fact that only a single statement can be executed at a time.

@steffengy
Copy link
Owner

I believe this won't be a problem anymore with 0.4

@steffengy steffengy added this to the 0.4 milestone Oct 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants