sbf-data_objects 0.10.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ChangeLog.markdown +115 -0
- data/LICENSE +20 -0
- data/README.markdown +18 -0
- data/Rakefile +20 -0
- data/lib/data_objects/byte_array.rb +6 -0
- data/lib/data_objects/command.rb +79 -0
- data/lib/data_objects/connection.rb +95 -0
- data/lib/data_objects/error/connection_error.rb +4 -0
- data/lib/data_objects/error/data_error.rb +4 -0
- data/lib/data_objects/error/integrity_error.rb +4 -0
- data/lib/data_objects/error/sql_error.rb +17 -0
- data/lib/data_objects/error/syntax_error.rb +4 -0
- data/lib/data_objects/error/transaction_error.rb +4 -0
- data/lib/data_objects/error.rb +4 -0
- data/lib/data_objects/extension.rb +9 -0
- data/lib/data_objects/logger.rb +247 -0
- data/lib/data_objects/pooling.rb +243 -0
- data/lib/data_objects/quoting.rb +99 -0
- data/lib/data_objects/reader.rb +45 -0
- data/lib/data_objects/result.rb +21 -0
- data/lib/data_objects/spec/lib/pending_helpers.rb +13 -0
- data/lib/data_objects/spec/lib/ssl.rb +19 -0
- data/lib/data_objects/spec/setup.rb +5 -0
- data/lib/data_objects/spec/shared/command_spec.rb +201 -0
- data/lib/data_objects/spec/shared/connection_spec.rb +148 -0
- data/lib/data_objects/spec/shared/encoding_spec.rb +161 -0
- data/lib/data_objects/spec/shared/error/sql_error_spec.rb +23 -0
- data/lib/data_objects/spec/shared/quoting_spec.rb +0 -0
- data/lib/data_objects/spec/shared/reader_spec.rb +180 -0
- data/lib/data_objects/spec/shared/result_spec.rb +67 -0
- data/lib/data_objects/spec/shared/typecast/array_spec.rb +29 -0
- data/lib/data_objects/spec/shared/typecast/bigdecimal_spec.rb +112 -0
- data/lib/data_objects/spec/shared/typecast/boolean_spec.rb +133 -0
- data/lib/data_objects/spec/shared/typecast/byte_array_spec.rb +76 -0
- data/lib/data_objects/spec/shared/typecast/class_spec.rb +53 -0
- data/lib/data_objects/spec/shared/typecast/date_spec.rb +114 -0
- data/lib/data_objects/spec/shared/typecast/datetime_spec.rb +140 -0
- data/lib/data_objects/spec/shared/typecast/float_spec.rb +115 -0
- data/lib/data_objects/spec/shared/typecast/integer_spec.rb +92 -0
- data/lib/data_objects/spec/shared/typecast/ipaddr_spec.rb +0 -0
- data/lib/data_objects/spec/shared/typecast/nil_spec.rb +107 -0
- data/lib/data_objects/spec/shared/typecast/other_spec.rb +41 -0
- data/lib/data_objects/spec/shared/typecast/range_spec.rb +29 -0
- data/lib/data_objects/spec/shared/typecast/string_spec.rb +130 -0
- data/lib/data_objects/spec/shared/typecast/time_spec.rb +111 -0
- data/lib/data_objects/transaction.rb +111 -0
- data/lib/data_objects/uri.rb +109 -0
- data/lib/data_objects/utilities.rb +18 -0
- data/lib/data_objects/version.rb +3 -0
- data/lib/data_objects.rb +20 -0
- data/spec/command_spec.rb +24 -0
- data/spec/connection_spec.rb +31 -0
- data/spec/do_mock.rb +29 -0
- data/spec/do_mock2.rb +29 -0
- data/spec/pooling_spec.rb +153 -0
- data/spec/reader_spec.rb +19 -0
- data/spec/result_spec.rb +21 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/transaction_spec.rb +37 -0
- data/spec/uri_spec.rb +23 -0
- data/tasks/release.rake +14 -0
- data/tasks/spec.rake +10 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +122 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
shared_examples 'supporting Float' do
|
2
|
+
before :all do
|
3
|
+
setup_test_environment
|
4
|
+
end
|
5
|
+
|
6
|
+
before do
|
7
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
@connection.close
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'reading a Float' do
|
15
|
+
describe 'with manual typecasting' do
|
16
|
+
before do
|
17
|
+
@command = @connection.create_command('SELECT id FROM widgets WHERE ad_description = ?')
|
18
|
+
@command.set_types(Float)
|
19
|
+
@reader = @command.execute_reader('Buy this product now!')
|
20
|
+
@reader.next!
|
21
|
+
@values = @reader.values
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
@reader.close
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns the correctly typed result' do
|
29
|
+
expect(@values.first).to be_kind_of(Float)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns the correct result' do
|
33
|
+
# Some of the drivers starts auto-incrementation from 0 not 1
|
34
|
+
expect(@values.first).to(satisfy { |val| [1.0, 0.0].include?(val) })
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'with manual typecasting a nil' do
|
39
|
+
before do
|
40
|
+
@command = @connection.create_command('SELECT cost1 FROM widgets WHERE id = ?')
|
41
|
+
@command.set_types(Float)
|
42
|
+
@reader = @command.execute_reader(5)
|
43
|
+
@reader.next!
|
44
|
+
@values = @reader.values
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
@reader.close
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns the correctly typed result' do
|
52
|
+
expect(@values.first).to be_kind_of(NilClass)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns the correct result' do
|
56
|
+
expect(@values.first).to be_nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'writing a Float' do
|
62
|
+
before do
|
63
|
+
@reader = @connection.create_command('SELECT id FROM widgets WHERE id = ?').execute_reader(2.0)
|
64
|
+
@reader.next!
|
65
|
+
@values = @reader.values
|
66
|
+
end
|
67
|
+
|
68
|
+
after do
|
69
|
+
@reader.close
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns the correct entry' do
|
73
|
+
# Some of the drivers starts auto-incrementation from 0 not 1
|
74
|
+
expect(@values.first).to(satisfy { |val| [1, 2].include?(val) })
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
shared_examples 'supporting Float autocasting' do
|
80
|
+
before :all do
|
81
|
+
setup_test_environment
|
82
|
+
end
|
83
|
+
|
84
|
+
before do
|
85
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
86
|
+
end
|
87
|
+
|
88
|
+
after do
|
89
|
+
@connection.close
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'reading a Float' do
|
93
|
+
describe 'with automatic typecasting' do
|
94
|
+
before do
|
95
|
+
@reader = @connection.create_command('SELECT weight, cost1 FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
|
96
|
+
@reader.next!
|
97
|
+
@values = @reader.values
|
98
|
+
end
|
99
|
+
|
100
|
+
after do
|
101
|
+
@reader.close
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'returns the correctly typed result' do
|
105
|
+
expect(@values.first).to be_kind_of(Float)
|
106
|
+
expect(@values.last).to be_kind_of(Float)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'returns the correct result' do
|
110
|
+
expect(@values.first).to eq 13.4
|
111
|
+
expect(BigDecimal(@values.last.to_s).round(2)).to eq 10.23
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
shared_examples 'supporting Integer' do
|
2
|
+
before :all do
|
3
|
+
setup_test_environment
|
4
|
+
end
|
5
|
+
|
6
|
+
before do
|
7
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
@connection.close
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'reading an Integer' do
|
15
|
+
describe 'with automatic typecasting' do
|
16
|
+
before do
|
17
|
+
@reader = @connection.create_command('SELECT id FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
|
18
|
+
@reader.next!
|
19
|
+
@values = @reader.values
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
@reader.close
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the correctly typed result' do
|
27
|
+
expect(@values.first).to be_kind_of(Integer)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the correct result' do
|
31
|
+
# Some of the drivers starts auto-incrementation from 0 not 1
|
32
|
+
expect(@values.first).to(satisfy { |val| [1, 0].include?(val) })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'with manual typecasting' do
|
37
|
+
before do
|
38
|
+
@command = @connection.create_command('SELECT weight FROM widgets WHERE ad_description = ?')
|
39
|
+
@command.set_types(Integer)
|
40
|
+
@reader = @command.execute_reader('Buy this product now!')
|
41
|
+
@reader.next!
|
42
|
+
@values = @reader.values
|
43
|
+
end
|
44
|
+
|
45
|
+
after do
|
46
|
+
@reader.close
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns the correctly typed result' do
|
50
|
+
expect(@values.first).to be_kind_of(Integer)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns the correct result' do
|
54
|
+
expect(@values.first).to eq 13
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'writing an Integer' do
|
60
|
+
before do
|
61
|
+
@reader = @connection.create_command('SELECT id FROM widgets WHERE id = ?').execute_reader(2)
|
62
|
+
@reader.next!
|
63
|
+
@values = @reader.values
|
64
|
+
end
|
65
|
+
|
66
|
+
after do
|
67
|
+
@reader.close
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns the correct entry' do
|
71
|
+
expect(@values.first).to eq 2
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'writing a big Integer' do
|
76
|
+
before do
|
77
|
+
@connection.create_command('UPDATE widgets SET super_number = ? WHERE id = 10')
|
78
|
+
.execute_non_query(2_147_483_648) # bigger than Integer.MAX in java !!
|
79
|
+
@reader = @connection.create_command('SELECT super_number FROM widgets WHERE id = ?').execute_reader(10)
|
80
|
+
@reader.next!
|
81
|
+
@values = @reader.values
|
82
|
+
end
|
83
|
+
|
84
|
+
after do
|
85
|
+
@reader.close
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'returns the correct entry' do
|
89
|
+
expect(@values.first).to eq 2_147_483_648
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
File without changes
|
@@ -0,0 +1,107 @@
|
|
1
|
+
shared_examples 'supporting Nil' do
|
2
|
+
before :all do
|
3
|
+
setup_test_environment
|
4
|
+
end
|
5
|
+
|
6
|
+
before do
|
7
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
@connection.close
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'reading a Nil' do
|
15
|
+
describe 'with manual typecasting' do
|
16
|
+
before do
|
17
|
+
@command = @connection.create_command('SELECT flags FROM widgets WHERE ad_description = ?')
|
18
|
+
@command.set_types(NilClass)
|
19
|
+
@reader = @command.execute_reader('Buy this product now!')
|
20
|
+
@reader.next!
|
21
|
+
@values = @reader.values
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
@reader.close
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns the correctly typed result' do
|
29
|
+
expect(@values.first).to be_kind_of(NilClass)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns the correct result' do
|
33
|
+
expect(@values.first).to be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
shared_examples 'supporting writing an Nil' do
|
40
|
+
before :all do
|
41
|
+
setup_test_environment
|
42
|
+
end
|
43
|
+
|
44
|
+
before do
|
45
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
46
|
+
end
|
47
|
+
|
48
|
+
after do
|
49
|
+
@connection.close
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'supporting writing an Nil' do
|
53
|
+
# see as an example oracle
|
54
|
+
# http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements005.htm#sthref487
|
55
|
+
# http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions013.htm#i1050801
|
56
|
+
|
57
|
+
describe 'as a parameter' do
|
58
|
+
before do
|
59
|
+
@reader = @connection.create_command('SELECT id FROM widgets WHERE ad_description IN (?) ORDER BY id').execute_reader(nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
after do
|
63
|
+
@reader.close
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns the correct entry' do
|
67
|
+
expect(@reader.next!).to be false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
shared_examples 'supporting Nil autocasting' do
|
74
|
+
before :all do
|
75
|
+
setup_test_environment
|
76
|
+
end
|
77
|
+
|
78
|
+
before do
|
79
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
80
|
+
end
|
81
|
+
|
82
|
+
after do
|
83
|
+
@connection.close
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'reading a Nil' do
|
87
|
+
describe 'with automatic typecasting' do
|
88
|
+
before do
|
89
|
+
@reader = @connection.create_command('SELECT ad_description FROM widgets WHERE id = ?').execute_reader(3)
|
90
|
+
@reader.next!
|
91
|
+
@values = @reader.values
|
92
|
+
end
|
93
|
+
|
94
|
+
after do
|
95
|
+
@reader.close
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'returns the correctly typed result' do
|
99
|
+
expect(@values.first).to be_kind_of(NilClass)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns the correct result' do
|
103
|
+
expect(@values.first).to be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class ::CustomTextType
|
2
|
+
def initialize(value)
|
3
|
+
@value = value
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_s
|
7
|
+
@value.to_s
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples 'supporting other (unknown) type' do
|
12
|
+
before :all do
|
13
|
+
setup_test_environment
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'writing an object of unknown type' do
|
17
|
+
before do
|
18
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
@connection.close
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
@command = @connection.create_command('SELECT ad_description FROM widgets WHERE ad_description = ?')
|
27
|
+
@command.set_types(CustomTextType)
|
28
|
+
@reader = @command.execute_reader('Buy this product now!')
|
29
|
+
@reader.next!
|
30
|
+
@values = @reader.values
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
@reader.close
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns the correct entry' do
|
38
|
+
expect(@values.first).to eq 'Buy this product now!'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
shared_examples 'supporting Range' do
|
2
|
+
before :all do
|
3
|
+
setup_test_environment
|
4
|
+
end
|
5
|
+
|
6
|
+
before do
|
7
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
@connection.close
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'passing a Range as a parameter in execute_reader' do
|
15
|
+
before do
|
16
|
+
@reader = @connection.create_command('SELECT * FROM widgets WHERE id between ?').execute_reader(2..5)
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
@reader.close
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns correct number of rows' do
|
24
|
+
counter = 0
|
25
|
+
counter += 1 while @reader.next!
|
26
|
+
expect(counter).to eq 4
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
shared_examples 'supporting String' do
|
2
|
+
before :all do
|
3
|
+
setup_test_environment
|
4
|
+
end
|
5
|
+
|
6
|
+
before do
|
7
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
@connection.close
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'reading a String' do
|
15
|
+
describe 'with automatic typecasting' do
|
16
|
+
before do
|
17
|
+
@reader = @connection.create_command('SELECT code FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
|
18
|
+
@reader.next!
|
19
|
+
@values = @reader.values
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
@reader.close
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the correctly typed result' do
|
27
|
+
expect(@values.first).to be_kind_of(String)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the correct result' do
|
31
|
+
expect(@values.first).to eq 'W0000001'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'with manual typecasting' do
|
36
|
+
before do
|
37
|
+
@command = @connection.create_command('SELECT number_sold FROM widgets WHERE ad_description = ?')
|
38
|
+
@command.set_types(String)
|
39
|
+
@reader = @command.execute_reader('Buy this product now!')
|
40
|
+
@reader.next!
|
41
|
+
@values = @reader.values
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
@reader.close
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns the correctly typed result' do
|
49
|
+
expect(@values.first).to be_kind_of(String)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns the correct result' do
|
53
|
+
expect(@values.first).to eq '0'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'writing a String' do
|
59
|
+
before do
|
60
|
+
@reader = @connection.create_command('SELECT id FROM widgets WHERE id = ?').execute_reader('2')
|
61
|
+
@reader.next!
|
62
|
+
@values = @reader.values
|
63
|
+
end
|
64
|
+
|
65
|
+
after do
|
66
|
+
@reader.close
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns the correct entry' do
|
70
|
+
# Some of the drivers starts auto-incrementation from 0 not 1
|
71
|
+
expect(@values.first).to(satisfy { |val| [1, 2].include?(val) })
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'writing and reading a multibyte String' do
|
76
|
+
['Aslak Hellesøy',
|
77
|
+
'Пётр Алексе́евич Рома́нов',
|
78
|
+
'歐陽龍'].each do |name|
|
79
|
+
before do
|
80
|
+
# SQL Server Unicode String Literals
|
81
|
+
@n = 'N' if defined?(DataObjects::SqlServer::Connection) && @connection.is_a?(DataObjects::SqlServer::Connection)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'writes a multibyte String' do
|
85
|
+
@command = @connection.create_command('INSERT INTO users (name) VALUES(?)')
|
86
|
+
expect { @command.execute_non_query(name) }.not_to raise_error
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'reads back the multibyte String' do
|
90
|
+
@command = @connection.create_command('SELECT name FROM users WHERE name = ?')
|
91
|
+
@reader = @command.execute_reader(name)
|
92
|
+
@reader.next!
|
93
|
+
expect(@reader.values.first).to eq name
|
94
|
+
@reader.close
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'writes a multibyte String (without query parameters)' do
|
98
|
+
@command = @connection.create_command("INSERT INTO users (name) VALUES(#{@n}'#{name}')")
|
99
|
+
expect { @command.execute_non_query }.not_to raise_error
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'reads back the multibyte String (without query parameters)' do
|
103
|
+
@command = @connection.create_command("SELECT name FROM users WHERE name = #{@n}'#{name}'")
|
104
|
+
@reader = @command.execute_reader
|
105
|
+
@reader.next!
|
106
|
+
expect(@reader.values.first).to eq name
|
107
|
+
@reader.close
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class ::StringWithExtraPowers < String; end
|
113
|
+
|
114
|
+
describe 'writing a kind of (subclass of) String' do
|
115
|
+
before do
|
116
|
+
@reader = @connection.create_command('SELECT id FROM widgets WHERE id = ?').execute_reader(StringWithExtraPowers.new('2'))
|
117
|
+
@reader.next!
|
118
|
+
@values = @reader.values
|
119
|
+
end
|
120
|
+
|
121
|
+
after do
|
122
|
+
@reader.close
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns the correct entry' do
|
126
|
+
# Some of the drivers starts auto-incrementation from 0 not 1
|
127
|
+
expect(@values.first).to(satisfy { |val| [1, 2].include?(val) })
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
shared_examples 'supporting Time' do
|
2
|
+
before :all do
|
3
|
+
setup_test_environment
|
4
|
+
end
|
5
|
+
|
6
|
+
before do
|
7
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
@connection.close
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'reading a Time' do
|
15
|
+
describe 'with manual typecasting' do
|
16
|
+
before do
|
17
|
+
@command = @connection.create_command('SELECT release_date FROM widgets WHERE ad_description = ?')
|
18
|
+
@command.set_types(Time)
|
19
|
+
@reader = @command.execute_reader('Buy this product now!')
|
20
|
+
@reader.next!
|
21
|
+
@values = @reader.values
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
@reader.close
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns the correctly typed result' do
|
29
|
+
expect(@values.first).to be_kind_of(Time)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns the correct result' do
|
33
|
+
expect(@values.first).to eq Time.local(2008, 2, 14)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'with manual typecasting a nil value' do
|
38
|
+
before do
|
39
|
+
@command = @connection.create_command('SELECT release_timestamp FROM widgets WHERE id = ?')
|
40
|
+
@command.set_types(Time)
|
41
|
+
@reader = @command.execute_reader(9)
|
42
|
+
@reader.next!
|
43
|
+
@values = @reader.values
|
44
|
+
end
|
45
|
+
|
46
|
+
after do
|
47
|
+
@reader.close
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns a nil class' do
|
51
|
+
expect(@values.first).to be_kind_of(NilClass)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns nil' do
|
55
|
+
expect(@values.first).to be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'writing an Time' do
|
61
|
+
before do
|
62
|
+
@reader = @connection.create_command('SELECT id FROM widgets WHERE release_datetime = ? ORDER BY id').execute_reader(Time.local(
|
63
|
+
2008, 2, 14, 0o0, 31, 12
|
64
|
+
))
|
65
|
+
@reader.next!
|
66
|
+
@values = @reader.values
|
67
|
+
end
|
68
|
+
|
69
|
+
after do
|
70
|
+
@reader.close
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns the correct entry' do
|
74
|
+
# Some of the drivers starts auto-incrementation from 0 not 1
|
75
|
+
expect(@values.first).to(satisfy { |val| [1, 0].include?(val) })
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
shared_examples 'supporting sub second Time' do
|
81
|
+
before :all do
|
82
|
+
setup_test_environment
|
83
|
+
end
|
84
|
+
|
85
|
+
before do
|
86
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
87
|
+
@connection.create_command(<<-EOF).execute_non_query(Time.parse('2010-12-15 14:32:08.49377-08').localtime)
|
88
|
+
update widgets set release_timestamp = ? where id = 1
|
89
|
+
EOF
|
90
|
+
@connection.create_command(<<-EOF).execute_non_query(Time.parse('2010-12-15 14:32:28.942694-08').localtime)
|
91
|
+
update widgets set release_timestamp = ? where id = 2
|
92
|
+
EOF
|
93
|
+
|
94
|
+
@command = @connection.create_command('SELECT release_timestamp FROM widgets WHERE id < ? order by id')
|
95
|
+
@command.set_types(Time)
|
96
|
+
@reader = @command.execute_reader(3)
|
97
|
+
@reader.next!
|
98
|
+
@values = @reader.values
|
99
|
+
end
|
100
|
+
|
101
|
+
after do
|
102
|
+
@connection.close
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'handles variable subsecond lengths properly' do
|
106
|
+
expect(@values.first.to_f).to be_within(0.00002).of(Time.at(1_292_452_328, 493_770).to_f)
|
107
|
+
@reader.next!
|
108
|
+
@values = @reader.values
|
109
|
+
expect(@values.first.to_f).to be_within(0.00002).of(Time.at(1_292_452_348, 942_694).to_f)
|
110
|
+
end
|
111
|
+
end
|