mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
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:
parent
670b1c221e
commit
1fb00e99b7
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user