do_mysql 0.9.12-x86-mingw32 → 0.10.0-x86-mingw32

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.
@@ -1,9 +1,4 @@
1
- if RUBY_PLATFORM =~ /darwin/
2
- ENV["RC_ARCHS"] = `uname -m`.chomp if `uname -sr` =~ /^Darwin/
3
-
4
- # On PowerPC the defaults are fine
5
- ENV["RC_ARCHS"] = '' if `uname -m` =~ /^Power Macintosh/
6
- end
1
+ ENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/
7
2
 
8
3
  require 'mkmf'
9
4
 
data/lib/do_mysql.rb CHANGED
@@ -1,21 +1,30 @@
1
- require 'rubygems'
2
1
  require 'data_objects'
3
2
  if RUBY_PLATFORM =~ /java/
4
3
  require 'do_jdbc'
5
4
  require 'java'
6
- gem 'jdbc-mysql'
7
- require 'jdbc/mysql' # the JDBC driver, packaged as a gem
5
+
6
+ driver = 'com.mysql.jdbc.Driver'
7
+ begin
8
+ java.lang.Thread.currentThread.getContextClassLoader().loadClass(driver, true)
9
+ rescue
10
+ require 'jdbc/mysql' # the JDBC driver, packaged as a gem
11
+ end
12
+
13
+ # Another way of loading the JDBC Class. This seems to be more reliable
14
+ # than Class.forName() or
15
+ # Thread.currentThread.getContextClassLoader().loadClass() within the
16
+ # data_objects.Connection Java class, which is currently not working as
17
+ # expected.
18
+ java_import driver
19
+
8
20
  end
9
21
 
10
22
  require 'do_mysql_ext'
11
- require File.expand_path(File.join(File.dirname(__FILE__), 'do_mysql', 'version'))
12
- require File.expand_path(File.join(File.dirname(__FILE__), 'do_mysql', 'transaction'))
23
+ require 'do_mysql/version'
24
+ require 'do_mysql/transaction'
25
+ require 'do_mysql/encoding'
13
26
 
14
27
  if RUBY_PLATFORM =~ /java/
15
- # Another way of loading the JDBC Class. This seems to be more reliable
16
- # than Class.forName() within the data_objects.Connection Java class,
17
- # which is currently not working as expected.
18
- import 'com.mysql.jdbc.Driver'
19
28
 
20
29
  module DataObjects
21
30
  module Mysql
@@ -28,15 +37,9 @@ if RUBY_PLATFORM =~ /java/
28
37
  @using_socket
29
38
  end
30
39
 
31
- def character_set
32
- # JDBC API does not provide an easy way to get the current character set
33
- reader = self.create_command("SHOW VARIABLES LIKE 'character_set_client'").execute_reader
34
- reader.next!
35
- char_set = reader.values[1]
36
- reader.close
37
- char_set.downcase
40
+ def secure?
41
+ false
38
42
  end
39
-
40
43
  end
41
44
  end
42
45
  end
@@ -0,0 +1,38 @@
1
+ module DataObjects
2
+ module Mysql
3
+ module Encoding
4
+ MAP = {
5
+ "Big5" => "big5",
6
+ "CP850" => "cp850",
7
+ "KOI8-R" => "koi8r",
8
+ "ISO-8859-1" => "latin1",
9
+ "ISO-8859-2" => "latin2",
10
+ "US-ASCII" => "ascii",
11
+ "EUC-JP" => "ujis",
12
+ "SJIS" => "sjis",
13
+ "ISO-8859-8" => "hebrew",
14
+ "TIS-620" => "tis620",
15
+ "EUC-KR" => "euckr",
16
+ "KOI8-U" => "koi8u",
17
+ "GB2312" => "gb2312",
18
+ "ISO-8859-7" => "greek",
19
+ "Windows-1250" => "cp1250",
20
+ "GBK" => "gbk",
21
+ "ISO-8859-9" => "latin5",
22
+ "UTF-8" => "utf8",
23
+ "UTF-16BE" => "ucs2",
24
+ "IBM866" => "cp866",
25
+ "macCentEuro" => "macce",
26
+ "macRoman" => "macroman",
27
+ "CP852" => "cp852",
28
+ "ISO-8859-13" => "latin7",
29
+ "Windows-1251" => "cp1251",
30
+ "Windows-1256" => "cp1256",
31
+ "Windows-1257" => "cp1257",
32
+ "ASCII-8BIT" => "binary",
33
+ "Windows-31J" => "cp932",
34
+ "eucJP-ms" => "eucjpms"
35
+ }
36
+ end
37
+ end
38
+ end
@@ -5,27 +5,16 @@ module DataObjects
5
5
 
