sbf-data_objects 0.10.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog.markdown +115 -0
  3. data/LICENSE +20 -0
  4. data/README.markdown +18 -0
  5. data/Rakefile +20 -0
  6. data/lib/data_objects/byte_array.rb +6 -0
  7. data/lib/data_objects/command.rb +79 -0
  8. data/lib/data_objects/connection.rb +95 -0
  9. data/lib/data_objects/error/connection_error.rb +4 -0
  10. data/lib/data_objects/error/data_error.rb +4 -0
  11. data/lib/data_objects/error/integrity_error.rb +4 -0
  12. data/lib/data_objects/error/sql_error.rb +17 -0
  13. data/lib/data_objects/error/syntax_error.rb +4 -0
  14. data/lib/data_objects/error/transaction_error.rb +4 -0
  15. data/lib/data_objects/error.rb +4 -0
  16. data/lib/data_objects/extension.rb +9 -0
  17. data/lib/data_objects/logger.rb +247 -0
  18. data/lib/data_objects/pooling.rb +243 -0
  19. data/lib/data_objects/quoting.rb +99 -0
  20. data/lib/data_objects/reader.rb +45 -0
  21. data/lib/data_objects/result.rb +21 -0
  22. data/lib/data_objects/spec/lib/pending_helpers.rb +13 -0
  23. data/lib/data_objects/spec/lib/ssl.rb +19 -0
  24. data/lib/data_objects/spec/setup.rb +5 -0
  25. data/lib/data_objects/spec/shared/command_spec.rb +201 -0
  26. data/lib/data_objects/spec/shared/connection_spec.rb +148 -0
  27. data/lib/data_objects/spec/shared/encoding_spec.rb +161 -0
  28. data/lib/data_objects/spec/shared/error/sql_error_spec.rb +23 -0
  29. data/lib/data_objects/spec/shared/quoting_spec.rb +0 -0
  30. data/lib/data_objects/spec/shared/reader_spec.rb +180 -0
  31. data/lib/data_objects/spec/shared/result_spec.rb +67 -0
  32. data/lib/data_objects/spec/shared/typecast/array_spec.rb +29 -0
  33. data/lib/data_objects/spec/shared/typecast/bigdecimal_spec.rb +112 -0
  34. data/lib/data_objects/spec/shared/typecast/boolean_spec.rb +133 -0
  35. data/lib/data_objects/spec/shared/typecast/byte_array_spec.rb +76 -0
  36. data/lib/data_objects/spec/shared/typecast/class_spec.rb +53 -0
  37. data/lib/data_objects/spec/shared/typecast/date_spec.rb +114 -0
  38. data/lib/data_objects/spec/shared/typecast/datetime_spec.rb +140 -0
  39. data/lib/data_objects/spec/shared/typecast/float_spec.rb +115 -0
  40. data/lib/data_objects/spec/shared/typecast/integer_spec.rb +92 -0
  41. data/lib/data_objects/spec/shared/typecast/ipaddr_spec.rb +0 -0
  42. data/lib/data_objects/spec/shared/typecast/nil_spec.rb +107 -0
  43. data/lib/data_objects/spec/shared/typecast/other_spec.rb +41 -0
  44. data/lib/data_objects/spec/shared/typecast/range_spec.rb +29 -0
  45. data/lib/data_objects/spec/shared/typecast/string_spec.rb +130 -0
  46. data/lib/data_objects/spec/shared/typecast/time_spec.rb +111 -0
  47. data/lib/data_objects/transaction.rb +111 -0
  48. data/lib/data_objects/uri.rb +109 -0
  49. data/lib/data_objects/utilities.rb +18 -0
  50. data/lib/data_objects/version.rb +3 -0
  51. data/lib/data_objects.rb +20 -0
  52. data/spec/command_spec.rb +24 -0
  53. data/spec/connection_spec.rb +31 -0
  54. data/spec/do_mock.rb +29 -0
  55. data/spec/do_mock2.rb +29 -0
  56. data/spec/pooling_spec.rb +153 -0
  57. data/spec/reader_spec.rb +19 -0
  58. data/spec/result_spec.rb +21 -0
  59. data/spec/spec_helper.rb +18 -0
  60. data/spec/transaction_spec.rb +37 -0
  61. data/spec/uri_spec.rb +23 -0
  62. data/tasks/release.rake +14 -0
  63. data/tasks/spec.rake +10 -0
  64. data/tasks/yard.rake +9 -0
  65. data/tasks/yardstick.rake +19 -0
  66. metadata +122 -0
