Skip to content

Commit

Permalink
Cast the BIT(1) type when :cast_booleans is true for prepared statements
Browse files Browse the repository at this point in the history
  • Loading branch information
sodabrew committed Nov 14, 2017
1 parent 35a4f6b commit 934a4a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ext/mysql2/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
val = INT2NUM(*((signed char*)result_buffer->buffer));
}
break;
case MYSQL_TYPE_BIT: /* BIT field (MySQL 5.0.3 and up) */
if (args->castBool && fields[i].length == 1) {
val = (*((unsigned char*)result_buffer->buffer) != 0) ? Qtrue : Qfalse;
}else{
val = rb_str_new(result_buffer->buffer, *(result_buffer->length));
}
break;
case MYSQL_TYPE_SHORT: // short int
if (result_buffer->is_unsigned) {
val = UINT2NUM(*((unsigned short int*)result_buffer->buffer));
Expand Down Expand Up @@ -494,7 +501,6 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
case MYSQL_TYPE_BLOB: // char[]
case MYSQL_TYPE_MEDIUM_BLOB: // char[]
case MYSQL_TYPE_LONG_BLOB: // char[]
case MYSQL_TYPE_BIT: // char[]
case MYSQL_TYPE_SET: // char[]
case MYSQL_TYPE_ENUM: // char[]
case MYSQL_TYPE_GEOMETRY: // char[]
Expand Down

0 comments on commit 934a4a8

Please sign in to comment.