tiberius
tiberius copied to clipboard
Cannot execute multi-statement query
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();
(this is on master
)
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.
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.
I believe this won't be a problem anymore with 0.4