for DATE columns, return ruby Date object instead of Time (didn't realize I could create them from y,m,d integers without ActiveSupport)

This commit is contained in:
Brian Lopez 2010-04-21 10:28:25 -07:00
parent eefa443c2e
commit 51babb3362
3 changed files with 10 additions and 3 deletions

View File

@ -383,7 +383,7 @@ static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self) {
val = Qnil; val = Qnil;
} else { } else {
strptime(row[i], "%F", &parsedTime); strptime(row[i], "%F", &parsedTime);
val = rb_funcall(rb_cTime, intern_local, 3, INT2NUM(1900+parsedTime.tm_year), INT2NUM(parsedTime.tm_mon+1), INT2NUM(parsedTime.tm_mday)); val = rb_funcall(cDate, intern_new, 3, INT2NUM(1900+parsedTime.tm_year), INT2NUM(parsedTime.tm_mon+1), INT2NUM(parsedTime.tm_mday));
} }
break; break;
case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_TINY_BLOB:

View File

@ -21,7 +21,7 @@ module ActiveRecord
when :float then Float when :float then Float
when :decimal then BigDecimal when :decimal then BigDecimal
when :datetime then Time when :datetime then Time
when :date then Time when :date then Date
when :timestamp then Time when :timestamp then Time
when :time then Time when :time then Time
when :text, :string then String when :text, :string then String

View File

@ -140,7 +140,6 @@ describe Mysql2::Result do
end end
{ {
'date_test' => 'DATE',
'date_time_test' => 'DATETIME', 'date_time_test' => 'DATETIME',
'timestamp_test' => 'TIMESTAMP', 'timestamp_test' => 'TIMESTAMP',
'time_test' => 'TIME' 'time_test' => 'TIME'
@ -150,6 +149,14 @@ describe Mysql2::Result do
end end
end end
{
'date_test' => 'DATE'
}.each do |field, type|
it "should return a Date for #{type}" do
@test_result[field].class.should eql(Date)
end
end
{ {
'char_test' => 'CHAR', 'char_test' => 'CHAR',
'varchar_test' => 'VARCHAR', 'varchar_test' => 'VARCHAR',