mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 09:09:19 +08:00
Merge pull request #646 from gwenn/execute_alter
Fix error while executing ALTER statement
This commit is contained in:
commit
f2063c5bec
10
src/lib.rs
10
src/lib.rs
@ -1118,6 +1118,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "extra_check")]
|
||||||
fn test_execute_select() {
|
fn test_execute_select() {
|
||||||
let db = checked_memory_handle();
|
let db = checked_memory_handle();
|
||||||
let err = db.execute("SELECT 1 WHERE 1 < ?", &[1i32]).unwrap_err();
|
let err = db.execute("SELECT 1 WHERE 1 < ?", &[1i32]).unwrap_err();
|
||||||
@ -1745,5 +1746,14 @@ mod test {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.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();
|
let r = self.stmt.step();
|
||||||
self.stmt.reset();
|
self.stmt.reset();
|
||||||
match r {
|
match r {
|
||||||
ffi::SQLITE_DONE => {
|
ffi::SQLITE_DONE => Ok(self.conn.changes()),
|
||||||
if self.column_count() == 0 {
|
|
||||||
Ok(self.conn.changes())
|
|
||||||
} else {
|
|
||||||
Err(Error::ExecuteReturnedResults)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ffi::SQLITE_ROW => Err(Error::ExecuteReturnedResults),
|
ffi::SQLITE_ROW => Err(Error::ExecuteReturnedResults),
|
||||||
_ => Err(self.conn.decode_result(r).unwrap_err()),
|
_ => Err(self.conn.decode_result(r).unwrap_err()),
|
||||||
}
|
}
|
||||||
@ -551,6 +545,7 @@ impl Statement<'_> {
|
|||||||
#[cfg(all(feature = "modern_sqlite", feature = "extra_check"))]
|
#[cfg(all(feature = "modern_sqlite", feature = "extra_check"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn check_update(&self) -> Result<()> {
|
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() {
|
if self.column_count() > 0 || self.stmt.readonly() {
|
||||||
return Err(Error::ExecuteReturnedResults);
|
return Err(Error::ExecuteReturnedResults);
|
||||||
}
|
}
|
||||||
@ -560,6 +555,7 @@ impl Statement<'_> {
|
|||||||
#[cfg(all(not(feature = "modern_sqlite"), feature = "extra_check"))]
|
#[cfg(all(not(feature = "modern_sqlite"), feature = "extra_check"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn check_update(&self) -> Result<()> {
|
fn check_update(&self) -> Result<()> {
|
||||||
|
// sqlite3_column_count works for DML but not for DDL (ie ALTER)
|
||||||
if self.column_count() > 0 {
|
if self.column_count() > 0 {
|
||||||
return Err(Error::ExecuteReturnedResults);
|
return Err(Error::ExecuteReturnedResults);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user