sbf-do_mysql 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 +116 -0
- data/LICENSE +20 -0
- data/README.markdown +100 -0
- data/Rakefile +25 -0
- data/ext/do_mysql/compat.h +55 -0
- data/ext/do_mysql/do_common.c +510 -0
- data/ext/do_mysql/do_common.h +132 -0
- data/ext/do_mysql/do_mysql.c +691 -0
- data/ext/do_mysql/error.h +403 -0
- data/ext/do_mysql/extconf.rb +87 -0
- data/ext/do_mysql/mysql_compat.h +25 -0
- data/lib/do_mysql/encoding.rb +39 -0
- data/lib/do_mysql/transaction.rb +31 -0
- data/lib/do_mysql/version.rb +5 -0
- data/lib/do_mysql.rb +24 -0
- data/spec/command_spec.rb +7 -0
- data/spec/connection_spec.rb +55 -0
- data/spec/encoding_spec.rb +46 -0
- data/spec/error/sql_error_spec.rb +6 -0
- data/spec/reader_spec.rb +29 -0
- data/spec/result_spec.rb +38 -0
- data/spec/spec_helper.rb +242 -0
- data/spec/typecast/array_spec.rb +6 -0
- data/spec/typecast/bigdecimal_spec.rb +7 -0
- data/spec/typecast/boolean_spec.rb +7 -0
- data/spec/typecast/byte_array_spec.rb +6 -0
- data/spec/typecast/class_spec.rb +6 -0
- data/spec/typecast/date_spec.rb +30 -0
- data/spec/typecast/datetime_spec.rb +30 -0
- data/spec/typecast/float_spec.rb +7 -0
- data/spec/typecast/integer_spec.rb +6 -0
- data/spec/typecast/nil_spec.rb +8 -0
- data/spec/typecast/other_spec.rb +6 -0
- data/spec/typecast/range_spec.rb +6 -0
- data/spec/typecast/string_spec.rb +6 -0
- data/spec/typecast/time_spec.rb +6 -0
- data/tasks/compile.rake +16 -0
- data/tasks/release.rake +14 -0
- data/tasks/retrieve.rake +20 -0
- data/tasks/spec.rake +10 -0
- data/tasks/ssl.rake +26 -0
- metadata +101 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/encoding_spec'
|
3
|
+
|
4
|
+
describe DataObjects::Mysql::Connection do
|
5
|
+
it_behaves_like 'a driver supporting different encodings'
|
6
|
+
it_behaves_like 'returning correctly encoded strings for the default database encoding'
|
7
|
+
it_behaves_like 'returning correctly encoded strings for the default internal encoding'
|
8
|
+
|
9
|
+
describe 'sets the character set through the URI' do
|
10
|
+
before do
|
11
|
+
@utf8mb4_connection = DataObjects::Connection.new(
|
12
|
+
"#{CONFIG.scheme}://#{CONFIG.user}:#{CONFIG.pass}@#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}?encoding=UTF-8-MB4"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
after { @utf8mb4_connection.close }
|
17
|
+
|
18
|
+
it { expect(@utf8mb4_connection.character_set).to eq 'UTF-8-MB4' }
|
19
|
+
|
20
|
+
describe 'writing a multibyte String' do
|
21
|
+
it 'writes a multibyte String' do
|
22
|
+
@command = @utf8mb4_connection.create_command('INSERT INTO users_mb4 (name) VALUES(?)')
|
23
|
+
expect { @command.execute_non_query('😀') }.not_to raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'reading a String' do
|
28
|
+
before do
|
29
|
+
@reader = @utf8mb4_connection.create_command('SELECT name FROM users_mb4').execute_reader
|
30
|
+
@reader.next!
|
31
|
+
@values = @reader.values
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
@reader.close
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns a UTF-8 encoded String' do
|
39
|
+
expect(@values.first).to be_kind_of(String)
|
40
|
+
expect(@values.first.encoding.name).to eq 'UTF-8'
|
41
|
+
expect(@values.first).to eq '😀'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
# rubocop:enable Metrics/BlockLength
|
data/spec/reader_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/reader_spec'
|
3
|
+
|
4
|
+
describe DataObjects::Mysql::Reader do
|
5
|
+
it_behaves_like 'a Reader'
|
6
|
+
|
7
|
+
describe 'reading database metadata' do
|
8
|
+
subject { reader }
|
9
|
+
|
10
|
+
let(:connection) { DataObjects::Connection.new(CONFIG.uri) }
|
11
|
+
let(:command) { connection.create_command(sql) }
|
12
|
+
let(:reader) { command.execute_reader }
|
13
|
+
|
14
|
+
after do
|
15
|
+
reader.close
|
16
|
+
connection.close
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'showing correct column field names for a table' do
|
20
|
+
let(:sql) { 'SHOW COLUMNS FROM `widgets`' }
|
21
|
+
its(:fields) { is_expected.to eq %w(Field Type Null Key Default Extra) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'showing correct column field names for variables' do
|
25
|
+
let(:sql) { "SHOW VARIABLES LIKE 'character_set_connection'" }
|
26
|
+
its(:fields) { is_expected.to eq %w(Variable_name Value) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/result_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/result_spec'
|
3
|
+
|
4
|
+
# splitting the describe into two separate declaration avoids
|
5
|
+
# concurrent execution of the "it_behaves_like ....."
|
6
|
+
# needed by some databases (sqlite3)
|
7
|
+
|
8
|
+
describe DataObjects::Mysql::Result do
|
9
|
+
it_behaves_like 'a Result'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe DataObjects::Mysql::Result do
|
13
|
+
it_behaves_like 'a Result which returns inserted key with sequences'
|
14
|
+
it_behaves_like 'a Result which returns nil without sequences'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe DataObjects::Mysql::Result do
|
18
|
+
describe 'insert_id' do
|
19
|
+
before do
|
20
|
+
setup_test_environment
|
21
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
22
|
+
# set the sequence to a value larger than SQL integer
|
23
|
+
command = @connection.create_command('INSERT INTO stuff (id, value) VALUES (?,?)')
|
24
|
+
command.execute_non_query(3_000_000_000, 'cow')
|
25
|
+
# use the sequence to generate an id
|
26
|
+
command = @connection.create_command('INSERT INTO stuff (value) VALUES (?)')
|
27
|
+
@result = command.execute_non_query('monkey')
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
@connection.close
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns the bigint id' do
|
35
|
+
expect(@result.insert_id).to eq 3_000_000_001
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
# rubocop:disable Style/GlobalVars
|
2
|
+
$TESTING = true
|
3
|
+
# rubocop:enable Style/GlobalVars
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec/its'
|
8
|
+
require 'date'
|
9
|
+
require 'ostruct'
|
10
|
+
require 'fileutils'
|
11
|
+
require 'win32console' if RUBY_PLATFORM =~ /mingw|mswin/
|
12
|
+
|
13
|
+
driver_lib = File.expand_path('../lib', __dir__)
|
14
|
+
$LOAD_PATH.unshift(driver_lib) unless $LOAD_PATH.include?(driver_lib)
|
15
|
+
|
16
|
+
# Prepend data_objects/do_jdbc in the repository to the load path.
|
17
|
+
# DO NOT USE installed gems, except when running the specs from gem.
|
18
|
+
repo_root = File.expand_path('../..', __dir__)
|
19
|
+
|
20
|
+
lib_path = "#{repo_root}/data_objects/lib"
|
21
|
+
$LOAD_PATH.unshift(lib_path) if File.directory?(lib_path) && !$LOAD_PATH.include?(lib_path)
|
22
|
+
|
23
|
+
require 'data_objects'
|
24
|
+
require 'data_objects/spec/setup'
|
25
|
+
require 'data_objects/spec/lib/ssl'
|
26
|
+
require 'data_objects/spec/lib/pending_helpers'
|
27
|
+
require 'do_mysql'
|
28
|
+
|
29
|
+
DataObjects::Mysql.logger = DataObjects::Logger.new($stdout, :off)
|
30
|
+
at_exit { DataObjects.logger.flush }
|
31
|
+
|
32
|
+
CONFIG = OpenStruct.new
|
33
|
+
CONFIG.scheme = 'mysql'
|
34
|
+
CONFIG.user = ENV['DO_MYSQL_USER'] || 'root'
|
35
|
+
CONFIG.pass = ENV['DO_MYSQL_PASS'] || ''
|
36
|
+
CONFIG.user_info = if CONFIG.user == 'root' && CONFIG.pass.empty?
|
37
|
+
''
|
38
|
+
else
|
39
|
+
"#{CONFIG.user}:#{CONFIG.pass}@"
|
40
|
+
end
|
41
|
+
CONFIG.host = ENV['DO_MYSQL_HOST'] || 'localhost'
|
42
|
+
CONFIG.port = ENV['DO_MYSQL_PORT'] || '3306'
|
43
|
+
CONFIG.database = ENV['DO_MYSQL_DATABASE'] || '/do_test'
|
44
|
+
CONFIG.ssl = SSLHelpers.query(:ca_cert, :client_cert, :client_key)
|
45
|
+
|
46
|
+
CONFIG.driver = 'mysql'
|
47
|
+
CONFIG.uri = ENV['DO_MYSQL_SPEC_URI'] ||
|
48
|
+
"#{CONFIG.scheme}://#{CONFIG.user_info}#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}?zeroDateTimeBehavior=convertToNull"
|
49
|
+
CONFIG.sleep = 'SELECT sleep(1)'
|
50
|
+
|
51
|
+
module DataObjectsSpecHelpers
|
52
|
+
# rubocop:disable Metrics/MethodLength
|
53
|
+
def setup_test_environment
|
54
|
+
conn = DataObjects::Connection.new(CONFIG.uri)
|
55
|
+
|
56
|
+
conn.create_command(<<-EOF).execute_non_query
|
57
|
+
DROP TABLE IF EXISTS `invoices`
|
58
|
+
EOF
|
59
|
+
|
60
|
+
conn.create_command(<<-EOF).execute_non_query
|
61
|
+
DROP TABLE IF EXISTS `users`
|
62
|
+
EOF
|
63
|
+
|
64
|
+
conn.create_command(<<-EOF).execute_non_query
|
65
|
+
DROP TABLE IF EXISTS `users_mb4`
|
66
|
+
EOF
|
67
|
+
|
68
|
+
conn.create_command(<<-EOF).execute_non_query
|
69
|
+
DROP TABLE IF EXISTS `stuff`
|
70
|
+
EOF
|
71
|
+
|
72
|
+
conn.create_command(<<-EOF).execute_non_query
|
73
|
+
DROP TABLE IF EXISTS `widgets`
|
74
|
+
EOF
|
75
|
+
|
76
|
+
conn.create_command(<<-EOF).execute_non_query
|
77
|
+
CREATE TABLE `users` (
|
78
|
+
`id` int(11) NOT NULL auto_increment,
|
79
|
+
`name` varchar(200) default 'Billy' NULL,
|
80
|
+
`fired_at` timestamp,
|
81
|
+
PRIMARY KEY (`id`)
|
82
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
83
|
+
EOF
|
84
|
+
|
85
|
+
conn.create_command(<<-EOF).execute_non_query
|
86
|
+
CREATE TABLE `users_mb4` (
|
87
|
+
`id` int(11) NOT NULL auto_increment,
|
88
|
+
`name` varchar(200),
|
89
|
+
PRIMARY KEY (`id`)
|
90
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
91
|
+
EOF
|
92
|
+
|
93
|
+
conn.create_command(<<-EOF).execute_non_query
|
94
|
+
CREATE TABLE `invoices` (
|
95
|
+
`invoice_number` varchar(50) NOT NULL,
|
96
|
+
PRIMARY KEY (`invoice_number`)
|
97
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
98
|
+
EOF
|
99
|
+
|
100
|
+
conn.create_command(<<-EOF).execute_non_query
|
101
|
+
CREATE TABLE `stuff` (
|
102
|
+
`id` bigint NOT NULL auto_increment,
|
103
|
+
`value` varchar(50) NULL,
|
104
|
+
PRIMARY KEY (`id`)
|
105
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
106
|
+
EOF
|
107
|
+
|
108
|
+
conn.create_command(<<-EOF).execute_non_query
|
109
|
+
CREATE TABLE `widgets` (
|
110
|
+
`id` int(11) NOT NULL auto_increment,
|
111
|
+
`code` char(8) default 'A14' NULL,
|
112
|
+
`name` varchar(200) default 'Super Widget' NULL,
|
113
|
+
`shelf_location` tinytext NULL,
|
114
|
+
`description` text NULL,
|
115
|
+
`image_data` blob NULL,
|
116
|
+
`ad_description` mediumtext NULL,
|
117
|
+
`ad_image` mediumblob NULL,
|
118
|
+
`whitepaper_text` longtext NULL,
|
119
|
+
`cad_drawing` longblob NULL,
|
120
|
+
`flags` boolean default false,
|
121
|
+
`number_in_stock` smallint default 500,
|
122
|
+
`number_sold` mediumint default 0,
|
123
|
+
`super_number` bigint default 9223372036854775807,
|
124
|
+
`weight` float default 1.23,
|
125
|
+
`cost1` double default 10.23,
|
126
|
+
`cost2` decimal(8,2) default 50.23,
|
127
|
+
`release_date` date default '2008-02-14',
|
128
|
+
`release_datetime` datetime default '2008-02-14 00:31:12',
|
129
|
+
`release_timestamp` timestamp NULL default '2008-02-14 00:31:31',
|
130
|
+
`status` enum('active','out of stock') NOT NULL default 'active',
|
131
|
+
PRIMARY KEY (`id`)
|
132
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
133
|
+
EOF
|
134
|
+
|
135
|
+
1.upto(16) do |n|
|
136
|
+
conn.create_command(<<-EOF).execute_non_query
|
137
|
+
insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number, weight) VALUES ('W#{n.to_s.rjust(7, '0')}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'String', 'CAD \001 \000 DRAWING', 1234, 13.4);
|
138
|
+
EOF
|
139
|
+
end
|
140
|
+
|
141
|
+
conn.create_command(<<-EOF).execute_non_query
|
142
|
+
update widgets set flags = true where id = 2
|
143
|
+
EOF
|
144
|
+
|
145
|
+
conn.create_command(<<-EOF).execute_non_query
|
146
|
+
update widgets set ad_description = NULL where id = 3
|
147
|
+
EOF
|
148
|
+
|
149
|
+
conn.create_command(<<-EOF).execute_non_query
|
150
|
+
update widgets set flags = NULL where id = 4
|
151
|
+
EOF
|
152
|
+
|
153
|
+
conn.create_command(<<-EOF).execute_non_query
|
154
|
+
update widgets set cost1 = NULL where id = 5
|
155
|
+
EOF
|
156
|
+
|
157
|
+
conn.create_command(<<-EOF).execute_non_query
|
158
|
+
update widgets set cost2 = NULL where id = 6
|
159
|
+
EOF
|
160
|
+
|
161
|
+
conn.create_command(<<-EOF).execute_non_query
|
162
|
+
update widgets set release_date = NULL where id = 7
|
163
|
+
EOF
|
164
|
+
|
165
|
+
conn.create_command(<<-EOF).execute_non_query
|
166
|
+
update widgets set release_datetime = NULL where id = 8
|
167
|
+
EOF
|
168
|
+
|
169
|
+
conn.create_command(<<-EOF).execute_non_query
|
170
|
+
update widgets set release_timestamp = NULL where id = 9
|
171
|
+
EOF
|
172
|
+
|
173
|
+
conn.create_command(<<-EOF).execute_non_query
|
174
|
+
update widgets set release_datetime = '2008-07-14 00:31:12' where id = 10
|
175
|
+
EOF
|
176
|
+
|
177
|
+
conn.close
|
178
|
+
end
|
179
|
+
# rubocop:enable Metrics/MethodLength
|
180
|
+
|
181
|
+
def self.test_environment_ssl_config
|
182
|
+
ssl_config = SSLHelpers::CONFIG
|
183
|
+
|
184
|
+
message = "\nYou can configure MySQL via my.cnf with the following options in [mysqld]:\n"
|
185
|
+
message << "ssl_ca=#{ssl_config.ca_cert}\n"
|
186
|
+
message << "ssl_cert=#{ssl_config.server_cert}\n"
|
187
|
+
message << "ssl_key=#{ssl_config.server_key}\n"
|
188
|
+
message << "ssl_cipher=#{ssl_config.cipher}\n"
|
189
|
+
|
190
|
+
message << "\nOr you can use the following command line options:\n"
|
191
|
+
message << "--ssl-ca #{ssl_config.ca_cert} "
|
192
|
+
message << "--ssl-cert #{ssl_config.server_cert} "
|
193
|
+
message << "--ssl-key #{ssl_config.server_key} "
|
194
|
+
message << "--ssl-cipher #{ssl_config.cipher} "
|
195
|
+
message
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.test_environment_ssl_config_errors
|
199
|
+
conn = DataObjects::Connection.new(CONFIG.uri)
|
200
|
+
|
201
|
+
ssl_variables = conn.create_command(<<-EOF).execute_reader
|
202
|
+
SHOW VARIABLES LIKE '%ssl%'
|
203
|
+
EOF
|
204
|
+
|
205
|
+
ssl_config = SSLHelpers::CONFIG
|
206
|
+
current_config = {}
|
207
|
+
|
208
|
+
while ssl_variables.next!
|
209
|
+
variable, value = ssl_variables.values
|
210
|
+
current_config[variable.intern] = value
|
211
|
+
end
|
212
|
+
|
213
|
+
errors = []
|
214
|
+
|
215
|
+
errors << 'SSL was not compiled' if current_config[:have_ssl] == 'NO'
|
216
|
+
|
217
|
+
errors << 'SSL was not enabled' if current_config[:have_ssl] == 'DISABLED'
|
218
|
+
|
219
|
+
errors << "The CA certificate is not configured (it was set to '#{current_config[:ssl_ca]}')" if current_config[:ssl_ca] != ssl_config.ca_cert
|
220
|
+
|
221
|
+
if current_config[:ssl_cert] != ssl_config.server_cert
|
222
|
+
errors << "The server certificate is not configured (it was set to '#{current_config[:ssl_cert]}')"
|
223
|
+
end
|
224
|
+
|
225
|
+
errors << "The server key is not configured, (it was set to '#{current_config[:ssl_key]}')" if current_config[:ssl_key] != ssl_config.server_key
|
226
|
+
|
227
|
+
errors << "The cipher is not configured, (it was set to '#{current_config[:ssl_cipher]}')" if current_config[:ssl_cipher] != ssl_config.cipher
|
228
|
+
|
229
|
+
errors
|
230
|
+
ensure
|
231
|
+
conn.close
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.test_environment_supports_ssl?
|
235
|
+
test_environment_ssl_config_errors.empty?
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
RSpec.configure do |config|
|
240
|
+
config.include(DataObjectsSpecHelpers)
|
241
|
+
config.include(DataObjects::Spec::PendingHelpers)
|
242
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/typecast/bigdecimal_spec'
|
3
|
+
|
4
|
+
describe 'DataObjects::Mysql with BigDecimal' do
|
5
|
+
it_behaves_like 'supporting BigDecimal'
|
6
|
+
it_behaves_like 'supporting BigDecimal autocasting'
|
7
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/typecast/boolean_spec'
|
3
|
+
|
4
|
+
describe 'DataObjects::Mysql with Boolean' do
|
5
|
+
it_behaves_like 'supporting Boolean'
|
6
|
+
it_behaves_like 'supporting Boolean autocasting'
|
7
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/typecast/date_spec'
|
3
|
+
|
4
|
+
describe 'DataObjects::Mysql with Date' do
|
5
|
+
it_behaves_like 'supporting Date'
|
6
|
+
it_behaves_like 'supporting Date autocasting'
|
7
|
+
|
8
|
+
describe 'reading 0000-00-00' do
|
9
|
+
before do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
|
12
|
+
@connection.create_command("SET SESSION sql_mode = 'ALLOW_INVALID_DATES'").execute_non_query
|
13
|
+
@connection.create_command("INSERT INTO widgets (release_date) VALUES ('')").execute_non_query
|
14
|
+
|
15
|
+
@command = @connection.create_command("SELECT release_date FROM widgets WHERE release_date = '0000-00-00'")
|
16
|
+
@reader = @command.execute_reader
|
17
|
+
@reader.next!
|
18
|
+
@values = @reader.values
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
@reader.close
|
23
|
+
@connection.close
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the number of created rows' do
|
27
|
+
expect(@values.first).to be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/typecast/datetime_spec'
|
3
|
+
|
4
|
+
describe 'DataObjects::Mysql with DateTime' do
|
5
|
+
it_behaves_like 'supporting DateTime'
|
6
|
+
it_behaves_like 'supporting DateTime autocasting'
|
7
|
+
|
8
|
+
describe 'reading 0000-00-00 00:00:00' do
|
9
|
+
before do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
|
12
|
+
@connection.create_command("SET SESSION sql_mode = 'ALLOW_INVALID_DATES'").execute_non_query
|
13
|
+
@connection.create_command("INSERT INTO widgets (release_datetime) VALUES ('')").execute_non_query
|
14
|
+
|
15
|
+
@command = @connection.create_command("SELECT release_datetime FROM widgets WHERE release_datetime = '0000-00-00 00:00:00'")
|
16
|
+
@reader = @command.execute_reader
|
17
|
+
@reader.next!
|
18
|
+
@values = @reader.values
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
@reader.close
|
23
|
+
@connection.close
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the number of created rows' do
|
27
|
+
expect(@values.first).to be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/typecast/float_spec'
|
3
|
+
|
4
|
+
describe 'DataObjects::Mysql with Float' do
|
5
|
+
it_behaves_like 'supporting Float'
|
6
|
+
it_behaves_like 'supporting Float autocasting'
|
7
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
require 'data_objects/spec/shared/typecast/nil_spec'
|
3
|
+
|
4
|
+
describe 'DataObjects::Mysql with Nil' do
|
5
|
+
it_behaves_like 'supporting Nil'
|
6
|
+
it_behaves_like 'supporting writing an Nil'
|
7
|
+
it_behaves_like 'supporting Nil autocasting'
|
8
|
+
end
|
data/tasks/compile.rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
gem 'rake-compiler', '~>1.2'
|
3
|
+
require 'rake/extensiontask'
|
4
|
+
|
5
|
+
def gemspec
|
6
|
+
@gemspec ||= Gem::Specification.load(File.expand_path('../do_mysql.gemspec', __dir__))
|
7
|
+
end
|
8
|
+
|
9
|
+
Rake::ExtensionTask.new('do_mysql', gemspec) do |ext|
|
10
|
+
ext.lib_dir = "lib/#{gemspec.name}"
|
11
|
+
|
12
|
+
# automatically add build options to avoid need of manual input
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
warn 'To compile, install rake-compiler (gem install rake-compiler)'
|
16
|
+
end
|
data/tasks/release.rake
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
desc 'Builds all gems (native, binaries for JRuby and Windows)'
|
2
|
+
task :build_all do
|
3
|
+
`rake clean`
|
4
|
+
`rake build`
|
5
|
+
end
|
6
|
+
|
7
|
+
desc 'Release all gems (native, binaries for JRuby and Windows)'
|
8
|
+
task release_all: :build_all do
|
9
|
+
Dir.children("pkg").each do |gem_path|
|
10
|
+
command = "gem push pkg/#{gem_path}"
|
11
|
+
puts "Executing #{command.inspect}:"
|
12
|
+
sh command
|
13
|
+
end
|
14
|
+
end
|
data/tasks/retrieve.rake
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
gem 'rake-compiler', '~>1.2'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/extensioncompiler'
|
5
|
+
|
6
|
+
# download mysql library and headers
|
7
|
+
directory 'vendor'
|
8
|
+
|
9
|
+
# only on Windows or cross platform compilation
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# clobber vendored packages
|
14
|
+
CLOBBER.include('vendor')
|
15
|
+
|
16
|
+
# vendor:mysql
|
17
|
+
|
18
|
+
# hook into cross compilation vendored mysql dependency
|
19
|
+
rescue LoadError
|
20
|
+
end
|
data/tasks/spec.rake
ADDED
data/tasks/ssl.rake
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :ssl do
|
2
|
+
task :env do
|
3
|
+
require ROOT.join('spec', 'spec_helper')
|
4
|
+
end
|
5
|
+
|
6
|
+
desc 'Check test environment for SSL support.'
|
7
|
+
task check: :env do
|
8
|
+
DataObjectsSpecHelpers.test_environment_supports_ssl?
|
9
|
+
|
10
|
+
puts
|
11
|
+
if DataObjectsSpecHelpers.test_environment_supports_ssl?
|
12
|
+
puts '** SSL successfully configured for the test environment **'
|
13
|
+
else
|
14
|
+
puts '** SSL is not configured for the test environment **'
|
15
|
+
puts
|
16
|
+
puts DataObjectsSpecHelpers.test_environment_ssl_config_errors.join("\n")
|
17
|
+
puts
|
18
|
+
raise 'Run rake ssl:config for instructions on how to configure the test environment.'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Provide instructions on how to configure SSL in your test environment.'
|
23
|
+
task config: :env do
|
24
|
+
puts DataObjectsSpecHelpers.test_environment_ssl_config
|
25
|
+
end
|
26
|
+
end
|