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.
- data/LICENSE +1 -1
- data/Manifest.txt +15 -4
- data/Rakefile +7 -122
- data/ext/do_mysql_ext/do_mysql_ext.c +154 -99
- data/ext/do_mysql_ext/extconf.rb +1 -0
- data/lib/do_mysql.rb +5 -2
- data/lib/do_mysql/version.rb +1 -1
- data/spec/command_spec.rb +9 -0
- data/spec/connection_spec.rb +19 -0
- data/spec/encoding_spec.rb +8 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +3 -0
- data/spec/reader_spec.rb +8 -0
- data/spec/result_spec.rb +9 -0
- data/spec/spec_helper.rb +38 -47
- data/spec/typecast/array_spec.rb +8 -0
- data/spec/typecast/bigdecimal_spec.rb +9 -0
- data/spec/typecast/boolean_spec.rb +9 -0
- data/spec/typecast/byte_array_spec.rb +8 -0
- data/spec/typecast/class_spec.rb +8 -0
- data/spec/typecast/date_spec.rb +9 -0
- data/spec/typecast/datetime_spec.rb +9 -0
- data/spec/typecast/float_spec.rb +9 -0
- data/spec/typecast/integer_spec.rb +8 -0
- data/spec/typecast/nil_spec.rb +10 -0
- data/spec/typecast/range_spec.rb +8 -0
- data/spec/typecast/string_spec.rb +8 -0
- data/spec/typecast/time_spec.rb +8 -0
- data/tasks/gem.rake +60 -0
- data/tasks/install.rake +15 -0
- data/tasks/native.rake +31 -0
- data/tasks/release.rake +75 -0
- data/tasks/retrieve.rake +67 -0
- data/tasks/spec.rake +18 -0
- metadata +72 -40
- data/.gitignore +0 -0
- data/buildfile +0 -27
- data/ext-java/src/main/java/DoMysqlExtService.java +0 -23
- data/ext-java/src/main/java/do_mysql/MySqlDriverDefinition.java +0 -22
- data/ext/.gitignore +0 -2
- data/spec/integration/do_mysql_spec.rb +0 -341
- data/spec/integration/logging_spec.rb +0 -52
- data/spec/integration/quoting_spec.rb +0 -45
- data/spec/spec.opts +0 -2
- data/spec/unit/transaction_spec.rb +0 -35
data/tasks/native.rake
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
begin
|
2
|
+
gem('rake-compiler')
|
3
|
+
require 'rake/extensiontask'
|
4
|
+
|
5
|
+
Rake::ExtensionTask.new('do_mysql_ext', GEM_SPEC) do |ext|
|
6
|
+
|
7
|
+
mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-#{BINARY_VERSION}-win32"))
|
8
|
+
|
9
|
+
# automatically add build options to avoid need of manual input
|
10
|
+
if RUBY_PLATFORM =~ /mswin|mingw/ then
|
11
|
+
ext.config_options << "--with-mysql-include=#{mysql_lib}/include"
|
12
|
+
ext.config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt"
|
13
|
+
else
|
14
|
+
ext.cross_compile = true
|
15
|
+
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
|
16
|
+
ext.cross_config_options << "--with-mysql-include=#{mysql_lib}/include"
|
17
|
+
ext.cross_config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
rescue LoadError
|
22
|
+
warn "To cross-compile, install rake-compiler (gem install rake-compiler)"
|
23
|
+
|
24
|
+
if (tasks_dir = ROOT.parent + 'tasks').directory?
|
25
|
+
require tasks_dir + 'ext_helper'
|
26
|
+
require tasks_dir + 'ext_helper_java'
|
27
|
+
|
28
|
+
setup_c_extension("#{GEM_SPEC.name}_ext", GEM_SPEC)
|
29
|
+
setup_java_extension("#{GEM_SPEC.name}_ext", GEM_SPEC)
|
30
|
+
end
|
31
|
+
end
|
data/tasks/release.rake
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
begin
|
2
|
+
gem 'rubyforge', '~> 1.0.1'
|
3
|
+
require 'rubyforge'
|
4
|
+
rescue Exception
|
5
|
+
nil
|
6
|
+
end
|
7
|
+
|
8
|
+
if defined?(RubyForge) then
|
9
|
+
if defined?(GEM_SPEC) then
|
10
|
+
desc 'Package and upload to RubyForge'
|
11
|
+
task :release => [:package] do |t|
|
12
|
+
ver = ENV['VERSION'] or fail "Must supply VERSION (rake release VERSION=x.y.z)."
|
13
|
+
|
14
|
+
# compare versions to avoid mistakes
|
15
|
+
unless ver == GEM_SPEC.version.to_s then
|
16
|
+
fail "Version mismatch (supplied and specification versions differ)."
|
17
|
+
end
|
18
|
+
|
19
|
+
# no rubyforge project? no release for you!
|
20
|
+
if GEM_SPEC.rubyforge_project == 'TODO' or GEM_SPEC.rubyforge_project.nil? then
|
21
|
+
fail "Must define rubyforge_project in your gem specification."
|
22
|
+
end
|
23
|
+
|
24
|
+
# instantiate a RubyForge object
|
25
|
+
rf = RubyForge.new
|
26
|
+
|
27
|
+
# read project info and overview
|
28
|
+
notes = begin
|
29
|
+
r = File.read("README.rdoc")
|
30
|
+
r.split(/^(=+ .*)/)[1..4].join.strip
|
31
|
+
rescue
|
32
|
+
warn "Missing README.rdoc"
|
33
|
+
''
|
34
|
+
end
|
35
|
+
|
36
|
+
# read changes
|
37
|
+
changes = begin
|
38
|
+
h = File.read("History.txt")
|
39
|
+
h.split(/^(==+ .*)/)[1..2].join.strip
|
40
|
+
rescue
|
41
|
+
warn "Missing History.txt"
|
42
|
+
''
|
43
|
+
end
|
44
|
+
|
45
|
+
# build the configuration for the release
|
46
|
+
config = Hash.new
|
47
|
+
config["release_notes"] = notes
|
48
|
+
config["release_changes"] = changes
|
49
|
+
config["preformatted"] = true
|
50
|
+
|
51
|
+
# prepare configuration
|
52
|
+
rf.configure config
|
53
|
+
|
54
|
+
files = FileList["pkg/#{GEM_SPEC.name}-#{GEM_SPEC.version}*.*"].to_a
|
55
|
+
fail "No files found for the release." if files.empty?
|
56
|
+
|
57
|
+
puts "Logging in RubyForge..."
|
58
|
+
rf.login
|
59
|
+
|
60
|
+
puts "Files to upload:"
|
61
|
+
files.each do |f|
|
62
|
+
puts " * #{f}"
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "Releasing #{GEM_SPEC.name} version #{GEM_SPEC.version}..."
|
66
|
+
rf.add_release GEM_SPEC.rubyforge_project, GEM_SPEC.name, GEM_SPEC.version, *files
|
67
|
+
puts "Done."
|
68
|
+
end
|
69
|
+
#Rake::Task['release'].prerequisites.unshift('clean', 'cross', 'native')
|
70
|
+
else
|
71
|
+
warn "no GEM_SPEC is found or defined. 'release' task cannot work without it."
|
72
|
+
end
|
73
|
+
else
|
74
|
+
warn "rubyforge gem is required to generate releases, please install it (gem install rubyforge)."
|
75
|
+
end
|
data/tasks/retrieve.rake
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
begin
|
2
|
+
gem('rake-compiler')
|
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
|
+
def dlltool(dllname, deffile, libfile)
|
11
|
+
# define if we are using GCC or not
|
12
|
+
if Rake::ExtensionCompiler.mingw_gcc_executable then
|
13
|
+
dir = File.dirname(Rake::ExtensionCompiler.mingw_gcc_executable)
|
14
|
+
tool = case RUBY_PLATFORM
|
15
|
+
when /mingw/
|
16
|
+
File.join(dir, 'dlltool.exe')
|
17
|
+
when /linux|darwin/
|
18
|
+
File.join(dir, "#{Rake::ExtensionCompiler.mingw_host}-dlltool")
|
19
|
+
end
|
20
|
+
return "#{tool} --dllname #{dllname} --def #{deffile} --output-lib #{libfile}"
|
21
|
+
else
|
22
|
+
if RUBY_PLATFORM =~ /mswin/ then
|
23
|
+
tool = 'lib.exe'
|
24
|
+
else
|
25
|
+
fail "Unsupported platform for cross-compilation (please, contribute some patches)."
|
26
|
+
end
|
27
|
+
return "#{tool} /DEF:#{deffile} /OUT:#{libfile}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
file "vendor/mysql-noinstall-#{BINARY_VERSION}-win32.zip" => ['vendor'] do |t|
|
32
|
+
base_version = BINARY_VERSION.gsub(/\.[0-9]+$/, '')
|
33
|
+
url = "http://mysql.proserve.nl/Downloads/MySQL-#{base_version}/#{File.basename(t.name)}"
|
34
|
+
when_writing "downloading #{t.name}" do
|
35
|
+
cd File.dirname(t.name) do
|
36
|
+
sh "wget -c #{url} || curl -C - -O #{url}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
file "vendor/mysql-#{BINARY_VERSION}-win32/include/mysql.h" => ["vendor/mysql-noinstall-#{BINARY_VERSION}-win32.zip"] do |t|
|
42
|
+
full_file = File.expand_path(t.prerequisites.last)
|
43
|
+
when_writing "creating #{t.name}" do
|
44
|
+
cd "vendor" do
|
45
|
+
sh "unzip #{full_file} mysql-#{BINARY_VERSION}-win32/bin/** mysql-#{BINARY_VERSION}-win32/include/** mysql-#{BINARY_VERSION}-win32/lib/**"
|
46
|
+
end
|
47
|
+
# update file timestamp to avoid Rake perform this extraction again.
|
48
|
+
touch t.name
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# clobber vendored packages
|
53
|
+
CLOBBER.include('vendor')
|
54
|
+
|
55
|
+
# vendor:mysql
|
56
|
+
task 'vendor:mysql' => ["vendor/mysql-#{BINARY_VERSION}-win32/include/mysql.h"]
|
57
|
+
|
58
|
+
# hook into cross compilation vendored mysql dependency
|
59
|
+
if RUBY_PLATFORM =~ /mingw|mswin/ then
|
60
|
+
Rake::Task['compile'].prerequisites.unshift 'vendor:mysql'
|
61
|
+
else
|
62
|
+
if Rake::Task.tasks.map {|t| t.name }.include? 'cross'
|
63
|
+
Rake::Task['cross'].prerequisites.unshift 'vendor:mysql'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
rescue LoadError
|
67
|
+
end
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Specs
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc 'Run specifications'
|
5
|
+
Spec::Rake::SpecTask.new(:spec => [ :clean, :compile ]) do |t|
|
6
|
+
t.spec_opts << '--options' << ROOT + 'spec/spec.opts'
|
7
|
+
t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb').map { |f| f.to_s }
|
8
|
+
|
9
|
+
begin
|
10
|
+
# RCov is run by default, except on the JRuby platform
|
11
|
+
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
12
|
+
t.rcov_opts << '--exclude' << 'spec'
|
13
|
+
t.rcov_opts << '--text-summary'
|
14
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
15
|
+
rescue Exception
|
16
|
+
# rcov not installed
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: do_mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dirkjan Bussink
|
@@ -9,9 +9,29 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-17 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: addressable
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: extlib
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.12
|
34
|
+
version:
|
15
35
|
- !ruby/object:Gem::Dependency
|
16
36
|
name: data_objects
|
17
37
|
type: :runtime
|
@@ -20,60 +40,72 @@ dependencies:
|
|
20
40
|
requirements:
|
21
41
|
- - "="
|
22
42
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
43
|
+
version: 0.9.12
|
24
44
|
version:
|
25
45
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
46
|
+
name: rspec
|
27
47
|
type: :development
|
28
48
|
version_requirement:
|
29
49
|
version_requirements: !ruby/object:Gem::Requirement
|
30
50
|
requirements:
|
31
|
-
- -
|
51
|
+
- - ~>
|
32
52
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
53
|
+
version: 1.2.0
|
34
54
|
version:
|
35
|
-
description:
|
36
|
-
email:
|
37
|
-
- d.bussink@gmail.com
|
55
|
+
description: Implements the DataObjects API for MySQL
|
56
|
+
email: d.bussink@gmail.com
|
38
57
|
executables: []
|
39
58
|
|
40
59
|
extensions:
|
41
60
|
- ext/do_mysql_ext/extconf.rb
|
42
|
-
extra_rdoc_files:
|
43
|
-
|
44
|
-
- Manifest.txt
|
45
|
-
- README.txt
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
46
63
|
files:
|
47
|
-
- .gitignore
|
48
|
-
- History.txt
|
49
|
-
- LICENSE
|
50
|
-
- Manifest.txt
|
51
|
-
- README.txt
|
52
|
-
- Rakefile
|
53
|
-
- buildfile
|
54
|
-
- ext-java/src/main/java/DoMysqlExtService.java
|
55
|
-
- ext-java/src/main/java/do_mysql/MySqlDriverDefinition.java
|
56
|
-
- ext/.gitignore
|
57
|
-
- ext/do_mysql_ext/do_mysql_ext.c
|
58
|
-
- ext/do_mysql_ext/extconf.rb
|
59
|
-
- lib/do_mysql.rb
|
60
64
|
- lib/do_mysql/transaction.rb
|
61
65
|
- lib/do_mysql/version.rb
|
62
|
-
-
|
63
|
-
- spec/
|
64
|
-
- spec/
|
65
|
-
- spec/
|
66
|
+
- lib/do_mysql.rb
|
67
|
+
- spec/command_spec.rb
|
68
|
+
- spec/connection_spec.rb
|
69
|
+
- spec/encoding_spec.rb
|
70
|
+
- spec/lib/rspec_immediate_feedback_formatter.rb
|
71
|
+
- spec/reader_spec.rb
|
72
|
+
- spec/result_spec.rb
|
66
73
|
- spec/spec_helper.rb
|
67
|
-
- spec/
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
-
|
74
|
+
- spec/typecast/array_spec.rb
|
75
|
+
- spec/typecast/bigdecimal_spec.rb
|
76
|
+
- spec/typecast/boolean_spec.rb
|
77
|
+
- spec/typecast/byte_array_spec.rb
|
78
|
+
- spec/typecast/class_spec.rb
|
79
|
+
- spec/typecast/date_spec.rb
|
80
|
+
- spec/typecast/datetime_spec.rb
|
81
|
+
- spec/typecast/float_spec.rb
|
82
|
+
- spec/typecast/integer_spec.rb
|
83
|
+
- spec/typecast/nil_spec.rb
|
84
|
+
- spec/typecast/range_spec.rb
|
85
|
+
- spec/typecast/string_spec.rb
|
86
|
+
- spec/typecast/time_spec.rb
|
87
|
+
- tasks/gem.rake
|
88
|
+
- tasks/install.rake
|
89
|
+
- tasks/native.rake
|
90
|
+
- tasks/release.rake
|
91
|
+
- tasks/retrieve.rake
|
92
|
+
- tasks/spec.rake
|
93
|
+
- ext/do_mysql_ext/extconf.rb
|
94
|
+
- ext/do_mysql_ext/do_mysql_ext.c
|
95
|
+
- LICENSE
|
96
|
+
- Rakefile
|
97
|
+
- History.txt
|
98
|
+
- Manifest.txt
|
73
99
|
- README.txt
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://github.com/datamapper/do
|
102
|
+
licenses: []
|
103
|
+
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
74
107
|
require_paths:
|
75
108
|
- lib
|
76
|
-
- ext
|
77
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
110
|
requirements:
|
79
111
|
- - ">="
|
@@ -89,9 +121,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
121
|
requirements: []
|
90
122
|
|
91
123
|
rubyforge_project: dorb
|
92
|
-
rubygems_version: 1.3.
|
124
|
+
rubygems_version: 1.3.3
|
93
125
|
signing_key:
|
94
|
-
specification_version:
|
95
|
-
summary:
|
126
|
+
specification_version: 3
|
127
|
+
summary: DataObjects MySQL Driver
|
96
128
|
test_files: []
|
97
129
|
|
data/.gitignore
DELETED
File without changes
|
data/buildfile
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# Apache Buildr buildfile for do_mysql
|
2
|
-
# see http://incubator.apache.org/buildr/ for more information on Apache Buildr
|
3
|
-
require 'buildr'
|
4
|
-
require 'pathname'
|
5
|
-
|
6
|
-
VERSION_NUMBER = '1.0'
|
7
|
-
JDBC_SUPPORT = ['data_objects:jdbc:jar:1.0']
|
8
|
-
TARGET_DIR = 'pkg/classes'
|
9
|
-
repositories.remote << 'http://www.ibiblio.org/maven2/'
|
10
|
-
|
11
|
-
define 'do_mysql' do
|
12
|
-
project.version = VERSION_NUMBER
|
13
|
-
project.group = 'data_objects.rb'
|
14
|
-
|
15
|
-
manifest['Copyright'] = 'Alex Coles (C) 2008-2009'
|
16
|
-
|
17
|
-
compile.using :target => '1.5', :lint => 'all', :deprecation => 'true'
|
18
|
-
|
19
|
-
define 'ext-java' do
|
20
|
-
package(:jar).clean.include(TARGET_DIR)
|
21
|
-
|
22
|
-
jdbc_support_jar = file('../../do_jdbc/lib/do_jdbc_internal.jar')
|
23
|
-
jdbc_support = artifact('data_objects:jdbc:jar:1.0').from(jdbc_support_jar)
|
24
|
-
|
25
|
-
compile.into(TARGET_DIR).with(JDBC_SUPPORT)
|
26
|
-
end
|
27
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import data_objects.drivers.DriverDefinition;
|
2
|
-
import do_mysql.MySqlDriverDefinition;
|
3
|
-
|
4
|
-
public class DoMysqlExtService extends AbstractDataObjectsExtService {
|
5
|
-
|
6
|
-
private final static DriverDefinition driver = new MySqlDriverDefinition();
|
7
|
-
public final static String RUBY_MODULE_NAME = "Mysql";
|
8
|
-
public final static String RUBY_ERROR_NAME = "MysqlError";
|
9
|
-
|
10
|
-
public String getModuleName() {
|
11
|
-
return RUBY_MODULE_NAME;
|
12
|
-
}
|
13
|
-
|
14
|
-
@Override
|
15
|
-
public String getErrorName() {
|
16
|
-
return RUBY_ERROR_NAME;
|
17
|
-
}
|
18
|
-
|
19
|
-
public DriverDefinition getDriverDefinition() {
|
20
|
-
return driver;
|
21
|
-
}
|
22
|
-
|
23
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
package do_mysql;
|
2
|
-
|
3
|
-
import data_objects.drivers.AbstractDriverDefinition;
|
4
|
-
|
5
|
-
public class MySqlDriverDefinition extends AbstractDriverDefinition {
|
6
|
-
|
7
|
-
public boolean supportsJdbcGeneratedKeys()
|
8
|
-
{
|
9
|
-
return true;
|
10
|
-
}
|
11
|
-
|
12
|
-
//@Override
|
13
|
-
public String quoteString(String str) {
|
14
|
-
StringBuffer quotedValue = new StringBuffer(str.length() + 2);
|
15
|
-
quotedValue.append("\'");
|
16
|
-
quotedValue.append(str.replaceAll("'", "\\\\'"));
|
17
|
-
// TODO: handle backslashes
|
18
|
-
quotedValue.append("\'");
|
19
|
-
return quotedValue.toString();
|
20
|
-
}
|
21
|
-
|
22
|
-
}
|
data/ext/.gitignore
DELETED
@@ -1,341 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
5
|
-
|
6
|
-
describe DataObjects::Mysql do
|
7
|
-
include MysqlSpecHelpers
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
setup_test_environment
|
11
|
-
end
|
12
|
-
|
13
|
-
after :each do
|
14
|
-
teardown_test_environment
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should expose the proper DataObjects classes" do
|
18
|
-
DataObjects::Mysql.const_get('Connection').should_not be_nil
|
19
|
-
DataObjects::Mysql.const_get('Command').should_not be_nil
|
20
|
-
DataObjects::Mysql.const_get('Result').should_not be_nil
|
21
|
-
DataObjects::Mysql.const_get('Reader').should_not be_nil
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should connect successfully via TCP" do
|
25
|
-
connection = DataObjects::Connection.new("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.host}:#{MYSQL.port}/#{MYSQL.database}")
|
26
|
-
connection.should_not be_using_socket
|
27
|
-
connection.close
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should be able to send queries asynchronously in parallel" do
|
31
|
-
threads = []
|
32
|
-
|
33
|
-
start = Time.now
|
34
|
-
4.times do |i|
|
35
|
-
threads << Thread.new do
|
36
|
-
connection = DataObjects::Connection.new("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.host}:#{MYSQL.port}/#{MYSQL.database}")
|
37
|
-
command = connection.create_command("SELECT sleep(1)")
|
38
|
-
result = command.execute_non_query
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
threads.each{|t| t.join }
|
43
|
-
finish = Time.now
|
44
|
-
(finish - start).should < 2
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# I comment this out partly to raise the issue for discussion. Socket files are afaik not supported under windows. Does this
|
49
|
-
# mean that we should test for it on unix boxes but not on windows boxes? Or does it mean that it should not be speced at all?
|
50
|
-
# It's not really a requirement, since all architectures that support MySQL also supports TCP connectsion, ne?
|
51
|
-
#
|
52
|
-
# it "should connect successfully via the socket file" do
|
53
|
-
# @connection = DataObjects::Mysql::Connection.new("mysql://#{MYSQL.user}@#{MYSQL.hostname}:#{MYSQL.port}/#{MYSQL.database}/?socket=#{SOCKET_PATH}")
|
54
|
-
# @connection.should be_using_socket
|
55
|
-
# end
|
56
|
-
|
57
|
-
it "should return the current character set" do
|
58
|
-
connection = DataObjects::Connection.new("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.hostname}:#{MYSQL.port}/#{MYSQL.database}")
|
59
|
-
connection.character_set.should == "utf8"
|
60
|
-
connection.close
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should support changing the character set" do
|
64
|
-
pending "JDBC API does not provide an easy way to get the current character set" if JRUBY
|
65
|
-
# current character set can be retrieved with the following query:
|
66
|
-
# "SHOW VARIABLES LIKE character_set_database"
|
67
|
-
|
68
|
-
connection = DataObjects::Connection.new("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.hostname}:#{MYSQL.port}/#{MYSQL.database}?charset=latin1")
|
69
|
-
# N.B. query parameter after forward slash causes problems with JDBC
|
70
|
-
connection.character_set.should == "latin1"
|
71
|
-
connection.close
|
72
|
-
|
73
|
-
connection = DataObjects::Connection.new("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.hostname}:#{MYSQL.port}/#{MYSQL.database}?charset=utf8")
|
74
|
-
connection.character_set.should == "utf8"
|
75
|
-
connection.close
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should raise an error when opened with an invalid server uri" do
|
79
|
-
def connecting_with(uri)
|
80
|
-
lambda { DataObjects::Connection.new(uri) }
|
81
|
-
end
|
82
|
-
|
83
|
-
unless JRUBY ## FIXME in JRuby
|
84
|
-
# Missing database name
|
85
|
-
connecting_with("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.hostname}:#{MYSQL.port}/").should raise_error(MysqlError)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Wrong port
|
89
|
-
connecting_with("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.hostname}:666/").should raise_error(MysqlError)
|
90
|
-
|
91
|
-
unless JRUBY ## FIXME in JRuby
|
92
|
-
# Bad Username
|
93
|
-
connecting_with("mysql://baduser@#{MYSQL.hostname}:#{MYSQL.port}/").should raise_error(MysqlError)
|
94
|
-
end
|
95
|
-
|
96
|
-
# Bad Password
|
97
|
-
connecting_with("mysql://#{MYSQL.user}:wrongpassword@#{MYSQL.hostname}:#{MYSQL.port}/").should raise_error(MysqlError)
|
98
|
-
|
99
|
-
# Bad Database Name
|
100
|
-
connecting_with("mysql://#{MYSQL.user}:#{MYSQL.pass}@#{MYSQL.hostname}:#{MYSQL.port}/bad_database").should raise_error(MysqlError)
|
101
|
-
|
102
|
-
#
|
103
|
-
# Again, should socket even be speced if we don't support it across all platforms?
|
104
|
-
#
|
105
|
-
# Invalid Socket Path
|
106
|
-
#connecting_with("mysql://#{MYSQL.user}@#{MYSQL.hostname}:#{MYSQL.port}/MYSQL.database/?socket=/invalid/path/mysql.sock").should raise_error(MysqlError)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe DataObjects::Mysql::Connection do
|
111
|
-
include MysqlSpecHelpers
|
112
|
-
|
113
|
-
before :each do
|
114
|
-
setup_test_environment
|
115
|
-
end
|
116
|
-
|
117
|
-
after :each do
|
118
|
-
teardown_test_environment
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should raise an error when attempting to execute a bad query" do
|
122
|
-
lambda { @connection.create_command("INSERT INTO non_existant_table (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should raise an error when executing a bad reader" do
|
126
|
-
lambda { @connection.create_command("SELECT * FROM non_existant_table").execute_reader }.should raise_error(MysqlError)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should not raise a connection closed error after an incorrect query" do
|
130
|
-
lambda { @connection.create_command("INSERT INTO non_existant_table (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
|
131
|
-
lambda { @connection.create_command("INSERT INTO non_existant_table (tester) VALUES (1)").execute_non_query }.should_not raise_error(MysqlError, "This connection has already been closed.")
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should not raise a connection closed error after an incorrect reader" do
|
135
|
-
lambda { @connection.create_command("SELECT * FROM non_existant_table").execute_reader }.should raise_error(MysqlError)
|
136
|
-
lambda { @connection.create_command("SELECT * FROM non_existant_table").execute_reader }.should_not raise_error(MysqlError, "This connection has already been closed.")
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
describe DataObjects::Mysql::Reader do
|
142
|
-
include MysqlSpecHelpers
|
143
|
-
|
144
|
-
before :each do
|
145
|
-
setup_test_environment
|
146
|
-
end
|
147
|
-
|
148
|
-
after :each do
|
149
|
-
teardown_test_environment
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should raise an error when you pass too many or too few types for the expected result set" do
|
153
|
-
lambda { select("SELECT name, fired_at FROM users", [String, DateTime, Integer]) }.should raise_error(MysqlError)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "shouldn't raise an error when you pass NO types for the expected result set" do
|
157
|
-
lambda { select("SELECT name, fired_at FROM users", nil) }.should_not raise_error(MysqlError)
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should return the proper number of fields" do
|
161
|
-
id = insert("INSERT INTO users (name) VALUES ('Billy Bob')")
|
162
|
-
|
163
|
-
select("SELECT id, name, fired_at FROM users WHERE id = ?", nil, id) do |reader|
|
164
|
-
reader.fields.size.should == 3
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should return proper number of rows and fields using row_count and field_count" do
|
169
|
-
pending "Neither do_jdbc nor C-extension return row_count correctly at the moment"
|
170
|
-
command = @connection.create_command("SELECT * FROM widgets WHERE id = (SELECT max(id) FROM widgets)")
|
171
|
-
reader = command.execute_reader
|
172
|
-
reader.field_count.should == 21
|
173
|
-
reader.row_count.should == 1
|
174
|
-
reader.close
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should raise an exception if .values is called after reading all available rows" do
|
178
|
-
|
179
|
-
select("SELECT * FROM widgets LIMIT 2") do |reader|
|
180
|
-
# select already calls next once for us
|
181
|
-
reader.next!
|
182
|
-
reader.next!
|
183
|
-
|
184
|
-
lambda { reader.values }.should raise_error(MysqlError)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should fetch the proper number of rows" do
|
189
|
-
ids = [
|
190
|
-
insert("INSERT INTO users (name) VALUES ('Slappy Wilson')"),
|
191
|
-
insert("INSERT INTO users (name) VALUES ('Jumpy Jones')")
|
192
|
-
]
|
193
|
-
# do_jdbc rewrites "?" as "(?,?)"
|
194
|
-
# to correspond to the JDBC API
|
195
|
-
|
196
|
-
select("SELECT * FROM users WHERE id IN ?", nil, ids) do |reader|
|
197
|
-
# select already calls next once for us
|
198
|
-
reader.next!.should == true
|
199
|
-
reader.next!.should be_nil
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should contain tainted strings" do
|
204
|
-
id = insert("INSERT INTO users (name) VALUES ('Cuppy Canes')")
|
205
|
-
|
206
|
-
select("SELECT name FROM users WHERE id = ?", nil, id) do |reader|
|
207
|
-
reader.values.first.should be_tainted
|
208
|
-
end
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should return DB nulls as nil" do
|
213
|
-
id = insert("INSERT INTO users (name) VALUES (NULL)")
|
214
|
-
select("SELECT name from users WHERE name is null") do |reader|
|
215
|
-
reader.values[0].should == nil
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should not convert empty strings to null" do
|
220
|
-
id = insert("INSERT INTO users (name) VALUES ('')")
|
221
|
-
select("SELECT name FROM users WHERE id = ?", [String], id) do |reader|
|
222
|
-
reader.values.first.should == ''
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should correctly work with default utf8 character set" do
|
227
|
-
name = "Билли Боб"
|
228
|
-
id = insert("INSERT INTO users (name) VALUES ('#{name}')")
|
229
|
-
|
230
|
-
select("SELECT name from users WHERE id = ?", [String], id) do |reader|
|
231
|
-
reader.values[0].should == name
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "Date, Time, and DateTime" do
|
236
|
-
|
237
|
-
it "should return nil when the time is 0" do
|
238
|
-
pending "We need to introduce something like Proxy for typeasting where each SQL type will have _rules_ of casting" if JRUBY
|
239
|
-
# skip the test if the strict dates/times setting is turned on
|
240
|
-
strict_time = select("SHOW VARIABLES LIKE 'sql_mode'") do |reader|
|
241
|
-
reader.values.last.split(',').any? do |mode|
|
242
|
-
%w[ NO_ZERO_IN_DATE NO_ZERO_DATE ].include?(mode.strip.upcase)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
unless strict_time
|
247
|
-
id = insert("INSERT INTO users (name, fired_at) VALUES ('James', 0);")
|
248
|
-
select("SELECT fired_at FROM users WHERE id = ?", [Time], id) do |reader|
|
249
|
-
reader.values.last.should be_nil
|
250
|
-
end
|
251
|
-
exec("DELETE FROM users WHERE id = ?", id)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should return DateTimes using the current locale's Time Zone" do
|
256
|
-
date = DateTime.now
|
257
|
-
id = insert("INSERT INTO users (name, fired_at) VALUES (?, ?)", 'Sam', date)
|
258
|
-
|
259
|
-
select("SELECT fired_at FROM users WHERE id = ?", [DateTime], id) do |reader|
|
260
|
-
reader.values.last.to_s.should == date.to_s
|
261
|
-
end
|
262
|
-
|
263
|
-
exec("DELETE FROM users WHERE id = ?", id)
|
264
|
-
end
|
265
|
-
|
266
|
-
now = DateTime.now
|
267
|
-
|
268
|
-
dates = [
|
269
|
-
now.new_offset( (-11 * 3600).to_r / 86400), # GMT -11:00
|
270
|
-
now.new_offset( (-9 * 3600 + 10 * 60).to_r / 86400), # GMT -9:10, contrived
|
271
|
-
now.new_offset( (-8 * 3600).to_r / 86400), # GMT -08:00
|
272
|
-
now.new_offset( (+3 * 3600).to_r / 86400), # GMT +03:00
|
273
|
-
now.new_offset( (+5 * 3600 + 30 * 60).to_r / 86400) # GMT +05:30 (New Delhi)
|
274
|
-
]
|
275
|
-
|
276
|
-
dates.each do |date|
|
277
|
-
it "should return #{date.to_s} offset to the current locale's Time Zone if they were inserted using a different timezone" do
|
278
|
-
pending "We don't support non-local date input yet"
|
279
|
-
|
280
|
-
dates.each do |date|
|
281
|
-
id = insert("INSERT INTO users (name, fired_at) VALUES (?, ?)", 'Sam', date)
|
282
|
-
|
283
|
-
select("SELECT fired_at FROM users WHERE id = ?", [DateTime], id) do |reader|
|
284
|
-
reader.values.last.to_s.should == now.to_s
|
285
|
-
end
|
286
|
-
|
287
|
-
exec("DELETE FROM users WHERE id = ?", id)
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
end
|
293
|
-
|
294
|
-
describe "executing a non-query" do
|
295
|
-
it "should return a Result" do
|
296
|
-
command = @connection.create_command("INSERT INTO invoices (invoice_number) VALUES ('1234')")
|
297
|
-
result = command.execute_non_query
|
298
|
-
result.should be_kind_of(DataObjects::Mysql::Result)
|
299
|
-
end
|
300
|
-
|
301
|
-
it "should be able to determine the affected_rows" do
|
302
|
-
command = @connection.create_command("INSERT INTO invoices (invoice_number) VALUES ('1234')")
|
303
|
-
result = command.execute_non_query
|
304
|
-
result.to_i.should == 1
|
305
|
-
end
|
306
|
-
|
307
|
-
it "should yield the last inserted id" do
|
308
|
-
@connection.create_command("TRUNCATE TABLE invoices").execute_non_query
|
309
|
-
|
310
|
-
result = @connection.create_command("INSERT INTO invoices (invoice_number) VALUES ('1234')").execute_non_query
|
311
|
-
result.insert_id.should == 1
|
312
|
-
|
313
|
-
result = @connection.create_command("INSERT INTO invoices (invoice_number) VALUES ('3456')").execute_non_query
|
314
|
-
result.insert_id.should == 2
|
315
|
-
end
|
316
|
-
|
317
|
-
it "should be able to determine the affected_rows" do
|
318
|
-
[
|
319
|
-
"TRUNCATE TABLE invoices",
|
320
|
-
"INSERT INTO invoices (invoice_number) VALUES ('1234')",
|
321
|
-
"INSERT INTO invoices (invoice_number) VALUES ('1234')"
|
322
|
-
].each { |q| @connection.create_command(q).execute_non_query }
|
323
|
-
|
324
|
-
result = @connection.create_command("UPDATE invoices SET invoice_number = '3456'").execute_non_query
|
325
|
-
result.to_i.should == 2
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should raise an error when executing an invalid query" do
|
329
|
-
command = @connection.create_command("UPDwhoopsATE invoices SET invoice_number = '3456'")
|
330
|
-
|
331
|
-
lambda { command.execute_non_query }.should raise_error(Exception)
|
332
|
-
end
|
333
|
-
|
334
|
-
# it "should raise an error when inserting the wrong typed data" do
|
335
|
-
# command = @connection.create_command("UPDATE invoices SET invoice_number = ?")
|
336
|
-
# command.execute_non_query(1)
|
337
|
-
# end
|
338
|
-
|
339
|
-
end
|
340
|
-
|
341
|
-
end
|