do_mysql 0.10.0-java → 0.10.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/ChangeLog.markdown +27 -0
  2. data/LICENSE +1 -1
  3. data/README.markdown +104 -3
  4. data/Rakefile +56 -9
  5. data/ext/do_mysql/compat.h +55 -0
  6. data/ext/do_mysql/do_mysql.c +1065 -0
  7. data/ext/do_mysql/error.h +527 -0
  8. data/ext/do_mysql/extconf.rb +74 -0
  9. data/lib/do_mysql.rb +27 -11
  10. data/lib/do_mysql/do_mysql.jar +0 -0
  11. data/lib/do_mysql/version.rb +1 -1
  12. data/spec/command_spec.rb +2 -2
  13. data/spec/connection_spec.rb +16 -14
  14. data/spec/encoding_spec.rb +2 -1
  15. data/spec/reader_spec.rb +1 -1
  16. data/spec/result_spec.rb +3 -3
  17. data/spec/spec_helper.rb +21 -31
  18. data/spec/typecast/array_spec.rb +1 -1
  19. data/spec/typecast/bigdecimal_spec.rb +2 -2
  20. data/spec/typecast/boolean_spec.rb +2 -2
  21. data/spec/typecast/byte_array_spec.rb +1 -1
  22. data/spec/typecast/class_spec.rb +1 -1
  23. data/spec/typecast/date_spec.rb +2 -2
  24. data/spec/typecast/datetime_spec.rb +2 -2
  25. data/spec/typecast/float_spec.rb +2 -2
  26. data/spec/typecast/integer_spec.rb +1 -1
  27. data/spec/typecast/nil_spec.rb +3 -3
  28. data/spec/typecast/other_spec.rb +8 -0
  29. data/spec/typecast/range_spec.rb +1 -1
  30. data/spec/typecast/string_spec.rb +1 -1
  31. data/spec/typecast/time_spec.rb +1 -1
  32. data/tasks/compile.rake +65 -0
  33. data/tasks/release.rake +12 -71
  34. data/tasks/retrieve.rake +1 -1
  35. data/tasks/spec.rake +19 -15
  36. metadata +119 -107
  37. data/HISTORY.markdown +0 -17
  38. data/Manifest.txt +0 -32
  39. data/lib/do_mysql_ext.jar +0 -0
  40. data/spec/lib/rspec_immediate_feedback_formatter.rb +0 -3
  41. data/tasks/gem.rake +0 -8
  42. data/tasks/install.rake +0 -15
  43. data/tasks/native.rake +0 -31
@@ -0,0 +1,74 @@
1
+ ENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/
2
+
3
+ require 'mkmf'
4
+
5
+ # Allow for custom compiler to be specified.
6
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
7
+
8
+ # All instances of mysql_config on PATH ...
9
+ def mysql_config_paths
10
+ ENV['PATH'].split(File::PATH_SEPARATOR).collect do |path|
11
+ [ "#{path}/mysql_config", "#{path}/mysql_config5" ].
12
+ detect { |bin| File.exist?(bin) }
13
+ end
14
+ end
15
+
16
+ # The first mysql_config binary on PATH ...
17
+ def default_mysql_config_path
18
+ mysql_config_paths.compact.first
19
+ end
20
+
21
+ def mysql_config(type)
22
+ IO.popen("#{default_mysql_config_path} --#{type}").readline.chomp rescue nil
23
+ end
24
+
25
+ def default_prefix
26
+ if mc = default_mysql_config_path
27
+ File.dirname(File.dirname(mc))
28
+ else
29
+ "/usr/local"
30
+ end
31
+ end
32
+
33
+ # Allow overriding path to mysql_config on command line using:
34
+ # ruby extconf.rb --with-mysql-config=/path/to/mysql_config
35
+ if RUBY_PLATFORM =~ /mswin|mingw/
36
+ dir_config('mysql')
37
+ have_header 'my_global.h'
38
+ have_header 'mysql.h' || exit(1)
39
+ have_library 'libmysql' || exit(1)
40
+ have_func('mysql_query', 'mysql.h') || exit(1)
41
+ have_func('mysql_ssl_set', 'mysql.h')
42
+ elsif mc = with_config('mysql-config', default_mysql_config_path)
43
+ includes = mysql_config('include').split(/\s+/).map do |dir|
44
+ dir.gsub(/^-I/, "")
45
+ end.uniq
46
+ libs = mysql_config('libs').split(/\s+/).select {|lib| lib =~ /^-L/}.map do |dir|
47
+ dir.gsub(/^-L/, "")
48
+ end.uniq
49
+ dir_config('mysql', includes, libs)
50
+ else
51
+ inc, lib = dir_config('mysql', default_prefix)
52
+ libs = ['m', 'z', 'socket', 'nsl']
53
+ lib_dirs =
54
+ [ lib, "/usr/lib", "/usr/local/lib", "/opt/local/lib" ].collect do |path|
55
+ [ path, "#{path}/mysql", "#{path}/mysql5/mysql" ]
56
+ end
57
+ find_library('mysqlclient', 'mysql_query', *lib_dirs.flatten) || exit(1)
58
+ find_header('mysql.h', *lib_dirs.flatten.map { |p| p.gsub('/lib', '/include') })
59
+ end
60
+
61
+ unless RUBY_PLATFORM =~ /mswin|mingw/
62
+ have_header 'mysql.h'
63
+ have_library 'mysqlclient' || exit(1)
64
+ have_func 'mysql_query' || exit(1)
65
+ have_func 'mysql_ssl_set'
66
+ end
67
+
68
+ $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
69
+
70
+ if RUBY_VERSION < '1.8.6'
71
+ $CFLAGS << ' -DRUBY_LESS_THAN_186'
72
+ end
73
+
74
+ create_makefile('do_mysql/do_mysql')
data/lib/do_mysql.rb CHANGED
@@ -19,26 +19,42 @@ if RUBY_PLATFORM =~ /java/
19
19
 
