Skip to content

Commit 5654fa5

Browse files
committed
Fail on incorrect parameter count
1 parent 4ec8130 commit 5654fa5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ impl<'self> NormalPostgresStatement<'self> {
573573
-> Option<PostgresDbError> {
574574
let mut formats = ~[];
575575
let mut values = ~[];
576+
assert!(self.param_types.len() == params.len(),
577+
"Expected %u parameters but found %u",
578+
self.param_types.len(), params.len());
576579
for (&param, &ty) in params.iter().zip(self.param_types.iter()) {
577580
let (format, value) = param.to_sql(ty);
578581
formats.push(format as i16);

src/test.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,22 @@ fn test_wrong_param_type() {
311311
conn.try_update("SELECT $1::VARCHAR", [&1i32 as &ToSql]);
312312
}
313313

314+
#[test]
315+
#[should_fail]
316+
fn test_too_few_params() {
317+
let conn = PostgresConnection::connect("postgres://postgres@localhost");
318+
conn.try_update("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]);
319+
}
320+
321+
#[test]
322+
#[should_fail]
323+
fn test_too_many_params() {
324+
let conn = PostgresConnection::connect("postgres://postgres@localhost");
325+
conn.try_update("SELECT $1::INT, $2::INT", [&1i32 as &ToSql,
326+
&2i32 as &ToSql,
327+
&3i32 as &ToSql]);
328+
}
329+
314330
#[test]
315331
fn test_find_col_named() {
316332
let conn = PostgresConnection::connect("postgres://postgres@localhost");

0 commit comments

Comments
 (0)