add initial type checking and ruby object creation from resultset
This commit is contained in:
parent
ce559dded2
commit
c844c66046
@ -51,14 +51,14 @@ static VALUE rb_mysql_client_query(VALUE self, VALUE sql) {
|
||||
query = mysql_real_query(client, RSTRING_PTR(sql), RSTRING_LEN(sql));
|
||||
if (query != 0) {
|
||||
// lookup error code and msg, raise exception
|
||||
fprintf(stdout, "Error: %s\n", mysql_error(client));
|
||||
fprintf(stdout, "mysql_real_query error: %s\n", mysql_error(client));
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
result = mysql_store_result(client);
|
||||
if (result == NULL) {
|
||||
// lookup error code and msg, raise exception
|
||||
fprintf(stdout, "Error: %s\n", mysql_error(client));
|
||||
fprintf(stdout, "mysql_store_result error: %s\n", mysql_error(client));
|
||||
return Qnil;
|
||||
}
|
||||
return rb_mysql_result_to_obj(result);
|
||||
@ -118,7 +118,44 @@ static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self) {
|
||||
key = rb_str_new(fields[i].name, fields[i].name_length);
|
||||
}
|
||||
if (row[i]) {
|
||||
rb_hash_aset(rowHash, key, Qnil);
|
||||
VALUE val;
|
||||
switch(fields[i].type) {
|
||||
case MYSQL_TYPE_STRING: // CHAR or BINARY field
|
||||
val = rb_str_new(row[i], fieldLengths[i]);
|
||||
case MYSQL_TYPE_NULL: // NULL-type field
|
||||
val = Qnil;
|
||||
case MYSQL_TYPE_TINY: // TINYINT field
|
||||
case MYSQL_TYPE_SHORT: // SMALLINT field
|
||||
case MYSQL_TYPE_LONG: // INTEGER field
|
||||
case MYSQL_TYPE_INT24: // MEDIUMINT field
|
||||
case MYSQL_TYPE_LONGLONG: // BIGINT field
|
||||
val = rb_cstr2inum(row[i], 10);
|
||||
case MYSQL_TYPE_DECIMAL: // DECIMAL or NUMERIC field
|
||||
case MYSQL_TYPE_NEWDECIMAL: // Precision math DECIMAL or NUMERIC field (MySQL 5.0.3 and up)
|
||||
val = Qnil;
|
||||
case MYSQL_TYPE_FLOAT: // FLOAT field
|
||||
val = Qnil;
|
||||
case MYSQL_TYPE_DOUBLE: // DOUBLE or REAL field
|
||||
val = Qnil;
|
||||
case MYSQL_TYPE_BIT: // BIT field (MySQL 5.0.3 and up)
|
||||
case MYSQL_TYPE_TIMESTAMP: // TIMESTAMP field
|
||||
case MYSQL_TYPE_DATE: // DATE field
|
||||
case MYSQL_TYPE_TIME: // TIME field
|
||||
case MYSQL_TYPE_DATETIME: // DATETIME field
|
||||
val = Qnil;
|
||||
case MYSQL_TYPE_YEAR: // YEAR field
|
||||
val = rb_cstr2inum(row[i], 10);
|
||||
case MYSQL_TYPE_VAR_STRING: // VARCHAR or VARBINARY field
|
||||
case MYSQL_TYPE_BLOB: // BLOB or TEXT field (use max_length to determine the maximum length)
|
||||
val = rb_str_new(row[i], fieldLengths[i]);
|
||||
case MYSQL_TYPE_SET: // SET field
|
||||
case MYSQL_TYPE_ENUM: // ENUM field
|
||||
case MYSQL_TYPE_GEOMETRY: // Spatial fielda
|
||||
default:
|
||||
val = rb_str_new(row[i], fieldLengths[i]);
|
||||
}
|
||||
// TODO: determine field type then inflate a new ruby object around it
|
||||
rb_hash_aset(rowHash, key, val);
|
||||
} else {
|
||||
rb_hash_aset(rowHash, key, Qnil);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user