rails-dbi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3694 -0
- data/LICENSE +25 -0
- data/README +271 -0
- data/bin/dbi +518 -0
- data/bin/test_broken_dbi +37 -0
- data/build/Rakefile.dbi.rb +60 -0
- data/examples/test1.pl +39 -0
- data/examples/test1.rb +20 -0
- data/examples/xmltest.rb +8 -0
- data/lib/dbi/base_classes/database.rb +135 -0
- data/lib/dbi/base_classes/driver.rb +47 -0
- data/lib/dbi/base_classes/statement.rb +171 -0
- data/lib/dbi/base_classes.rb +12 -0
- data/lib/dbi/binary.rb +25 -0
- data/lib/dbi/columninfo.rb +107 -0
- data/lib/dbi/exceptions.rb +65 -0
- data/lib/dbi/handles/database.rb +241 -0
- data/lib/dbi/handles/driver.rb +60 -0
- data/lib/dbi/handles/statement.rb +408 -0
- data/lib/dbi/handles.rb +49 -0
- data/lib/dbi/row.rb +270 -0
- data/lib/dbi/sql/preparedstatement.rb +115 -0
- data/lib/dbi/sql.rb +22 -0
- data/lib/dbi/sql_type_constants.rb +75 -0
- data/lib/dbi/trace.rb +91 -0
- data/lib/dbi/types.rb +218 -0
- data/lib/dbi/typeutil.rb +109 -0
- data/lib/dbi/utils/date.rb +59 -0
- data/lib/dbi/utils/tableformatter.rb +112 -0
- data/lib/dbi/utils/time.rb +52 -0
- data/lib/dbi/utils/timestamp.rb +96 -0
- data/lib/dbi/utils/xmlformatter.rb +73 -0
- data/lib/dbi/utils.rb +60 -0
- data/lib/dbi.rb +337 -0
- data/test/dbi/tc_columninfo.rb +94 -0
- data/test/dbi/tc_date.rb +88 -0
- data/test/dbi/tc_dbi.rb +184 -0
- data/test/dbi/tc_row.rb +256 -0
- data/test/dbi/tc_sqlbind.rb +168 -0
- data/test/dbi/tc_statementhandle.rb +29 -0
- data/test/dbi/tc_time.rb +77 -0
- data/test/dbi/tc_timestamp.rb +142 -0
- data/test/dbi/tc_types.rb +268 -0
- data/test/ts_dbi.rb +15 -0
- metadata +132 -0
data/test/dbi/tc_time.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# tc_time.rb
|
3
|
+
#
|
4
|
+
# Test case for the DBI::Time class (currently) located in the utils.rb file.
|
5
|
+
##############################################################################
|
6
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
7
|
+
$LOAD_PATH.unshift(File.dirname(Dir.pwd))
|
8
|
+
$LOAD_PATH.unshift("../../lib")
|
9
|
+
$LOAD_PATH.unshift("../../lib/dbi")
|
10
|
+
$LOAD_PATH.unshift("lib")
|
11
|
+
|
12
|
+
require 'dbi'
|
13
|
+
require 'test/unit'
|
14
|
+
|
15
|
+
Deprecate.set_action(proc { })
|
16
|
+
|
17
|
+
class TC_DBI_Time < Test::Unit::TestCase
|
18
|
+
def setup
|
19
|
+
@time = Time.new
|
20
|
+
@dbi_time = DBI::Time.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_constructor
|
24
|
+
assert_nothing_raised{ DBI::Time.new(9) }
|
25
|
+
assert_nothing_raised{ DBI::Time.new(9, 41) }
|
26
|
+
assert_nothing_raised{ DBI::Time.new(9, 41, 20) }
|
27
|
+
assert_nothing_raised{ DBI::Time.new(Date.new) }
|
28
|
+
assert_nothing_raised{ DBI::Time.new(Time.now) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_hour
|
32
|
+
assert_respond_to(@dbi_time, :hour)
|
33
|
+
assert_respond_to(@dbi_time, :hour=)
|
34
|
+
assert_equal(0, @dbi_time.hour)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_minute
|
38
|
+
assert_respond_to(@dbi_time, :minute)
|
39
|
+
assert_respond_to(@dbi_time, :minute=)
|
40
|
+
assert_equal(0, @dbi_time.minute)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Alias for minute
|
44
|
+
def test_min
|
45
|
+
assert_respond_to(@dbi_time, :min)
|
46
|
+
assert_respond_to(@dbi_time, :min=)
|
47
|
+
assert_equal(0, @dbi_time.min)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_second
|
51
|
+
assert_respond_to(@dbi_time, :second)
|
52
|
+
assert_respond_to(@dbi_time, :second=)
|
53
|
+
assert_equal(0, @dbi_time.second)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_sec
|
57
|
+
assert_respond_to(@dbi_time, :sec)
|
58
|
+
assert_respond_to(@dbi_time, :sec=)
|
59
|
+
assert_equal(0, @dbi_time.sec)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_to_time
|
63
|
+
assert_respond_to(@dbi_time, :to_time)
|
64
|
+
assert_equal(@time, DBI::Time.new(@time).to_time)
|
65
|
+
#assert_equal(@time.object_id, DBI::Time.new(@time).object_id) # Fails ??
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_to_s
|
69
|
+
assert_respond_to(@dbi_time, :to_s)
|
70
|
+
assert_equal("00:00:00", @dbi_time.to_s)
|
71
|
+
end
|
72
|
+
|
73
|
+
def teardown
|
74
|
+
@time = nil
|
75
|
+
@dbi_time = nil
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# tc_timestamp.rb
|
3
|
+
#
|
4
|
+
# Test case for the DBI::Timestamp class (currently) located in the
|
5
|
+
# utils.rb file.
|
6
|
+
##############################################################################
|
7
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
8
|
+
$LOAD_PATH.unshift(File.dirname(Dir.pwd))
|
9
|
+
$LOAD_PATH.unshift("../../lib")
|
10
|
+
$LOAD_PATH.unshift("../../lib/dbi")
|
11
|
+
$LOAD_PATH.unshift("lib")
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'dbi'
|
15
|
+
require 'test/unit'
|
16
|
+
|
17
|
+
Deprecate.set_action(proc { })
|
18
|
+
|
19
|
+
class TC_DBI_Date < Test::Unit::TestCase
|
20
|
+
def setup
|
21
|
+
@date = Date.new
|
22
|
+
@time = Time.now
|
23
|
+
@dbi_ts = DBI::Timestamp.new(2006, 1, 31, 10, 23, 22, 45)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_constructor
|
27
|
+
assert_nothing_raised{ DBI::Timestamp.new }
|
28
|
+
assert_nothing_raised{ DBI::Timestamp.new(2006) }
|
29
|
+
assert_nothing_raised{ DBI::Timestamp.new(2006, 1) }
|
30
|
+
assert_nothing_raised{ DBI::Timestamp.new(2006, 1, 31) }
|
31
|
+
assert_nothing_raised{ DBI::Timestamp.new(2006, 1, 31, 10) }
|
32
|
+
assert_nothing_raised{ DBI::Timestamp.new(2006, 1, 31, 10, 23) }
|
33
|
+
assert_nothing_raised{ DBI::Timestamp.new(2006, 1, 31, 10, 23, 22) }
|
34
|
+
assert_nothing_raised{ DBI::Timestamp.new(2006, 1, 31, 10, 23, 22, 45) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_to_date
|
38
|
+
assert_respond_to(@dbi_ts, :to_date)
|
39
|
+
assert_kind_of(Date, @dbi_ts.to_date)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_to_time
|
43
|
+
assert_respond_to(@dbi_ts, :to_time)
|
44
|
+
assert_kind_of(Time, @dbi_ts.to_time)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_s
|
48
|
+
assert_respond_to(@dbi_ts, :to_s)
|
49
|
+
assert_equal("2006-01-31 10:23:22.000000045", @dbi_ts.to_s)
|
50
|
+
assert_equal("2008-03-08 10:39:01.0045",
|
51
|
+
DBI::Timestamp.new(2008, 3, 8, 10, 39, 1, 4500000).to_s)
|
52
|
+
assert_equal("2008-03-08 10:39:01.0",
|
53
|
+
DBI::Timestamp.new(2008, 3, 8, 10, 39, 1, 0).to_s)
|
54
|
+
assert_equal("2008-03-08 10:39:01",
|
55
|
+
DBI::Timestamp.new(2008, 3, 8, 10, 39, 1, nil).to_s)
|
56
|
+
assert_equal("0000-00-00 00:00:00", DBI::Timestamp.new.to_s)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_equality
|
60
|
+
assert_equal(true, @dbi_ts == DBI::Timestamp.new(2006,1,31,10,23,22,45))
|
61
|
+
assert_equal(false, @dbi_ts == DBI::Timestamp.new(2006,1,31,10,23,22,46))
|
62
|
+
assert_equal(false, @dbi_ts == nil)
|
63
|
+
assert_equal(false, @dbi_ts == 1)
|
64
|
+
assert_equal(false, @dbi_ts == "hello")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_fraction
|
68
|
+
assert_respond_to(@dbi_ts, :fraction)
|
69
|
+
assert_respond_to(@dbi_ts, :fraction=)
|
70
|
+
assert_equal(45, @dbi_ts.fraction)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_second
|
74
|
+
assert_respond_to(@dbi_ts, :second)
|
75
|
+
assert_respond_to(@dbi_ts, :second=)
|
76
|
+
assert_equal(22, @dbi_ts.second)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Alias for second
|
80
|
+
def test_sec
|
81
|
+
assert_respond_to(@dbi_ts, :sec)
|
82
|
+
assert_respond_to(@dbi_ts, :sec=)
|
83
|
+
assert_equal(22, @dbi_ts.sec)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_minute
|
87
|
+
assert_respond_to(@dbi_ts, :minute)
|
88
|
+
assert_respond_to(@dbi_ts, :minute=)
|
89
|
+
assert_equal(23, @dbi_ts.minute)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Alias for minute
|
93
|
+
def test_min
|
94
|
+
assert_respond_to(@dbi_ts, :min)
|
95
|
+
assert_respond_to(@dbi_ts, :min=)
|
96
|
+
assert_equal(23, @dbi_ts.min)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_hour
|
100
|
+
assert_respond_to(@dbi_ts, :hour)
|
101
|
+
assert_respond_to(@dbi_ts, :hour=)
|
102
|
+
assert_equal(10, @dbi_ts.hour)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_day
|
106
|
+
assert_respond_to(@dbi_ts, :day)
|
107
|
+
assert_respond_to(@dbi_ts, :day=)
|
108
|
+
assert_equal(31, @dbi_ts.day)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Alias for day
|
112
|
+
def test_mday
|
113
|
+
assert_respond_to(@dbi_ts, :mday)
|
114
|
+
assert_respond_to(@dbi_ts, :mday=)
|
115
|
+
assert_equal(31, @dbi_ts.mday)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_month
|
119
|
+
assert_respond_to(@dbi_ts, :month)
|
120
|
+
assert_respond_to(@dbi_ts, :month=)
|
121
|
+
assert_equal(1, @dbi_ts.month)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Alias for month
|
125
|
+
def test_mon
|
126
|
+
assert_respond_to(@dbi_ts, :mon)
|
127
|
+
assert_respond_to(@dbi_ts, :mon=)
|
128
|
+
assert_equal(1, @dbi_ts.mon)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_year
|
132
|
+
assert_respond_to(@dbi_ts, :year)
|
133
|
+
assert_respond_to(@dbi_ts, :year=)
|
134
|
+
assert_equal(2006, @dbi_ts.year)
|
135
|
+
end
|
136
|
+
|
137
|
+
def teardown
|
138
|
+
@date = nil
|
139
|
+
@time = nil
|
140
|
+
@dbi_ts = nil
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
2
|
+
$LOAD_PATH.unshift(File.dirname(Dir.pwd))
|
3
|
+
$LOAD_PATH.unshift("../../lib")
|
4
|
+
$LOAD_PATH.unshift("../../lib/dbi")
|
5
|
+
$LOAD_PATH.unshift("lib")
|
6
|
+
|
7
|
+
require "dbi"
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
class MyType
|
11
|
+
def initialize(obj)
|
12
|
+
@obj = obj
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
@obj.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TC_DBI_Type < Test::Unit::TestCase
|
21
|
+
def test_null
|
22
|
+
# all types except Varchar need to appropriately handle NULL
|
23
|
+
[
|
24
|
+
DBI::Type::Null,
|
25
|
+
DBI::Type::Integer,
|
26
|
+
DBI::Type::Float,
|
27
|
+
DBI::Type::Timestamp,
|
28
|
+
DBI::Type::Boolean
|
29
|
+
].each do |klass|
|
30
|
+
assert_equal(nil, klass.parse("NULL"))
|
31
|
+
assert_equal(nil, klass.parse("null"))
|
32
|
+
assert_equal(nil, klass.parse("Null"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_boolean
|
37
|
+
klass = DBI::Type::Boolean
|
38
|
+
assert_kind_of(NilClass, klass.parse(nil))
|
39
|
+
assert_kind_of(NilClass, klass.parse("NULL"))
|
40
|
+
assert_kind_of(TrueClass, klass.parse('t'))
|
41
|
+
assert_kind_of(TrueClass, klass.parse(1))
|
42
|
+
assert_kind_of(TrueClass, klass.parse('1'))
|
43
|
+
assert_kind_of(FalseClass, klass.parse('f'))
|
44
|
+
assert_kind_of(FalseClass, klass.parse(0))
|
45
|
+
assert_kind_of(FalseClass, klass.parse('0'))
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_varchar
|
49
|
+
klass = DBI::Type::Varchar
|
50
|
+
assert_kind_of(String, klass.parse("hello"))
|
51
|
+
assert_kind_of(String, klass.parse("1"))
|
52
|
+
assert_kind_of(String, klass.parse("1.23"))
|
53
|
+
|
54
|
+
assert_equal("NULL", klass.parse("NULL"))
|
55
|
+
assert_equal("1", klass.parse("1"))
|
56
|
+
assert_equal("hello", klass.parse("hello"))
|
57
|
+
assert_equal("1.23", klass.parse("1.23"))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_integer
|
61
|
+
klass = DBI::Type::Integer
|
62
|
+
assert_kind_of(Integer, klass.parse("1.23"))
|
63
|
+
assert_kind_of(Integer, klass.parse("-1.23"))
|
64
|
+
assert_kind_of(Integer, klass.parse("1.0"))
|
65
|
+
assert_kind_of(Integer, klass.parse("1"))
|
66
|
+
assert_kind_of(Integer, klass.parse("-1"))
|
67
|
+
assert_kind_of(Integer, klass.parse("0"))
|
68
|
+
|
69
|
+
assert_equal(nil, klass.parse("NULL"))
|
70
|
+
assert_equal(1, klass.parse("1.23"))
|
71
|
+
assert_equal(-1, klass.parse("-1.23"))
|
72
|
+
assert_equal(1, klass.parse("1.0"))
|
73
|
+
assert_equal(1, klass.parse("1"))
|
74
|
+
assert_equal(-1, klass.parse("-1"))
|
75
|
+
assert_equal(0, klass.parse("0"))
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_float
|
79
|
+
klass = DBI::Type::Float
|
80
|
+
assert_kind_of(Float, klass.parse("1.23"))
|
81
|
+
assert_kind_of(Float, klass.parse("-1.23"))
|
82
|
+
assert_kind_of(Float, klass.parse("1.0"))
|
83
|
+
assert_kind_of(Float, klass.parse("1"))
|
84
|
+
assert_kind_of(Float, klass.parse("-1"))
|
85
|
+
assert_kind_of(Float, klass.parse("0"))
|
86
|
+
|
87
|
+
assert_equal(nil, klass.parse("NULL"))
|
88
|
+
assert_equal(1.23, klass.parse("1.23"))
|
89
|
+
assert_equal(-1.23, klass.parse("-1.23"))
|
90
|
+
assert_equal(1, klass.parse("1.0"))
|
91
|
+
assert_equal(1, klass.parse("1"))
|
92
|
+
assert_equal(-1, klass.parse("-1"))
|
93
|
+
assert_equal(0, klass.parse("0"))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_timestamp
|
97
|
+
klass = DBI::Type::Timestamp
|
98
|
+
assert_kind_of(DateTime, klass.parse(Time.now))
|
99
|
+
assert_kind_of(DateTime, klass.parse(Date.today))
|
100
|
+
assert_kind_of(DateTime, klass.parse(DateTime.now))
|
101
|
+
assert_kind_of(DateTime, klass.parse(Time.now.to_s))
|
102
|
+
assert_kind_of(DateTime, klass.parse(Date.today.to_s))
|
103
|
+
assert_kind_of(DateTime, klass.parse(DateTime.now.to_s))
|
104
|
+
|
105
|
+
assert_equal(nil, klass.parse("NULL"))
|
106
|
+
|
107
|
+
# string coercion
|
108
|
+
dt = DateTime.now
|
109
|
+
assert_equal(dt.to_s, klass.parse(dt).to_s)
|
110
|
+
|
111
|
+
t = Time.now
|
112
|
+
assert_equal(DateTime.parse(t.to_s).to_s, klass.parse(t).to_s)
|
113
|
+
|
114
|
+
d = Date.today
|
115
|
+
assert_equal(DateTime.parse(d.to_s).to_s, klass.parse(d).to_s)
|
116
|
+
|
117
|
+
md = "10-11"
|
118
|
+
|
119
|
+
if RUBY_VERSION =~ /^1\.9/
|
120
|
+
md = "11-10"
|
121
|
+
end
|
122
|
+
|
123
|
+
# be sure we're actually getting the right data back
|
124
|
+
assert_equal(
|
125
|
+
"2008-#{md}",
|
126
|
+
klass.parse(Date.parse("10/11/2008")).strftime("%Y-%m-%d")
|
127
|
+
)
|
128
|
+
|
129
|
+
assert_equal(
|
130
|
+
"10:01:02",
|
131
|
+
klass.parse(Time.parse("10:01:02")).strftime("%H:%M:%S")
|
132
|
+
)
|
133
|
+
|
134
|
+
assert_equal(
|
135
|
+
"#{md}-2008 10:01:02",
|
136
|
+
klass.parse(DateTime.parse("10/11/2008 10:01:02")).strftime("%m-%d-%Y %H:%M:%S")
|
137
|
+
)
|
138
|
+
|
139
|
+
# precision tests, related to ticket #27182
|
140
|
+
|
141
|
+
# iso8601 (bypasses regex)
|
142
|
+
[
|
143
|
+
'2009-09-27T19:41:00-05:00',
|
144
|
+
'2009-09-27T19:41:00.123-05:00'
|
145
|
+
].each do |string|
|
146
|
+
assert_equal(DateTime.parse(string), klass.parse(string))
|
147
|
+
end
|
148
|
+
|
149
|
+
# offset comparison check
|
150
|
+
assert_equal(
|
151
|
+
DateTime.parse('2009-09-27T19:41:00.123-05:00'),
|
152
|
+
klass.parse('2009-09-28T00:41:00.123+00:00')
|
153
|
+
)
|
154
|
+
|
155
|
+
assert_equal(
|
156
|
+
DateTime.parse('2009-09-28T00:41:00.123+00:00'),
|
157
|
+
klass.parse('2009-09-27T19:41:00.123-05:00')
|
158
|
+
)
|
159
|
+
|
160
|
+
# unix convention (uses regex)
|
161
|
+
|
162
|
+
[
|
163
|
+
'2009-09-27 19:41:00 -05:00',
|
164
|
+
'2009-09-27 19:41:00.123 -05:00'
|
165
|
+
].each do |string|
|
166
|
+
assert_equal(DateTime.parse(string), klass.parse(string))
|
167
|
+
end
|
168
|
+
|
169
|
+
# offset comparison check
|
170
|
+
assert_equal(
|
171
|
+
DateTime.parse('2009-09-27 19:41:00.123 -05:00'),
|
172
|
+
klass.parse('2009-09-28 00:41:00.123 +00:00')
|
173
|
+
)
|
174
|
+
|
175
|
+
assert_equal(
|
176
|
+
DateTime.parse('2009-09-28 00:41:00.123 +00:00'),
|
177
|
+
klass.parse('2009-09-27 19:41:00.123 -05:00')
|
178
|
+
)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class TC_DBI_TypeUtil < Test::Unit::TestCase
|
183
|
+
def cast(obj)
|
184
|
+
DBI::TypeUtil.convert(nil, obj)
|
185
|
+
end
|
186
|
+
|
187
|
+
def datecast(obj)
|
188
|
+
"'#{::DateTime.parse(obj.to_s).strftime("%Y-%m-%dT%H:%M:%S")}'"
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_default_unknown_cast
|
192
|
+
assert_kind_of(String, cast(MyType.new("foo")))
|
193
|
+
assert_equal("'foo'", cast(MyType.new("foo")))
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_default_numeric_cast
|
197
|
+
assert_kind_of(String, cast(1))
|
198
|
+
assert_equal("1", cast(1))
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_default_string_cast
|
202
|
+
assert_kind_of(String, cast("foo"))
|
203
|
+
assert_equal("'foo'", cast("foo"))
|
204
|
+
assert_equal("'foo''bar'", cast("foo'bar"))
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_default_time_casts
|
208
|
+
assert_kind_of(String, cast(Time.now))
|
209
|
+
assert_kind_of(String, cast(Date.today))
|
210
|
+
assert_kind_of(String, cast(DateTime.now))
|
211
|
+
|
212
|
+
obj = Time.now
|
213
|
+
assert_equal(datecast(obj), cast(obj))
|
214
|
+
obj = Date.today
|
215
|
+
assert_equal(datecast(obj), cast(obj))
|
216
|
+
obj = DateTime.now
|
217
|
+
assert_equal(datecast(obj), cast(obj))
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_default_boolean_casts
|
221
|
+
assert_kind_of(String, cast(false))
|
222
|
+
assert_kind_of(String, cast(true))
|
223
|
+
assert_kind_of(NilClass, cast(nil))
|
224
|
+
|
225
|
+
assert_equal("'1'", cast(true))
|
226
|
+
assert_equal("'0'", cast(false))
|
227
|
+
assert_equal(nil, cast(nil))
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_default_binary_casts
|
231
|
+
assert_kind_of(DBI::Binary, cast(DBI::Binary.new("poop")))
|
232
|
+
obj = DBI::Binary.new("poop")
|
233
|
+
assert_equal(obj.object_id, cast(obj).object_id)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
DBI::TypeUtil.register_conversion("test") do |obj|
|
238
|
+
case obj
|
239
|
+
when ::NilClass
|
240
|
+
["Custom Nil", false]
|
241
|
+
when ::TrueClass
|
242
|
+
["Custom True", false]
|
243
|
+
when ::FalseClass
|
244
|
+
["Custom False", false]
|
245
|
+
else
|
246
|
+
[obj, true]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
class TC_DBI_TypeUtil_Custom < Test::Unit::TestCase
|
251
|
+
def cast(obj)
|
252
|
+
DBI::TypeUtil.convert("test", obj)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_custom_casts
|
256
|
+
assert_equal("Custom Nil", cast(nil))
|
257
|
+
assert_equal("Custom True", cast(true))
|
258
|
+
assert_equal("Custom False", cast(false))
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_custom_fallthrough
|
262
|
+
assert_equal("'foo'", cast(:foo))
|
263
|
+
assert_equal("'foo'", cast("foo"))
|
264
|
+
assert_equal("'foo''bar'", cast("foo'bar"))
|
265
|
+
assert_equal("1", cast(1))
|
266
|
+
assert_equal("'foo'", cast(MyType.new("foo")))
|
267
|
+
end
|
268
|
+
end
|
data/test/ts_dbi.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Test suite for the DBI tests. No DBD tests are run as part of this
|
2
|
+
# test suite.
|
3
|
+
Dir.chdir("..") if File.basename(Dir.pwd) == "test"
|
4
|
+
$LOAD_PATH.unshift(Dir.pwd + "/lib")
|
5
|
+
Dir.chdir("test") rescue nil
|
6
|
+
|
7
|
+
require 'dbi/tc_columninfo'
|
8
|
+
require 'dbi/tc_date'
|
9
|
+
require 'dbi/tc_dbi'
|
10
|
+
require 'dbi/tc_row'
|
11
|
+
require 'dbi/tc_sqlbind'
|
12
|
+
require 'dbi/tc_statementhandle'
|
13
|
+
require 'dbi/tc_time'
|
14
|
+
require 'dbi/tc_timestamp'
|
15
|
+
require 'dbi/tc_types'
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-dbi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Raphael Costa
|
14
|
+
- Erik Hollensbe
|
15
|
+
- Christopher Maujean
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-08-10 00:00:00 -03:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: deprecated
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - "="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 13
|
32
|
+
segments:
|
33
|
+
- 2
|
34
|
+
- 0
|
35
|
+
- 1
|
36
|
+
version: 2.0.1
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
39
|
+
description: A vendor independent interface for accessing databases, similar to Perl's DBI compatible with Rails 3
|
40
|
+
email: ruby-dbi-users@rubyforge.org
|
41
|
+
executables:
|
42
|
+
- dbi
|
43
|
+
- test_broken_dbi
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README
|
48
|
+
- LICENSE
|
49
|
+
- ChangeLog
|
50
|
+
files:
|
51
|
+
- examples/test1.pl
|
52
|
+
- examples/test1.rb
|
53
|
+
- examples/xmltest.rb
|
54
|
+
- bin/dbi
|
55
|
+
- build/Rakefile.dbi.rb
|
56
|
+
- lib/dbi.rb
|
57
|
+
- lib/dbi/base_classes/database.rb
|
58
|
+
- lib/dbi/base_classes/driver.rb
|
59
|
+
- lib/dbi/base_classes/statement.rb
|
60
|
+
- lib/dbi/base_classes.rb
|
61
|
+
- lib/dbi/binary.rb
|
62
|
+
- lib/dbi/columninfo.rb
|
63
|
+
- lib/dbi/exceptions.rb
|
64
|
+
- lib/dbi/handles/database.rb
|
65
|
+
- lib/dbi/handles/driver.rb
|
66
|
+
- lib/dbi/handles/statement.rb
|
67
|
+
- lib/dbi/handles.rb
|
68
|
+
- lib/dbi/row.rb
|
69
|
+
- lib/dbi/sql/preparedstatement.rb
|
70
|
+
- lib/dbi/sql.rb
|
71
|
+
- lib/dbi/sql_type_constants.rb
|
72
|
+
- lib/dbi/trace.rb
|
73
|
+
- lib/dbi/types.rb
|
74
|
+
- lib/dbi/typeutil.rb
|
75
|
+
- lib/dbi/utils/date.rb
|
76
|
+
- lib/dbi/utils/tableformatter.rb
|
77
|
+
- lib/dbi/utils/time.rb
|
78
|
+
- lib/dbi/utils/timestamp.rb
|
79
|
+
- lib/dbi/utils/xmlformatter.rb
|
80
|
+
- lib/dbi/utils.rb
|
81
|
+
- test/ts_dbi.rb
|
82
|
+
- test/dbi/tc_columninfo.rb
|
83
|
+
- test/dbi/tc_date.rb
|
84
|
+
- test/dbi/tc_dbi.rb
|
85
|
+
- test/dbi/tc_row.rb
|
86
|
+
- test/dbi/tc_sqlbind.rb
|
87
|
+
- test/dbi/tc_statementhandle.rb
|
88
|
+
- test/dbi/tc_time.rb
|
89
|
+
- test/dbi/tc_timestamp.rb
|
90
|
+
- test/dbi/tc_types.rb
|
91
|
+
- README
|
92
|
+
- LICENSE
|
93
|
+
- ChangeLog
|
94
|
+
- bin/test_broken_dbi
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: http://www.rubyforge.org/projects/ruby-dbi
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 55
|
110
|
+
segments:
|
111
|
+
- 1
|
112
|
+
- 8
|
113
|
+
- 0
|
114
|
+
version: 1.8.0
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.3.7
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: A vendor independent interface for accessing databases, similar to Perl's DBI but compatible with Rails 3
|
131
|
+
test_files:
|
132
|
+
- test/ts_dbi.rb
|