20
20
  end
21
21
 
22
- require 'do_mysql_ext'
22
+ begin
23
+ require 'do_mysql/do_mysql'
24
+ rescue LoadError
25
+ if RUBY_PLATFORM =~ /mingw|mswin/
26
+ RUBY_VERSION =~ /(\d+.\d+)/
27
+ require "do_mysql/#{$1}/do_mysql"
28
+ else
29
+ raise
30
+ end
31
+ end
32
+
23
33
  require 'do_mysql/version'
24
- require 'do_mysql/transaction'
34
+ require 'do_mysql/transaction' if RUBY_PLATFORM !~ /java/
25
35
  require 'do_mysql/encoding'
26
36
 
27
37
  if RUBY_PLATFORM =~ /java/
28
38
 
39
+ DataObjects::Mysql::Connection.class_eval do
40
+
41
+ def using_socket?
42
+ @using_socket
43
+ end
44
+
45
+ def secure?
46
+ false
47
+ end
48
+
49
+ end
50
+
51
+ else
52
+
29
53
  module DataObjects
30
54
  module Mysql
31
55
  class Connection
32
- def self.pool_size
33
- 20
34
- end
35
-
36
- def using_socket?
37
- @using_socket
38
- end
39
-
40
56
  def secure?
41
- false
57
+ !(@ssl_cipher.nil? || @ssl_cipher.empty?)
42
58
  end
43
59
  end
44
60
  end
Binary file
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Mysql
3
- VERSION = "0.10.0"
3
+ VERSION = '0.10.1'.freeze
4
4
  end
5
5
  end
data/spec/command_spec.rb CHANGED
@@ -4,6 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/command_spec'
5
5
 
6
6
  describe DataObjects::Mysql::Command do
7
- it_should_behave_like 'a Command'
8
- it_should_behave_like 'a Command with async'
7
+ behaves_like 'a Command'
8
+ behaves_like 'a Command with async'
9
9
  end
@@ -6,19 +6,21 @@ require 'cgi'
6
6
 
7
7
  describe DataObjects::Mysql::Connection do
8
8
 
9
- before :all do
10
- @driver = CONFIG.scheme
11
- @user = CONFIG.user
9
+ before do
10
+ @driver = CONFIG.scheme
11
+ @user = CONFIG.user
12
12
  @password = CONFIG.pass
13
- @host = CONFIG.host
14
- @port = CONFIG.port
13
+ @host = CONFIG.host
14
+ @port = CONFIG.port
15
15
  @database = CONFIG.database
16
- @ssl = CONFIG.ssl
16
+ @ssl = CONFIG.ssl
17
17
  end
18
18
 
19
- it_should_behave_like 'a Connection'
20
- it_should_behave_like 'a Connection with authentication support'
21
- it_should_behave_like 'a Connection with SSL support' unless JRUBY
19
+ behaves_like 'a Connection'
20
+ behaves_like 'a Connection with authentication support'
21
+ # FIXME: behaves_like 'a Connection with JDBC URL support' if JRUBY
22
+ behaves_like 'a Connection with SSL support' unless JRUBY
23
+ behaves_like 'a Connection via JDNI' if JRUBY
22
24
 
23
25
  if DataObjectsSpecHelpers.test_environment_supports_ssl?
24
26
 
@@ -26,22 +28,22 @@ describe DataObjects::Mysql::Connection do
26
28
 
