do_mysql 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/LICENSE +1 -1
  2. data/Manifest.txt +15 -4
  3. data/Rakefile +7 -122
  4. data/ext/do_mysql_ext/do_mysql_ext.c +154 -99
  5. data/ext/do_mysql_ext/extconf.rb +1 -0
  6. data/lib/do_mysql.rb +5 -2
  7. data/lib/do_mysql/version.rb +1 -1
  8. data/spec/command_spec.rb +9 -0
  9. data/spec/connection_spec.rb +19 -0
  10. data/spec/encoding_spec.rb +8 -0
  11. data/spec/lib/rspec_immediate_feedback_formatter.rb +3 -0
  12. data/spec/reader_spec.rb +8 -0
  13. data/spec/result_spec.rb +9 -0
  14. data/spec/spec_helper.rb +38 -47
  15. data/spec/typecast/array_spec.rb +8 -0
  16. data/spec/typecast/bigdecimal_spec.rb +9 -0
  17. data/spec/typecast/boolean_spec.rb +9 -0
  18. data/spec/typecast/byte_array_spec.rb +8 -0
  19. data/spec/typecast/class_spec.rb +8 -0
  20. data/spec/typecast/date_spec.rb +9 -0
  21. data/spec/typecast/datetime_spec.rb +9 -0
  22. data/spec/typecast/float_spec.rb +9 -0
  23. data/spec/typecast/integer_spec.rb +8 -0
  24. data/spec/typecast/nil_spec.rb +10 -0
  25. data/spec/typecast/range_spec.rb +8 -0
  26. data/spec/typecast/string_spec.rb +8 -0
  27. data/spec/typecast/time_spec.rb +8 -0
  28. data/tasks/gem.rake +60 -0
  29. data/tasks/install.rake +15 -0
  30. data/tasks/native.rake +31 -0
  31. data/tasks/release.rake +75 -0
  32. data/tasks/retrieve.rake +67 -0
  33. data/tasks/spec.rake +18 -0
  34. metadata +72 -40
  35. data/.gitignore +0 -0
  36. data/buildfile +0 -27
  37. data/ext-java/src/main/java/DoMysqlExtService.java +0 -23
  38. data/ext-java/src/main/java/do_mysql/MySqlDriverDefinition.java +0 -22
  39. data/ext/.gitignore +0 -2
  40. data/spec/integration/do_mysql_spec.rb +0 -341
  41. data/spec/integration/logging_spec.rb +0 -52
  42. data/spec/integration/quoting_spec.rb +0 -45
  43. data/spec/spec.opts +0 -2
  44. data/spec/unit/transaction_spec.rb +0 -35
@@ -32,6 +32,7 @@ end
32
32
  # ruby extconf.rb --with-mysql-config=/path/to/mysql_config
33
33
  if RUBY_PLATFORM =~ /mswin|mingw/
34
34
  dir_config('mysql')
35
+ have_header 'my_global.h'
35
36
  have_header 'mysql.h' || exit(1)
36
37
  have_library 'libmysql' || exit(1)
37
38
  have_func('mysql_query', 'mysql.h') || exit(1)
@@ -30,8 +30,11 @@ if RUBY_PLATFORM =~ /java/
30
30
 
31
31
  def character_set
32
32
  # JDBC API does not provide an easy way to get the current character set
33
- # For now, we code the character_set used as utf8
34
- "utf8"
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
35
38
  end
36
39
 
37
40
  end
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Mysql
3
- VERSION = "0.9.11"
3
+ VERSION = "0.9.12"
4
4
  end
5
5
  end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/command_spec'
5
+
6
+ describe DataObjects::Mysql::Command do
7
+ it_should_behave_like 'a Command'
8
+ it_should_behave_like 'a Command with async'
9
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/connection_spec'
5
+
6
+ describe DataObjects::Mysql::Connection do
7
+
8
+ before :all do
9
+ @driver = CONFIG.scheme
10
+ @user = CONFIG.user
11
+ @password = CONFIG.pass
12
+ @host = CONFIG.host
13
+ @port = CONFIG.port
14
+ @database = CONFIG.database
15
+ end
16
+
17
+ it_should_behave_like 'a Connection'
18
+ #it_should_behave_like 'a Connection with authentication support'
19
+ 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/encoding_spec'
5
+
6
+ describe DataObjects::Mysql::Connection do
7
+ it_should_behave_like 'a driver supporting encodings'
8
+ end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'data_objects', 'spec', 'lib', 'rspec_immediate_feedback_formatter'))
@@ -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/reader_spec'
5
+
6
+ describe DataObjects::Mysql::Reader do
7
+ it_should_behave_like 'a Reader'
8
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/result_spec'
5
+
6
+ describe DataObjects::Mysql::Result do
7
+ it_should_behave_like 'a Result'
8
+ it_should_behave_like 'a Result which returns inserted keys'
9
+ end
@@ -3,7 +3,7 @@ JRUBY = RUBY_PLATFORM =~ /java/
3
3
 
4
4
  require 'rubygems'
5
5
 
