diff --git a/src/inner_connection.rs b/src/inner_connection.rs index e35eb14..00675e2 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -264,7 +264,8 @@ impl InnerConnection { }; // If there is an error, *ppStmt is set to NULL. 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_tail: *const c_char = unsafe { c_tail.assume_init() }; // TODO ignore spaces, comments, ... at the end diff --git a/src/statement.rs b/src/statement.rs index 785548a..f866c9f 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -1062,4 +1062,35 @@ mod test { db.query_row("SELECT ?1, ?2, ?3", data.iter(), |row| row.get::<_, u8>(0)) .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()); + } }