27
29
  it 'should raise an error when passed ssl=true' do
28
30
  lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl=true") }.
29
- should raise_error(ArgumentError)
31
+ should.raise(ArgumentError)
30
32
  end
31
33
 
32
34
  it 'should raise an error when passed a nonexistent client certificate' do
33
35
  lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl[client_cert]=nonexistent") }.
34
- should raise_error(ArgumentError)
36
+ should.raise(ArgumentError)
35
37
  end
36
38
 
37
39
  it 'should raise an error when passed a nonexistent client key' do
38
40
  lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl[client_key]=nonexistent") }.
39
- should raise_error(ArgumentError)
41
+ should.raise(ArgumentError)
40
42
  end
41
43
 
42
44
  it 'should raise an error when passed a nonexistent ca certificate' do
43
45
  lambda { DataObjects::Connection.new("#{CONFIG.uri}?ssl[ca_cert]=nonexistent") }.
44
- should raise_error(ArgumentError)
46
+ should.raise(ArgumentError)
45
47
  end
46
48
 
47
49
  it 'should connect with a specified SSL cipher' do
@@ -51,7 +53,7 @@ describe DataObjects::Mysql::Connection do
51
53
 
52
54
  it 'should raise an error with an invalid SSL cipher' do
53
55
  lambda { DataObjects::Connection.new("#{CONFIG.uri}?#{CONFIG.ssl}&ssl[cipher]=invalid") }.
54
- should raise_error
56
+ should.raise
55
57
  end
56
58
 
57
59
  end
@@ -4,5 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/encoding_spec'
5
5
 
6
6
  describe DataObjects::Mysql::Connection do
7
- it_should_behave_like 'a driver supporting encodings'
7
+ behaves_like 'a driver supporting different encodings'
8
+ behaves_like 'returning correctly encoded strings for the default encoding'
8
9
  end
data/spec/reader_spec.rb CHANGED
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/reader_spec'
5
5
 
6
6
  describe DataObjects::Mysql::Reader do
7
- it_should_behave_like 'a Reader'
7
+ behaves_like 'a Reader'
8
8
  end
data/spec/result_spec.rb CHANGED
@@ -4,13 +4,13 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/result_spec'
5
5
 
6
6
  # splitting the descibe into two separate declaration avoids
7
- # concurrent execution of the "it_should_behave_like ....."
7
+ # concurrent execution of the "behaves_like ....."
8
8
  # needed by some databases (sqlite3)
9
9
 
10
10
  describe DataObjects::Mysql::Result do
11
- it_should_behave_like 'a Result'
11
+ behaves_like 'a Result'
12
12
  end
13
13
 
14
14
  describe DataObjects::Mysql::Result do
15
- it_should_behave_like 'a Result which returns inserted keys'
15
+ behaves_like 'a Result which returns inserted keys'
16
16
  end
data/spec/spec_helper.rb CHANGED
@@ -2,57 +2,45 @@ $TESTING=true
2
2
  JRUBY = RUBY_PLATFORM =~ /java/
3
3
 
4
4
  require 'rubygems'
5
-
6
- gem 'rspec', '>1.1.12'
7
- require 'spec'
8
-
9
5
  require 'date'
10
6
  require 'ostruct'
11
- require 'pathname'
12
7
  require 'fileutils'
8
+ require 'win32console' if RUBY_PLATFORM =~ /mingw|mswin/
9
+
10
+ driver_lib = File.expand_path('../../lib', __FILE__)
11
+ $LOAD_PATH.unshift(driver_lib) unless $LOAD_PATH.include?(driver_lib)
13
12
 
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)
17
- # put data_objects from repository in the load path
18
- # DO NOT USE installed gem of data_objects!
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
-
22
- if JRUBY
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)
25
- require 'do_jdbc'
13
+ # Prepend data_objects/do_jdbc in the repository to the load path.
14
+ # DO NOT USE installed gems, except when running the specs from gem.
15
+ repo_root = File.expand_path('../../..', __FILE__)
16
+ (['data_objects'] << ('do_jdbc' if JRUBY)).compact.each do |lib|
17
+ lib_path = "#{repo_root}/#{lib}/lib"
18
+ $LOAD_PATH.unshift(lib_path) if File.directory?(lib_path) && !$LOAD_PATH.include?(lib_path)
26
19
  end
27
20
 
28
21
  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
-
22
+ require 'data_objects/spec/bacon'
23
+ require 'data_objects/spec/helpers/ssl'
33
24
  require 'do_mysql'
34
25
 