6
- gem 'rspec', '>=1.1.3'
6
+ gem 'rspec', '>1.1.12'
7
7
  require 'spec'
8
8
 
9
9
  require 'date'
@@ -16,6 +16,9 @@ require 'fileutils'
16
16
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_objects', 'lib'))
17
17
  require 'data_objects'
18
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 }
21
+
19
22
  if JRUBY
20
23
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
21
24
  require 'do_jdbc'
@@ -32,57 +35,39 @@ DataObjects::Mysql.logger = DataObjects::Logger.new(log_path, :debug)
32
35
 
33
36
  at_exit { DataObjects.logger.flush }
34
37
 
35
- MYSQL = OpenStruct.new
36
- MYSQL.user = ENV['DO_MYSQL_USER'] || 'root'
37
- MYSQL.pass = ENV['DO_MYSQL_PASS'] || ''
38
- MYSQL.host = ENV['DO_MYSQL_HOST'] || '127.0.0.1'
39
- MYSQL.hostname = ENV['DO_MYSQL_HOSTNAME'] || 'localhost'
40
- MYSQL.port = ENV['DO_MYSQL_PORT'] || '3306'
41
- MYSQL.database = ENV['DO_MYSQL_DATABASE'] || 'do_mysql_test'
42
- MYSQL.socket = ENV['DO_MYSQL_SOCKET'] || '/tmp/mysql.sock'
43
-
44
- DO_MYSQL_SPEC_URI = Addressable::URI::parse(ENV["DO_MYSQL_SPEC_URI"] ||
45
- "mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.host}:#{MYSQL.port}/#{MYSQL.database}")
46
-
47
- module MysqlSpecHelpers
48
- def insert(query, *args)
49
- result = @secondary_connection.create_command(query).execute_non_query(*args)
50
- result.insert_id
51
- end
38
+ Spec::Runner.configure do |config|
39
+ config.include(DataObjects::Spec::PendingHelpers)
40
+ end
52
41
 
53
- def exec(query, *args)
54
- @secondary_connection.create_command(query).execute_non_query(*args)
55
- end
42
+ CONFIG = OpenStruct.new
43
+ CONFIG.scheme = 'mysql'
44
+ CONFIG.user = ENV['DO_MYSQL_USER'] || 'root'
45
+ CONFIG.pass = ENV['DO_MYSQL_PASS'] || ''
46
+ CONFIG.host = ENV['DO_MYSQL_HOST'] || 'localhost'
47
+ CONFIG.port = ENV['DO_MYSQL_PORT'] || '3306'
48
+ CONFIG.database = ENV['DO_MYSQL_DATABASE'] || '/do_test'
56
49
 