6
6
  class Transaction < DataObjects::Transaction
7
7
 
8
- def finalize_transaction
9
- cmd = "XA END '#{id}'"
10
- connection.create_command(cmd).execute_non_query
11
- end
12
-
13
- def begin
8
+ def begin_prepared
14
9
  cmd = "XA START '#{id}'"
15
10
  connection.create_command(cmd).execute_non_query
16
11
  end
17
12
 
18
- def commit
13
+ def commit_prepared
19
14
  cmd = "XA COMMIT '#{id}'"
20
15
  connection.create_command(cmd).execute_non_query
21
16
  end
22
17
 
23
- def rollback
24
- finalize_transaction
25
- cmd = "XA ROLLBACK '#{id}'"
26
- connection.create_command(cmd).execute_non_query
27
- end
28
-
29
18
  def rollback_prepared
30
19
  cmd = "XA ROLLBACK '#{id}'"
31
20
  connection.create_command(cmd).execute_non_query
@@ -37,6 +26,13 @@ module DataObjects
37
26
  connection.create_command(cmd).execute_non_query
38
27
  end
39
28
 
29
+ private
30
+
31
+ def finalize_transaction
32
+ cmd = "XA END '#{id}'"
33
+ connection.create_command(cmd).execute_non_query
34
+ end
35
+
40
36
  end
41
37
 
42
38
  end
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Mysql
3
- VERSION = "0.9.12"
3
+ VERSION = "0.10.0"
4
4
  end
5
5
  end
data/lib/do_mysql_ext.so CHANGED
Binary file
@@ -2,6 +2,7 @@
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/connection_spec'
5
+ require 'cgi'
5
6
 
6
7
  describe DataObjects::Mysql::Connection do
7
8
 
@@ -12,8 +13,49 @@ describe DataObjects::Mysql::Connection do
12
13
  @host = CONFIG.host
13
14
  @port = CONFIG.port
14
15
  @database = CONFIG.database
16
+ @ssl = CONFIG.ssl
15
17
  end
16
18
 
17
19
  it_should_behave_like 'a Connection'
18
- #it_should_behave_like 'a Connection with authentication support'
20
+ it_should_behave_like 'a Connection with authentication support'
21
+ it_should_behave_like 'a Connection with SSL support' unless JRUBY
22
+
23
+ if DataObjectsSpecHelpers.test_environment_supports_ssl?
24
+
25
+ describe 'connecting with SSL' do
26
+
27
+ it 'should raise an error when passed ssl=true' do
28
+ lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl=true") }.
29
+ should raise_error(ArgumentError)
30
+ end
31
+
32
+ it 'should raise an error when passed a nonexistent client certificate' do
33
+ lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl[client_cert]=nonexistent") }.
34
+ should raise_error(ArgumentError)
35
+ end
36
+
37
+ it 'should raise an error when passed a nonexistent client key' do
38
+ lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl[client_key]=nonexistent") }.
39
+ should raise_error(ArgumentError)
40
+ end
41
+
42
+ it 'should raise an error when passed a nonexistent ca certificate' do
43
+ lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl[ca_cert]=nonexistent") }.
44
+ should raise_error(ArgumentError)
45
+ end
46
+
47
+ it 'should connect with a specified SSL cipher' do
48
+ DataObjects::Connection.new("#{CONFIG.uri}?#{CONFIG.ssl}&ssl[cipher]=#{SSLHelpers::CONFIG.cipher}").
49
+ ssl_cipher.should == SSLHelpers::CONFIG.cipher
50
+ end
51
+
52
+ it 'should raise an error with an invalid SSL cipher' do
53
+ lambda { DataObjects::Connection.new("#{CONFIG.uri}?#{CONFIG.ssl}&ssl[cipher]=invalid") }.
54
+ should raise_error
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
19
61
  end
