Skip to content

Commit 219d797

Browse files
committed
Always :VVV, @vvv, $VVV as named params
Even in cases where VVV is a numeric value, these are considered named parameters by sqlite.
1 parent 969b6f1 commit 219d797

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

ext/sqlite3/statement.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,12 @@ named_params(VALUE self)
484484
// The first host parameter has an index of 1, not 0.
485485
for (int i = 1; i <= param_count; i++) {
486486
const char *name = sqlite3_bind_parameter_name(ctx->st, i);
487-
// If parameters of the ?NNN/$NNN/@NNN/:NNN form are used
488-
// there may be gaps in the list.
489-
if (name) {
487+
// We ignore numbered parameters (starting with ?)
488+
// And null values, since there can be gaps in the list
489+
if (name && *name != '?') {
490490
// We ignore numeric parameters
491-
int n = atoi(name + 1);
492-
if (n == 0) {
493-
VALUE param = interned_utf8_cstr(name + 1);
494-
rb_ary_push(params, param);
495-
}
491+
VALUE param = interned_utf8_cstr(name + 1);
492+
rb_ary_push(params, param);
496493
}
497494
}
498495
return rb_obj_freeze(params);

test/test_statement.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ def test_named_bind_not_found
257257
end
258258

259259
def test_params
260-
stmt = SQLite3::Statement.new(@db, "select ?1, :foo, ?, $bar, @zed, ?250, @999")
261-
assert_equal ["foo", "bar", "zed"], stmt.named_params
260+
stmt = SQLite3::Statement.new(@db, "select ?1, :foo, ?, $bar, @zed, ?250, @999, :123, $777")
261+
assert_equal ["foo", "bar", "zed", "999", "123", "777"], stmt.named_params
262262
stmt.close
263263
end
264264

0 commit comments

Comments
 (0)