mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-29 21:52:12 +08:00
Check that even when sqlite_stmt
is null, there is no panic.
This commit is contained in:
parent
8eb844b0c9
commit
ca5eccfe95
@ -264,7 +264,8 @@ impl InnerConnection {
|
|||||||
};
|
};
|
||||||
// If there is an error, *ppStmt is set to NULL.
|
// If there is an error, *ppStmt is set to NULL.
|
||||||
self.decode_result(r)?;
|
self.decode_result(r)?;
|
||||||
// If the input text contains no SQL (if the input is an empty string or a comment) then *ppStmt is set to NULL.
|
// If the input text contains no SQL (if the input is an empty string or a
|
||||||
|
// comment) then *ppStmt is set to NULL.
|
||||||
let c_stmt: *mut ffi::sqlite3_stmt = unsafe { c_stmt.assume_init() };
|
let c_stmt: *mut ffi::sqlite3_stmt = unsafe { c_stmt.assume_init() };
|
||||||
let c_tail: *const c_char = unsafe { c_tail.assume_init() };
|
let c_tail: *const c_char = unsafe { c_tail.assume_init() };
|
||||||
// TODO ignore spaces, comments, ... at the end
|
// TODO ignore spaces, comments, ... at the end
|
||||||
|
@ -1062,4 +1062,35 @@ mod test {
|
|||||||
db.query_row("SELECT ?1, ?2, ?3", data.iter(), |row| row.get::<_, u8>(0))
|
db.query_row("SELECT ?1, ?2, ?3", data.iter(), |row| row.get::<_, u8>(0))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_empty_stmt() {
|
||||||
|
let conn = Connection::open_in_memory().unwrap();
|
||||||
|
let mut stmt = conn.prepare("").unwrap();
|
||||||
|
assert_eq!(0, stmt.column_count());
|
||||||
|
assert!(stmt.parameter_index("test").is_ok());
|
||||||
|
assert!(stmt.step().is_err());
|
||||||
|
stmt.reset();
|
||||||
|
assert!(stmt.execute(NO_PARAMS).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_comment_stmt() {
|
||||||
|
let conn = Connection::open_in_memory().unwrap();
|
||||||
|
conn.prepare("/*SELECT 1;*/").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_comment_and_sql_stmt() {
|
||||||
|
let conn = Connection::open_in_memory().unwrap();
|
||||||
|
let stmt = conn.prepare("/*...*/ SELECT 1;").unwrap();
|
||||||
|
assert_eq!(1, stmt.column_count());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_semi_colon_stmt() {
|
||||||
|
let conn = Connection::open_in_memory().unwrap();
|
||||||
|
let stmt = conn.prepare(";").unwrap();
|
||||||
|
assert_eq!(0, stmt.column_count());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user