35
- log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'do.log'))
36
- FileUtils.mkdir_p(File.dirname(log_path))
37
-
38
- DataObjects::Mysql.logger = DataObjects::Logger.new(log_path, :debug)
39
-
26
+ DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, :off)
40
27
  at_exit { DataObjects.logger.flush }
41
28
 
42
- Spec::Runner.configure do |config|
43
- config.include(DataObjects::Spec::PendingHelpers)
44
- end
45
-
46
29
  CONFIG = OpenStruct.new
47
30
  CONFIG.scheme = 'mysql'
48
31
  CONFIG.user = ENV['DO_MYSQL_USER'] || 'root'
49
32
  CONFIG.pass = ENV['DO_MYSQL_PASS'] || ''
33
+ CONFIG.user_info = unless CONFIG.user == 'root' && CONFIG.pass.empty?
34
+ "#{CONFIG.user}:#{CONFIG.pass}@"
35
+ else
36
+ ''
37
+ end
50
38
  CONFIG.host = ENV['DO_MYSQL_HOST'] || 'localhost'
51
39
  CONFIG.port = ENV['DO_MYSQL_PORT'] || '3306'
52
40
  CONFIG.database = ENV['DO_MYSQL_DATABASE'] || '/do_test'
53
41
  CONFIG.ssl = SSLHelpers.query(:ca_cert, :client_cert, :client_key)
54
42
 
55
- CONFIG.uri = ENV["DO_MYSQL_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user}:#{CONFIG.pass}@#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}"
43
+ CONFIG.uri = ENV["DO_MYSQL_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user_info}#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}"
56
44
  CONFIG.sleep = "SELECT sleep(1)"
57
45
 
58
46
  module DataObjectsSpecHelpers
@@ -226,3 +214,5 @@ module DataObjectsSpecHelpers
226
214
  end
227
215
 
228
216
  end
217
+
218
+ include DataObjectsSpecHelpers
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/array_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Array' do
7
- it_should_behave_like 'supporting Array'
7
+ behaves_like 'supporting Array'
8
8
  end
@@ -4,6 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/bigdecimal_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with BigDecimal' do
7
- it_should_behave_like 'supporting BigDecimal'
8
- it_should_behave_like 'supporting BigDecimal autocasting'
7
+ behaves_like 'supporting BigDecimal'
8
+ behaves_like 'supporting BigDecimal autocasting'
9
9
  end
@@ -4,6 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/boolean_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Boolean' do
7
- it_should_behave_like 'supporting Boolean'
8
- it_should_behave_like 'supporting Boolean autocasting'
7
+ behaves_like 'supporting Boolean'
8
+ behaves_like 'supporting Boolean autocasting'
9
9
  end
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/byte_array_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with ByteArray' do
7
- it_should_behave_like 'supporting ByteArray'
7
+ behaves_like 'supporting ByteArray'
8
8
  end
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/class_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Class' do
7
- it_should_behave_like 'supporting Class'
7
+ behaves_like 'supporting Class'
8
8
  end
@@ -4,6 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/date_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Date' do
7
- it_should_behave_like 'supporting Date'
8
- it_should_behave_like 'supporting Date autocasting'
7
+ behaves_like 'supporting Date'
8
+ behaves_like 'supporting Date autocasting'
9
9
  end
@@ -4,6 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/datetime_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with DateTime' do
7
- it_should_behave_like 'supporting DateTime'
8
- it_should_behave_like 'supporting DateTime autocasting'
7
+ behaves_like 'supporting DateTime'
8
+ behaves_like 'supporting DateTime autocasting'
9
9
  end
@@ -4,6 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/float_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Float' do
7
- it_should_behave_like 'supporting Float'
8
- it_should_behave_like 'supporting Float autocasting'
7
+ behaves_like 'supporting Float'
8
+ behaves_like 'supporting Float autocasting'
9
9
  end
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/integer_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Integer' do
7
- it_should_behave_like 'supporting Integer'
7
+ behaves_like 'supporting Integer'
8
8
  end
@@ -4,7 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/nil_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Nil' do
7
- it_should_behave_like 'supporting Nil'
8
- it_should_behave_like 'supporting writing an Nil'
9
- it_should_behave_like 'supporting Nil autocasting'
7
+ behaves_like 'supporting Nil'
8
+ behaves_like 'supporting writing an Nil'
9
+ behaves_like 'supporting Nil autocasting'
10
10
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/other_spec'
5
+
6
+ describe 'DataObjects::H2 with other (unknown) type' do
7
+ behaves_like 'supporting other (unknown) type'
8
+ end
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/range_spec'
5
5
 
6
6
  describe 'DataObjects::Mysql with Range' do
7
- it_should_behave_like 'supporting Range'
7
+ behaves_like 'supporting Range'
8
8
  end