data/spec/result_spec.rb CHANGED
@@ -3,7 +3,14 @@
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/result_spec'
5
5
 
6
+ # splitting the descibe into two separate declaration avoids
7
+ # concurrent execution of the "it_should_behave_like ....."
8
+ # needed by some databases (sqlite3)
9
+
6
10
  describe DataObjects::Mysql::Result do
7
11
  it_should_behave_like 'a Result'
12
+ end
13
+
14
+ describe DataObjects::Mysql::Result do
8
15
  it_should_behave_like 'a Result which returns inserted keys'
9
16
  end
data/spec/spec_helper.rb CHANGED
@@ -11,21 +11,25 @@ require 'ostruct'
11
11
  require 'pathname'
12
12
  require 'fileutils'
13
13
 
14
+ dir = File.dirname(__FILE__)
15
+ lib_path = File.expand_path("#{dir}/../lib")
16
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
14
17
  # put data_objects from repository in the load path
15
18
  # DO NOT USE installed gem of data_objects!
16
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_objects', 'lib'))
17
- require 'data_objects'
18
-
19
- DATAOBJECTS_SPEC_ROOT = Pathname(__FILE__).dirname.parent.parent + 'data_objects' + 'spec'
20
- Pathname.glob((DATAOBJECTS_SPEC_ROOT + 'lib/**/*.rb').to_s).each { |f| require f }
19
+ do_lib_path = File.expand_path("#{dir}/../../data_objects/lib")
20
+ $LOAD_PATH.unshift do_lib_path unless $LOAD_PATH.include?(do_lib_path)
21
21
 
22
22
  if JRUBY
23
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
23
+ jdbc_lib_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
24
+ $LOAD_PATH.unshift jdbc_lib_path unless $LOAD_PATH.include?(jdbc_lib_path)
24
25
  require 'do_jdbc'
25
26
  end
26
27
 
27
- # put the pre-compiled extension in the path to be found
28
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
28
+ require 'data_objects'
29
+
30
+ DATAOBJECTS_SPEC_ROOT = Pathname(__FILE__).dirname.parent.parent + 'data_objects' + 'spec'
31
+ Pathname.glob((DATAOBJECTS_SPEC_ROOT + 'lib/**/*.rb').to_s).each { |f| require f }
32
+
29
33
  require 'do_mysql'
30
34
 
31
35
  log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'do.log'))
@@ -46,6 +50,7 @@ CONFIG.pass = ENV['DO_MYSQL_PASS'] || ''
46
50
  CONFIG.host = ENV['DO_MYSQL_HOST'] || 'localhost'
47
51
  CONFIG.port = ENV['DO_MYSQL_PORT'] || '3306'
48
52
  CONFIG.database = ENV['DO_MYSQL_DATABASE'] || '/do_test'
53
+ CONFIG.ssl = SSLHelpers.query(:ca_cert, :client_cert, :client_key)
49
54
 
