Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepared statements should handle booleans properly #871

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ext/mysql2/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
#endif
set_buffer_for_string(&bind_buffers[i], &length_buffers[i], params_enc[i]);
break;
case T_TRUE:
bind_buffers[i].buffer_type = MYSQL_TYPE_TINY;
bind_buffers[i].buffer = xmalloc(sizeof(signed char));
*(signed char*)(bind_buffers[i].buffer) = 1;
break;
case T_FALSE:
bind_buffers[i].buffer_type = MYSQL_TYPE_TINY;
bind_buffers[i].buffer = xmalloc(sizeof(signed char));
*(signed char*)(bind_buffers[i].buffer) = 0;
break;
default:
// TODO: what Ruby type should support MYSQL_TYPE_TIME
if (CLASS_OF(argv[i]) == rb_cTime || CLASS_OF(argv[i]) == cDateTime) {
Expand Down
6 changes: 6 additions & 0 deletions spec/mysql2/statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def stmt_count
expect(rows).to eq([{ "1" => 1 }])
end

it "should handle booleans" do
stmt = @client.prepare('SELECT ? AS `true`, ? AS `false`')
result = stmt.execute(true, false)
expect(result.to_a).to eq(['true' => 1, 'false' => 0])
end

it "should handle bignum but in int64_t" do
stmt = @client.prepare('SELECT ? AS max, ? AS min')
int64_max = (1 << 63) - 1
Expand Down