GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: DBSlayer adapter for DataMapper 0.9
Homepage: http://github.com/krobertson/dm-dbslayer
Clone URL: git://github.com/krobertson/dm-dbslayer.git
Extended testing and support for more data types
krobertson (author)
Mon May 19 23:11:02 -0700 2008
commit  6547d67f1e7c3b25de418914cfab6fc868fef1a0
tree    bfc0ad58e320ffb641a86c1d55866283670bd669
parent  a8e808df0319746498d6769f2945247bde9803c6
...
35
36
37
38
39
40
41
 
42
43
 
 
 
44
45
 
46
47
 
48
49
50
...
53
54
55
 
 
56
57
58
59
60
61
62
63
64
65
...
35
36
37
 
 
38
 
39
40
 
41
42
43
44
 
45
46
 
47
48
49
50
...
53
54
55
56
57
58
59
60
61
62
63
 
64
65
66
0
@@ -35,16 +35,16 @@ module DataObjects
0
             BigDecimal.new(row[p])
0
           when 'MYSQL_TYPE_BIT'
0
             row[p] == '1'
0
- when 'MYSQL_TYPE_TIMESTAMP'
0
- row[p]
0
           when 'MYSQL_TYPE_DATE'
0
- row[p]
0
+ Date.strptime(row[p], '%Y-%m-%d')
0
           when 'MYSQL_TYPE_TIME'
0
- row[p]
0
+ Time.parse(row[p])
0
+ when 'MYSQL_TYPE_TIMESTAMP'
0
+ Time.parse(row[p])
0
           when 'MYSQL_TYPE_DATETIME'
0
- row[p]
0
+ DateTime.strptime(row[p], '%Y-%m-%d %H:%M:%S')
0
           when 'MYSQL_TYPE_YEAR'
0
- row[p]
0
+ row[p].to_i
0
           when 'MYSQL_TYPE_BLOB'
0
             row[p]
0
           when 'MYSQL_TYPE_TINY_BLOB'
0
@@ -53,13 +53,14 @@ module DataObjects
0
             row[p]
0
           when 'MYSQL_TYPE_LONG_BLOB'
0
             row[p]
0
+ when 'MYSQL_TYPE_TINY'
0
+ row[p] == 1 # Bool
0
           when 'MYSQL_TYPE_NULL'
0
             nil
0
           else row[p]
0
           end
0
 
0
           # Following not needed since already the right type
0
- #when 'MYSQL_TYPE_TINY' : row[p].to_i
0
           #when 'MYSQL_TYPE_SHORT' : row[p].to_i
0
           #when 'MYSQL_TYPE_LONG' : row[p].to_i
0
           #when 'MYSQL_TYPE_INT24' : row[p].to_i
...
3
4
5
6
 
 
 
 
 
7
8
9
...
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
26
...
3
4
5
 
6
7
8
9
10
11
12
13
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
0
@@ -3,7 +3,11 @@ require File.join(File.dirname(__FILE__), '/spec_helper')
0
 describe DataObjects::Dbslayer::Reader do
0
   before :all do
0
     @reader_query = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'reader_result.txt')).read
0
- @reader = DataObjects::Dbslayer::Reader.new( JSON.parse(@reader_query)['RESULT'] )
0
+ @types_query = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'types_test.txt')).read
0
+ @reader = DataObjects::Dbslayer::Reader.new( JSON.parse(@reader_query)['RESULT'] )
0
+
0
+ @types_reader = DataObjects::Dbslayer::Reader.new( JSON.parse(@types_query)['RESULT'] )
0
+ @types_reader.next!
0
   end
0
 
0
   it 'should return the fields' do
0
@@ -22,4 +26,39 @@ describe DataObjects::Dbslayer::Reader do
0
     end
0
     rows.should == 10
0
   end
0
+
0
+ it 'should be able to read a number' do
0
+ @types_reader.values[0].class.should == Fixnum
0
+ @types_reader.values[0].should == 1
0
+ end
0
+
0
+ it 'should be able to read Date types' do
0
+ @types_reader.values[1].class.should == Date
0
+ @types_reader.values[1].should == Date.new(2008, 5, 19)
0
+ end
0
+
0
+ it 'should be able to read a Time(stamp) type' do
0
+ @types_reader.values[2].class.should == Time
0
+ @types_reader.values[2].should == Time.mktime(2008, 5, 19, 9, 46, 56)
0
+ end
0
+
0
+ it 'should be able to read a DateTime type' do
0
+ @types_reader.values[3].class.should == DateTime
0
+ @types_reader.values[3].should == DateTime.new(2008, 5, 19, 9, 48, 7)
0
+ end
0
+
0
+ it 'should be able to read a basic time type' do
0
+ @types_reader.values[4].class.should == Time
0
+ @types_reader.values[4].should == Time.parse('09:48:07')
0
+ end
0
+
0
+ it 'should be able to read a year type' do
0
+ @types_reader.values[5].class.should == Fixnum
0
+ @types_reader.values[5].should == 2008
0
+ end
0
+
0
+ it 'should be able to read a boolean type' do
0
+ @types_reader.values[6].class.should == TrueClass
0
+ @types_reader.values[6].should == true
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.