Fix error while executing ALTER statement

`execute_bacth` should be used for DDL.
`execute` should still work except when `extra-check` feature is
activated.
This commit is contained in:
gwenn 2020-03-04 20:26:31 +01:00
parent 670b1c221e
commit 1fb00e99b7
2 changed files with 12 additions and 7 deletions

View File

@ -1745,5 +1745,14 @@ mod test {
)
.unwrap();
}
#[test]
#[cfg(not(feature = "extra_check"))]
fn test_alter_table() {
let db = checked_memory_handle();
db.execute_batch("CREATE TABLE x(t);").unwrap();
// `execute_batch` should be used but `execute` should also work
db.execute("ALTER TABLE x RENAME TO y;", params![]).unwrap();
}
}
}

View File

@ -515,13 +515,7 @@ impl Statement<'_> {
let r = self.stmt.step();
self.stmt.reset();
match r {
ffi::SQLITE_DONE => {
if self.column_count() == 0 {
Ok(self.conn.changes())
} else {
Err(Error::ExecuteReturnedResults)
}
}
ffi::SQLITE_DONE => Ok(self.conn.changes()),
ffi::SQLITE_ROW => Err(Error::ExecuteReturnedResults),
_ => Err(self.conn.decode_result(r).unwrap_err()),
}
@ -551,6 +545,7 @@ impl Statement<'_> {
#[cfg(all(feature = "modern_sqlite", feature = "extra_check"))]
#[inline]
fn check_update(&self) -> Result<()> {
// sqlite3_column_count works for DML but not for DDL (ie ALTER)
if self.column_count() > 0 || self.stmt.readonly() {
return Err(Error::ExecuteReturnedResults);
}
@ -560,6 +555,7 @@ impl Statement<'_> {
#[cfg(all(not(feature = "modern_sqlite"), feature = "extra_check"))]
#[inline]
fn check_update(&self) -> Result<()> {
// sqlite3_column_count works for DML but not for DDL (ie ALTER)
if self.column_count() > 0 {
return Err(Error::ExecuteReturnedResults);
}