@@ -0,0 +1,112 @@
1
+ shared_examples 'supporting BigDecimal' 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 BigDecimal' do
15
+ describe 'with manual typecasting' do
16
+ before do
17
+ @command = @connection.create_command('SELECT cost1 FROM widgets WHERE ad_description = ?')
18
+ @command.set_types(BigDecimal)
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(BigDecimal)
30
+ end
31
+
32
+ it 'returns the correct result' do
33
+ # rounding seems necessary for the jruby do_derby driver
34
+ expect(@values.first.round(2)).to eq 10.23
35
+ end
36
+ end
37
+
38
+ describe 'with manual typecasting a nil value' do
39
+ before do
40
+ @command = @connection.create_command('SELECT cost2 FROM widgets WHERE id = ?')
41
+ @command.set_types(BigDecimal)
42
+ @reader = @command.execute_reader(6)
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 an Integer' do
62
+ before do
63
+ @reader = @connection.create_command('SELECT id FROM widgets WHERE id = ?').execute_reader(BigDecimal('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
+ expect(@values.first).to eq 2
74
+ end
75
+ end
76
+ end
77
+
78
+ shared_examples 'supporting BigDecimal autocasting' do
79
+ before :all do
80
+ setup_test_environment
81
+ end
82
+
83
+ before do
84
+ @connection = DataObjects::Connection.new(CONFIG.uri)
85
+ end
86
+
87
+ after do
88
+ @connection.close
89
+ end
90
+
91
+ describe 'reading a BigDecimal' do
92
+ describe 'with automatic typecasting' do
93
+ before do
94
+ @reader = @connection.create_command('SELECT cost2 FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
95
+ @reader.next!
96
+ @values = @reader.values
97
+ end
98
+
99
+ after do
100
+ @reader.close
101
+ end
102
+
103
+ it 'returns the correctly typed result' do
104
+ expect(@values.first).to be_kind_of(BigDecimal)
105
+ end
106
+
107
+ it 'returns the correct result' do
108
+ expect(@values.first).to eq 50.23
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,133 @@
1
+ shared_examples 'supporting Boolean' 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 Boolean' 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(TrueClass)
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(FalseClass)
30
+ end
31
+
32
+ it 'returns the correct result' do
33
+ expect(@values.first).to eq false
34
+ end
35
+ end
36
+
37
+ describe 'with manual typecasting a true value' do
38
+ before do
39
+ @command = @connection.create_command('SELECT flags FROM widgets WHERE id = ?')
40
+ @command.set_types(TrueClass)
41
+ @reader = @command.execute_reader(2)
42
+ @reader.next!
43
+ @values = @reader.values
44
+ end
45
+
46
+ after do
47
+ @reader.close
48
+ end
49
+
50
+ it 'returns the correctly typed result' do
51
+ expect(@values.first).to be_kind_of(TrueClass)
52
+ end
53
+
54
+ it 'returns the correct result' do
55
+ expect(@values.first).to be true
56
+ end
57
+ end
58
+
59
+ describe 'with manual typecasting a nil value' do
60
+ before do
61
+ @command = @connection.create_command('SELECT flags FROM widgets WHERE id = ?')
62
+ @command.set_types(TrueClass)
63
+ @reader = @command.execute_reader(4)
64
+ @reader.next!
65
+ @values = @reader.values
66
+ end
67
+
68
+ after do
69
+ @reader.close
70
+ end
71
+
72
+ it 'returns the correctly typed result' do
73
+ expect(@values.first).to be_kind_of(NilClass)
74
+ end
75
+
76
+ it 'returns the correct result' do
77
+ expect(@values.first).to be_nil
78
+ end
79
+ end
80
+ end
81
+
82
+ describe 'writing an Boolean' do
83
+ before do
84
+ @reader = @connection.create_command('SELECT id FROM widgets WHERE flags = ?').execute_reader(true)
85
+ @reader.next!
86
+ @values = @reader.values
87
+ end
88
+
89
+ after do
90
+ @reader.close
91
+ end
92
+
93
+ it 'returns the correct entry' do
94
+ expect(@values.first).to eq 2
95
+ end
96
+ end
97
+ end
98
+
99
+ shared_examples 'supporting Boolean autocasting' do
100
+ before :all do
101
+ setup_test_environment
102
+ end
103
+
104
+ before do
105
+ @connection = DataObjects::Connection.new(CONFIG.uri)
106
+ end
107
+
108
+ after do
109
+ @connection.close
110
+ end
111
+
112
+ describe 'reading a Boolean' do
113
+ describe 'with automatic typecasting' do
114
+ before do
115
+ @reader = @connection.create_command('SELECT flags FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
116
+ @reader.next!
117
+ @values = @reader.values
118
+ end
119
+
120
+ after do
121
+ @reader.close
122
+ end
123
+
124
+ it 'returns the correctly typed result' do
125
+ expect(@values.first).to be_kind_of(FalseClass)
126
+ end
127
+
128
+ it 'returns the correct result' do
129
+ expect(@values.first).to eq false
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,76 @@
1
+ shared_examples 'supporting ByteArray' 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 ByteArray' do
15
+ describe 'with automatic typecasting' do
16
+ before do
17
+ @reader = @connection.create_command('SELECT cad_drawing 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(Extlib::ByteArray)
28
+ end
29
+
30
+ it 'returns the correct result' do
31
+ expect(@values.first).to eq "CAD \001 \000 DRAWING"
32
+ end
33
+ end
34
+
35
+ describe 'with manual typecasting' do
36
+ before do
37
+ @command = @connection.create_command('SELECT cad_drawing FROM widgets WHERE ad_description = ?')
38
+ @command.set_types(Extlib::ByteArray)
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(Extlib::ByteArray)
50
+ end
51
+
52
+ it 'returns the correct result' do
53
+ expect(@values.first).to eq "CAD \001 \000 DRAWING"
54
+ end
55
+ end
56
+ end
57
+
58
+ describe 'writing a ByteArray' do
59
+ before do
60
+ @reader = @connection.create_command('SELECT ad_description FROM widgets WHERE cad_drawing = ?').execute_reader(
61
+ Extlib::ByteArray.new("CAD \001 \000 DRAWING")
62
+ )
63
+ @reader.next!
64
+ @values = @reader.values
65
+ end
66
+
67
+ after do
68
+ @reader.close
69
+ end
70
+
71
+ it 'returns the correct entry' do
72
+ # Some of the drivers starts auto-incrementation from 0 not 1
73
+ expect(@values.first).to eq 'Buy this product now!'
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,53 @@
1
+ shared_examples 'supporting Class' 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 Class' do
15
+ describe 'with manual typecasting' do
16
+ before do
17
+ @command = @connection.create_command('SELECT whitepaper_text FROM widgets WHERE ad_description = ?')
18
+ @command.set_types(Class)
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(Class)
30
+ end
31
+
32
+ it 'returns the correct result' do
33
+ expect(@values.first).to eq String
34
+ end
35
+ end
36
+ end
37
+
38
+ describe 'writing a Class' do
39
+ before do
40
+ @reader = @connection.create_command('SELECT whitepaper_text FROM widgets WHERE whitepaper_text = ?').execute_reader(String)
41
+ @reader.next!
42
+ @values = @reader.values
43
+ end
44
+
45
+ after do
46
+ @reader.close
47
+ end
48
+
49
+ it 'returns the correct entry' do
50
+ expect(@values.first).to eq 'String'
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,114 @@
1
+ shared_examples 'supporting Date' 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 Date' do
15
+ describe 'with manual typecasting' do
16
+ before do
17
+ @command = @connection.create_command('SELECT release_datetime FROM widgets WHERE ad_description = ?')
18
+ @command.set_types(Date)
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(Date)
30
+ end
31
+
32
+ it 'returns the correct result' do
33
+ expect(@values.first).to eq Date.civil(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_date FROM widgets WHERE id = ?')
40
+ @command.set_types(Date)
41
+ @reader = @command.execute_reader(7)
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 Date' do
61
+ before do
62
+ @reader = @connection.create_command('SELECT id FROM widgets WHERE release_date = ? ORDER BY id').execute_reader(Date.civil(
63
+ 2008, 2, 14
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 Date autocasting' do
81
+ before :all do
82
+ setup_test_environment
83
+ end
84
+
85
+ before do
86
+ @connection = DataObjects::Connection.new(CONFIG.uri)
87
+ end
88
+
89
+ after do
90
+ @connection.close
91
+ end
92
+
93
+ describe 'reading a Date' do
94
+ describe 'with automatic typecasting' do
95
+ before do
96
+ @reader = @connection.create_command('SELECT release_date FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
97
+ @reader.next!
98
+ @values = @reader.values
99
+ end
100
+
101
+ after do
102
+ @reader.close
103
+ end
104
+
105
+ it 'returns the correctly typed result' do
106
+ expect(@values.first).to be_kind_of(Date)
107
+ end
108
+
109
+ it 'returns the correct result' do
110
+ expect(@values.first).to eq Date.civil(2008, 2, 14)
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,140 @@
1
+ shared_examples 'supporting DateTime' 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 DateTime' do
15
+ describe 'with manual typecasting' do
16
+ before do
17
+ @command = @connection.create_command('SELECT release_datetime FROM widgets WHERE ad_description = ?')
18
+ @command.set_types(DateTime)
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(DateTime)
30
+ end
31
+
32
+ it 'returns the correct result' do
33
+ date = @values.first
34
+ local_offset = Rational(Time.local(2008, 2, 14).utc_offset, 86_400)
35
+ expect(date).to eq DateTime.civil(2008, 2, 14, 0o0, 31, 12, local_offset)
36
+ end
37
+ end
38
+
39
+ describe 'with manual typecasting a nil value' do
40
+ before do
41
+ @command = @connection.create_command('SELECT release_datetime FROM widgets WHERE id = ?')
42
+ @command.set_types(DateTime)
43
+ @reader = @command.execute_reader(8)
44
+ @reader.next!
45
+ @values = @reader.values
46
+ end
47
+
48
+ after do
49
+ @reader.close
50
+ end
51
+
52
+ it 'returns a nil class' do
53
+ expect(@values.first).to be_kind_of(NilClass)
54
+ end
55
+
56
+ it 'returns nil' do
57
+ expect(@values.first).to be_nil
58
+ end
59
+ end
60
+
61
+ describe 'with manual typecasting a datetime column' do
62
+ before do
63
+ @command = @connection.create_command('SELECT release_datetime FROM widgets WHERE id = ? OR id = ? ORDER BY id')
64
+ @command.set_types(DateTime)
65
+ @reader = @command.execute_reader(1, 10)
66
+ @reader.next!
67
+ @feb_row = @reader.values
68
+ @reader.next!
69
+ @jul_row = @reader.values
70
+ end
71
+
72
+ after do
73
+ @reader.close
74
+ end
75
+
76
+ it 'returns the correct offset in Feb' do
77
+ expect((@feb_row.first.offset * 86_400).to_i).to eq Time.local(2008, 2, 14, 0, 31, 12).utc_offset
78
+ end
79
+
80
+ it 'returns the correct offset in Jul' do
81
+ expect((@jul_row.first.offset * 86_400).to_i).to eq Time.local(2008, 7, 14, 0, 31, 12).utc_offset
82
+ end
83
+ end
84
+ end
85
+
86
+ describe 'writing an DateTime' do
87
+ before do
88
+ local_offset = Rational(Time.local(2008, 2, 14).utc_offset, 86_400)
89
+ @reader = @connection.create_command('SELECT id FROM widgets WHERE release_datetime = ? ORDER BY id')
90
+ .execute_reader(DateTime.civil(2008, 2, 14, 0o0, 31, 12, local_offset))
91
+ @reader.next!
92
+ @values = @reader.values
93
+ end
94
+
95
+ after do
96
+ @reader.close
97
+ end
98
+
99
+ it 'returns the correct entry' do
100
+ # Some of the drivers starts auto-incrementation from 0 not 1
101
+ expect(@values.first).to(satisfy { |val| [0, 1].include?(val) })
102
+ end
103
+ end
104
+ end
105
+
106
+ shared_examples 'supporting DateTime autocasting' do
107
+ before :all do
108
+ setup_test_environment
109
+ end
110
+
111
+ before do
112
+ @connection = DataObjects::Connection.new(CONFIG.uri)
113
+ end
114
+
115
+ after do
116
+ @connection.close
117
+ end
118
+
119
+ describe 'reading a DateTime' do
120
+ describe 'with automatic typecasting' do
121
+ before do
122
+ @reader = @connection.create_command('SELECT release_datetime FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
123
+ @reader.next!
124
+ @values = @reader.values
125
+ end
126
+
127
+ after do
128
+ @reader.close
129
+ end
130
+
131
+ it 'returns the correctly typed result' do
132
+ expect(@values.first).to be_kind_of(DateTime)
133
+ end
134
+
135
+ it 'returns the correct result' do
136
+ expect(@values.first).to eq Time.local(2008, 2, 14, 0o0, 31, 12).send(:to_datetime)
137
+ end
138
+ end
139
+ end
140
+ end