57
- def select(query, types = nil, *args)
58
- begin
59
- command = @connection.create_command(query)
60
- command.set_types types unless types.nil?
61
- reader = command.execute_reader(*args)
62
- reader.next!
63
- yield reader if block_given?
64
- ensure
65
- reader.close if reader
66
- end
67
- end
50
+ CONFIG.uri = ENV["DO_MYSQL_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user}:#{CONFIG.pass}@#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}"
51
+ CONFIG.sleep = "SELECT sleep(1)"
52
+
53
+ module DataObjectsSpecHelpers
68
54
 
69
55
  def setup_test_environment
70
- @connection = DataObjects::Connection.new(DO_MYSQL_SPEC_URI)
71
- @secondary_connection = DataObjects::Connection.new(DO_MYSQL_SPEC_URI)
56
+ conn = DataObjects::Connection.new(CONFIG.uri)
72
57
 
73
- @connection.create_command(<<-EOF).execute_non_query
58
+ conn.create_command(<<-EOF).execute_non_query
74
59
  DROP TABLE IF EXISTS `invoices`
75
60
  EOF
76
61
 
77
- @connection.create_command(<<-EOF).execute_non_query
62
+ conn.create_command(<<-EOF).execute_non_query
78
63
  DROP TABLE IF EXISTS `users`
79
64
  EOF
80
65
 
81
- @connection.create_command(<<-EOF).execute_non_query
66
+ conn.create_command(<<-EOF).execute_non_query
82
67
  DROP TABLE IF EXISTS `widgets`
83
68
  EOF
84
69
 
85
- @connection.create_command(<<-EOF).execute_non_query
70
+ conn.create_command(<<-EOF).execute_non_query
86
71
  CREATE TABLE `users` (
87
72
  `id` int(11) NOT NULL auto_increment,
88
73
  `name` varchar(200) default 'Billy' NULL,
@@ -91,7 +76,7 @@ module MysqlSpecHelpers
91
76
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
92
77
  EOF
93
78
 
94
- @connection.create_command(<<-EOF).execute_non_query
79
+ conn.create_command(<<-EOF).execute_non_query
95
80
  CREATE TABLE `invoices` (
96
81
  `id` int(11) NOT NULL auto_increment,
97
82
  `invoice_number` varchar(50) NOT NULL,
@@ -99,7 +84,7 @@ module MysqlSpecHelpers
99
84
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
100
85
  EOF
101
86
 
102
- @connection.create_command(<<-EOF).execute_non_query
87
+ conn.create_command(<<-EOF).execute_non_query
103
88
  CREATE TABLE `widgets` (
104
89
  `id` int(11) NOT NULL auto_increment,
105
90
  `code` char(8) default 'A14' NULL,
@@ -116,7 +101,7 @@ module MysqlSpecHelpers
116
101
  `number_sold` mediumint default 0,
117
102
  `super_number` bigint default 9223372036854775807,
118
103
  `weight` float default 1.23,
119
- `cost1` double(8,2) default 10.23,
104
+ `cost1` double default 10.23,
120
105
  `cost2` decimal(8,2) default 50.23,
121
106
  `release_date` date default '2008-02-14',
122
107
  `release_datetime` datetime default '2008-02-14 00:31:12',
@@ -127,15 +112,21 @@ module MysqlSpecHelpers
127
112
  EOF
128
113
 
129
114
  1.upto(16) do |n|
130
- @connection.create_command(<<-EOF).execute_non_query
131
- insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number) VALUES ('W#{n.to_s.rjust(7,"0")}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'Utilizing blah blah blah', 'CAD DRAWING', 1234);
115
+ conn.create_command(<<-EOF).execute_non_query
116
+ 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);
132
117
  EOF
133
118
  end
134
119
 
135
- end
120
+ conn.create_command(<<-EOF).execute_non_query
121
+ update widgets set flags = 1 where id = 2
122
+ EOF
123
+
124
+ conn.create_command(<<-EOF).execute_non_query
125
+ update widgets set ad_description = NULL where id = 3
126
+ EOF
127
+
128
+ conn.close
136
129
 
137
- def teardown_test_environment
138
- @connection.close
139
- @secondary_connection.close
140
130
  end
131
+
141
132
  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/array_spec'
5
+
6
+ describe 'DataObjects::Mysql with Array' do
7
+ it_should_behave_like 'supporting Array'
8
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/bigdecimal_spec'
5
+
6
+ describe 'DataObjects::Mysql with BigDecimal' do
7
+ it_should_behave_like 'supporting BigDecimal'
8
+ it_should_behave_like 'supporting BigDecimal autocasting'
9
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/boolean_spec'
5
+
6
+ describe 'DataObjects::Mysql with Boolean' do
7
+ it_should_behave_like 'supporting Boolean'
8
+ it_should_behave_like 'supporting Boolean autocasting'
9
+ 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/byte_array_spec'
5
+
6
+ describe 'DataObjects::Mysql with ByteArray' do
7
+ it_should_behave_like 'supporting ByteArray'
8
+ 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/class_spec'
5
+
6
+ describe 'DataObjects::Mysql with Class' do
7
+ it_should_behave_like 'supporting Class'
8
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/date_spec'
5
+
6
+ describe 'DataObjects::Mysql with Date' do
7
+ it_should_behave_like 'supporting Date'
8
+ it_should_behave_like 'supporting Date autocasting'
9
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/datetime_spec'
5
+
6
+ describe 'DataObjects::Mysql with DateTime' do
7
+ it_should_behave_like 'supporting DateTime'
8
+ it_should_behave_like 'supporting DateTime autocasting'
9
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/float_spec'
5
+
6
+ describe 'DataObjects::Mysql with Float' do
7
+ it_should_behave_like 'supporting Float'
8
+ it_should_behave_like 'supporting Float autocasting'
9
+ 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/integer_spec'
5
+
6
+ describe 'DataObjects::Mysql with Integer' do
7
+ it_should_behave_like 'supporting Integer'
8
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/nil_spec'
5
+
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'
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/range_spec'
5
+
6
+ describe 'DataObjects::Mysql with Range' do
7
+ it_should_behave_like 'supporting Range'
8
+ 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/string_spec'
5
+
6
+ describe 'DataObjects::Mysql with String' do
7
+ it_should_behave_like 'supporting String'
8
+ 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/time_spec'
5
+
6
+ describe 'DataObjects::Mysql with Time' do
7
+ it_should_behave_like 'supporting Time'
8
+ end
@@ -0,0 +1,60 @@
1
+ require 'rubygems/package_task'
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
48
+
49
+ gem_package = Gem::PackageTask.new(GEM_SPEC) do |pkg|
50
+ pkg.need_tar = false
51
+ pkg.need_zip = false
52
+ 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"]
@@ -0,0 +1,15 @@
1
+ def sudo_gem(cmd)
2
+ sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
3
+ end
4
+
5
+ # Installation
6
+
7
+ desc "Install #{GEM_SPEC.name} #{GEM_SPEC.version}"
8
+ task :install => [ :package ] do
9
+ sudo_gem "install pkg/#{GEM_SPEC.name}-#{GEM_SPEC.version} --no-update-sources"
10
+ end
11
+
12
+ desc "Uninstall #{GEM_SPEC.name} #{GEM_SPEC.version}"
13
+ task :uninstall => [ :clean ] do
14
+ sudo_gem "uninstall #{GEM_SPEC.name} -v#{GEM_SPEC.version} -I -x"
15
+ end