Skip to content

Commit

Permalink
fix include mysql.h Path. fix segmentation faults. By default directl…
Browse files Browse the repository at this point in the history
…y return results.

The mysql header files are usually present in include folder and prefixing mysql doesn't work.
Date fields  can be null, and it was failing with 'Bus error', as null cannot be converted to String.
with mysql_use_result a new query cannot be executed until all the results from the previous query has been extracted. so, mysql_store_result should be default.
  • Loading branch information
ssinghi committed Aug 12, 2010
1 parent 2ee5ff9 commit c9eb290
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/mysql_bindings_connection.cc
Expand Up @@ -771,7 +771,7 @@ Handle<Value> MysqlConn::Query(const Arguments& args) {

int result_mode = MYSQLSYNC_STORE_RESULT;

if (args.Length() == 1) {
if (args.Length() == 2) {
result_mode = MYSQLSYNC_USE_RESULT;
}

Expand All @@ -784,7 +784,6 @@ Handle<Value> MysqlConn::Query(const Arguments& args) {
MYSQLSYNC_DISABLE_MQ;

int r = mysql_real_query(conn->_conn, *query, query.length());

if (r != 0) {
return scope.Close(False());
}
Expand Down
2 changes: 1 addition & 1 deletion src/mysql_bindings_connection.h
Expand Up @@ -8,7 +8,7 @@ See license text in LICENSE file
#ifndef NODE_MYSQL_CONNECTION_H // NOLINT
#define NODE_MYSQL_CONNECTION_H

#include <mysql/mysql.h>
#include <mysql.h>

#include <v8.h>
#include <node.h>
Expand Down
24 changes: 16 additions & 8 deletions src/mysql_bindings_result.cc
Expand Up @@ -82,28 +82,38 @@ void MysqlConn::MysqlResult::SetFieldValue(
case MYSQL_TYPE_INT24: // MEDIUMINT field
case MYSQL_TYPE_LONGLONG: // BIGINT field
case MYSQL_TYPE_YEAR: // YEAR field
js_field = String::New(field_value)->ToInteger();
if (field_value) {
js_field = String::New(field_value)->ToInteger();
}
break;
case MYSQL_TYPE_DECIMAL: // DECIMAL or NUMERIC field
case MYSQL_TYPE_NEWDECIMAL: // Precision math DECIMAL or NUMERIC field
case MYSQL_TYPE_FLOAT: // FLOAT field
case MYSQL_TYPE_DOUBLE: // DOUBLE or REAL field
// TODO(Sannis): Read about MySQL datatypes and javascript data
js_field = String::New(field_value)->ToNumber();
if (field_value) {
js_field = String::New(field_value)->ToNumber();
}
break;
case MYSQL_TYPE_TIME: // TIME field
// TODO(Sannis): Read about MySQL datatypes and javascript data
js_field = String::New(field_value);
if (field_value) {
js_field = String::New(field_value);
}
break;
case MYSQL_TYPE_TIMESTAMP: // TIMESTAMP field
case MYSQL_TYPE_DATETIME: // DATETIME field
// TODO(Sannis): Read about MySQL datatypes and javascript data
js_field = String::New(field_value);
if (field_value) {
js_field = String::New(field_value);
}
break;
case MYSQL_TYPE_DATE: // DATE field
case MYSQL_TYPE_NEWDATE: // Newer const used > 5.0
// TODO(Sannis): Read about MySQL datatypes and javascript data
js_field = String::New(field_value);
if (field_value) {
js_field = String::New(field_value);
}
break;
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
Expand Down Expand Up @@ -208,16 +218,14 @@ Handle<Value> MysqlConn::MysqlResult::FetchArray(const Arguments& args) {
if (!res->_res) {
return scope.Close(False());
}

MYSQL_FIELD *fields = mysql_fetch_fields(res->_res);
uint32_t num_fields = mysql_num_fields(res->_res);
MYSQL_ROW result_row;
uint32_t j = 0;

Local<Array> js_result_row;
Local<Value> js_field;

result_row = mysql_fetch_row(res->_res);
MYSQL_ROW result_row = mysql_fetch_row(res->_res);

if (!result_row) {
return scope.Close(False());
Expand Down
2 changes: 1 addition & 1 deletion src/mysql_bindings_result.h
Expand Up @@ -8,7 +8,7 @@ See license text in LICENSE file
#ifndef NODE_MYSQL_RESULT_H // NOLINT
#define NODE_MYSQL_RESULT_H

#include <mysql/mysql.h>
#include <mysql.h>

#include <v8.h>
#include <node.h>
Expand Down
2 changes: 1 addition & 1 deletion src/mysql_bindings_statement.h
Expand Up @@ -8,7 +8,7 @@ See license text in LICENSE file
#ifndef NODE_MYSQL_STATEMENT_H // NOLINT
#define NODE_MYSQL_STATEMENT_H

#include <mysql/mysql.h>
#include <mysql.h>

#include <v8.h>
#include <node.h>
Expand Down

0 comments on commit c9eb290

Please sign in to comment.