Skip to content

Commit 8207fca

Browse files
committed
Fixed conversion to and from boolean values: bool to TINYINT
1 parent 8a1c3da commit 8207fca

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/mysql_bindings_statement.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ Handle<Value> MysqlStatement::BindParamsSync(const Arguments& args) {
306306
stmt->binds[i].buffer = int_data;
307307
stmt->binds[i].is_null = 0;
308308
stmt->binds[i].is_unsigned = false;
309+
} else if (js_param->IsBoolean()) {
310+
// I assume, booleans are usually stored as TINYINT(1)
311+
int_data = new int;
312+
*int_data = js_param->Int32Value();
313+
314+
stmt->binds[i].buffer_type = MYSQL_TYPE_TINY;
315+
stmt->binds[i].buffer = int_data;
316+
stmt->binds[i].is_null = 0;
317+
stmt->binds[i].is_unsigned = false;
309318
} else if (js_param->IsUint32()) {
310319
uint_data = new unsigned int;
311320
*uint_data = js_param->Uint32Value();
@@ -472,7 +481,9 @@ Handle<Value> MysqlStatement::FetchAllSync(const Arguments& args) {
472481
MYSQLSTMT_MUSTBE_PREPARED;
473482

474483
/* Get meta data for binding buffers */
484+
475485
unsigned int field_count = mysql_stmt_field_count(stmt->_stmt);
486+
476487
uint32_t i = 0, j = 0;
477488
unsigned long length[field_count];
478489
int row_count = 0;
@@ -490,7 +501,9 @@ Handle<Value> MysqlStatement::FetchAllSync(const Arguments& args) {
490501
memset(date_data, 0, sizeof(date_data));
491502

492503
memset(bind, 0, sizeof(bind));
504+
493505
meta = mysql_stmt_result_metadata(stmt->_stmt);
506+
494507
fields = meta->fields;
495508
while (i < field_count) {
496509
bind[i].buffer_type = fields[i].type;
@@ -559,33 +572,32 @@ Handle<Value> MysqlStatement::FetchAllSync(const Arguments& args) {
559572

560573
j = 0;
561574
while (j < field_count) {
562-
//fprintf(stdout, "Value: %s", buffers[j]);
563575
switch(fields[j].type) {
564576
case MYSQL_TYPE_NULL:
565577
case MYSQL_TYPE_SHORT:
566578
case MYSQL_TYPE_LONG:
567579
case MYSQL_TYPE_LONGLONG:
568580
case MYSQL_TYPE_INT24:
569-
//fprintf(stdout, "Value: %d (%ld)\n", int_data[j], length[j]);
570581
js_result = Integer::New(int_data[j]);
571582
break;
572583
case MYSQL_TYPE_TINY:
573-
fprintf(stdout, "Value: %u (%ld)\n", tiny_data[j], length[j]);
574-
js_result = Integer::NewFromUnsigned(tiny_data[j]);
575-
break;
584+
if (length[j] == 1) {
585+
js_result = BooleanObject::New(tiny_data[j] == true);
586+
} else {
587+
js_result = Integer::NewFromUnsigned(tiny_data[j]);
588+
}
589+
break;
576590
case MYSQL_TYPE_FLOAT:
577591
case MYSQL_TYPE_DOUBLE:
578-
//js_result = Number::New(double_data[j]);
592+
js_result = Number::New(double_data[j]);
579593
break;
580594
case MYSQL_TYPE_DECIMAL:
581595
case MYSQL_TYPE_NEWDECIMAL:
582-
//fprintf(stdout, "Value: %f (%ld)\n", double_data[j], length[j]);
583596
js_result = Number::New(double_data[j])->ToString();
584597
break;
585598
case MYSQL_TYPE_STRING:
586599
case MYSQL_TYPE_VAR_STRING:
587600
case MYSQL_TYPE_VARCHAR:
588-
//fprintf(stdout, "Value: %s (%ld)\n", str_data[j], length[j]);
589601
js_result = V8STR2(str_data[j], length[j]);
590602
break;
591603
case MYSQL_TYPE_YEAR:

0 commit comments

Comments
 (0)