50
55
  CONFIG.uri = ENV["DO_MYSQL_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user}:#{CONFIG.pass}@#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}"
51
56
  CONFIG.sleep = "SELECT sleep(1)"
@@ -96,7 +101,7 @@ module DataObjectsSpecHelpers
96
101
  `ad_image` mediumblob NULL,
97
102
  `whitepaper_text` longtext NULL,
98
103
  `cad_drawing` longblob NULL,
99
- `flags` tinyint(1) default 0,
104
+ `flags` boolean default false,
100
105
  `number_in_stock` smallint default 500,
101
106
  `number_sold` mediumint default 0,
102
107
  `super_number` bigint default 9223372036854775807,
@@ -105,7 +110,7 @@ module DataObjectsSpecHelpers
105
110
  `cost2` decimal(8,2) default 50.23,
106
111
  `release_date` date default '2008-02-14',
107
112
  `release_datetime` datetime default '2008-02-14 00:31:12',
108
- `release_timestamp` timestamp default '2008-02-14 00:31:31',
113
+ `release_timestamp` timestamp NULL default '2008-02-14 00:31:31',
109
114
  `status` enum('active','out of stock') NOT NULL default 'active',
110
115
  PRIMARY KEY (`id`)
111
116
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -118,15 +123,106 @@ module DataObjectsSpecHelpers
118
123
  end
119
124
 
120
125
  conn.create_command(<<-EOF).execute_non_query
121
- update widgets set flags = 1 where id = 2
126
+ update widgets set flags = true where id = 2
122
127
  EOF
123
128
 
124
129
  conn.create_command(<<-EOF).execute_non_query
125
130
  update widgets set ad_description = NULL where id = 3
126
131
  EOF
127
132
 
133
+ conn.create_command(<<-EOF).execute_non_query
134
+ update widgets set flags = NULL where id = 4
135
+ EOF
136
+
137
+ conn.create_command(<<-EOF).execute_non_query
138
+ update widgets set cost1 = NULL where id = 5
139
+ EOF
140
+
141
+ conn.create_command(<<-EOF).execute_non_query
142
+ update widgets set cost2 = NULL where id = 6
143
+ EOF
144
+
145
+ conn.create_command(<<-EOF).execute_non_query
146
+ update widgets set release_date = NULL where id = 7
147
+ EOF
148
+
149
+ conn.create_command(<<-EOF).execute_non_query
150
+ update widgets set release_datetime = NULL where id = 8
151
+ EOF
152
+
153
+ conn.create_command(<<-EOF).execute_non_query
154
+ update widgets set release_timestamp = NULL where id = 9
155
+ EOF
156
+
128
157
  conn.close
129
158
 
130
159
  end
131
160
 
161
+ def self.test_environment_ssl_config
162
+ ssl_config = SSLHelpers::CONFIG
163
+
164
+ message = "\nYou can configure MySQL via my.cnf with the following options in [mysqld]:\n"
165
+ message << "ssl_ca=#{ssl_config.ca_cert}\n"
166
+ message << "ssl_cert=#{ssl_config.server_cert}\n"
167
+ message << "ssl_key=#{ssl_config.server_key}\n"
168
+ message << "ssl_cipher=#{ssl_config.cipher}\n"
169
+
170
+ message << "\nOr you can use the following command line options:\n"
171
+ message << "--ssl-ca #{ssl_config.ca_cert} "
172
+ message << "--ssl-cert #{ssl_config.server_cert} "
173
+ message << "--ssl-key #{ssl_config.server_key} "
174
+ message << "--ssl-cipher #{ssl_config.cipher} "
175
+ message
176
+ end
177
+
178
+ def self.test_environment_ssl_config_errors
179
+ conn = DataObjects::Connection.new(CONFIG.uri)
180
+
181
+ ssl_variables = conn.create_command(<<-EOF).execute_reader
182
+ SHOW VARIABLES LIKE '%ssl%'
183
+ EOF
184
+
185
+ ssl_config = SSLHelpers::CONFIG
186
+ current_config = { }
187
+
188
+ while ssl_variables.next!
189
+ variable, value = ssl_variables.values
190
+ current_config[variable.intern] = value
191
+ end
192
+
193
+ errors = []
194
+
195
+ if current_config[:have_ssl] == 'NO'
196
+ errors << "SSL was not compiled"
197
+ end
198
+
199
+ if current_config[:have_ssl] == 'DISABLED'
200
+ errors << "SSL was not enabled"
201
+ end
202
+
203
+ if current_config[:ssl_ca] != ssl_config.ca_cert
204
+ errors << "The CA certificate is not configured (it was set to '#{current_config[:ssl_ca]}')"
205
+ end
206
+
207
+ if current_config[:ssl_cert] != ssl_config.server_cert
208
+ errors << "The server certificate is not configured (it was set to '#{current_config[:ssl_cert]}')"
209
+ end
210
+
211
+ if current_config[:ssl_key] != ssl_config.server_key
212
+ errors << "The server key is not configured, (it was set to '#{current_config[:ssl_key]}')"
213
+ end
214
+
215
+ if current_config[:ssl_cipher] != ssl_config.cipher
216
+ errors << "The cipher is not configured, (it was set to '#{current_config[:ssl_cipher]}')"
217
+ end
218
+
219
+ errors
220
+ ensure
221
+ conn.close if conn
222
+ end
223
+
224
+ def self.test_environment_supports_ssl?
225
+ test_environment_ssl_config_errors.empty?
226
+ end
227
+
132
228
  end
data/tasks/gem.rake CHANGED
@@ -1,60 +1,8 @@
1
1
  require 'rubygems/package_task'
2
2
 
3
- GEM_SPEC = Gem::Specification.new do |s|
4
- # basic information
5
- s.name = "do_mysql"
6
- s.version = DataObjects::Mysql::VERSION
7
-
8
- # description and details
9
- s.summary = 'DataObjects MySQL Driver'
10
- s.description = "Implements the DataObjects API for MySQL"
11
-
12
- # dependencies
13
- s.add_dependency "addressable", "~>2.0.0"
14
- s.add_dependency "extlib", "~>0.9.12"
15
- s.add_dependency "data_objects", DataObjects::Mysql::VERSION
16
-
17
- if JRUBY
18
- s.add_dependency "jdbc-mysql", ">=5.0.4"
19
- s.add_dependency "do_jdbc", DataObjects::Mysql::VERSION
20
- s.platform = "java"
21
- # components, files and paths
22
- s.files = FileList["lib/**/*.rb", "spec/**/*.rb", "tasks/**/*.rake",
23
- "LICENSE", "Rakefile", "*.{rdoc,txt,yml}", "lib/*.jar"]
24
- else
25
- s.platform = Gem::Platform::RUBY
26
- s.extensions << 'ext/do_mysql_ext/extconf.rb'
27
- s.files = FileList["lib/**/*.rb", "spec/**/*.rb", "tasks/**/*.rake", "ext/**/*.{rb,c}",
28
- "LICENSE", "Rakefile", "*.{rdoc,txt,yml}"]
29
- end
30
-
31
-
32
- # development dependencies
33
- s.add_development_dependency 'rspec', '~>1.2.0'
34
-
35
- s.require_path = 'lib'
36
-
37
- # documentation
38
- s.has_rdoc = false
39
-
40
- # project information
41
- s.homepage = 'http://github.com/datamapper/do'
42
- s.rubyforge_project = 'dorb'
43
-
44
- # author and contributors
45
- s.author = 'Dirkjan Bussink'
46
- s.email = 'd.bussink@gmail.com'
47
- end
3
+ GEM_SPEC = eval(File.read('do_mysql.gemspec'))
48
4
 
49
5
  gem_package = Gem::PackageTask.new(GEM_SPEC) do |pkg|
50
6
  pkg.need_tar = false
51
7
  pkg.need_zip = false
52
8
  end
53
-
54
- file "#{GEM_SPEC.name}.gemspec" => ['Rakefile', 'tasks/gem.rake'] do |t|
55
- puts "Generating #{t.name}"
56
- File.open(t.name, 'w') { |f| f.puts GEM_SPEC.to_yaml }
57
- end
58
-
59
- desc "Generate or update the standalone gemspec file for the project"
60
- task :gemspec => ["#{GEM_SPEC.name}.gemspec"]