activerecord-jdbc-adapter 0.9.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +163 -0
- data/Manifest.txt +130 -65
- data/README.txt +64 -72
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -633
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
- data/lib/activerecord-jdbc-adapter.rb +6 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/db2.rb +15 -0
- data/lib/arel/visitors/derby.rb +19 -0
- data/lib/arel/visitors/hsqldb.rb +24 -0
- data/lib/arel/visitors/mssql.rb +44 -0
- data/lib/arjdbc.rb +29 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +413 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +58 -132
- data/lib/arjdbc/derby/connection_methods.rb +18 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +36 -14
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +36 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +34 -62
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +10 -19
- data/lib/arjdbc/informix/connection_methods.rb +10 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +285 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +38 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +128 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +36 -26
- data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +17 -16
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +472 -0
- data/lib/arjdbc/mssql/connection_methods.rb +30 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
- data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +2 -1
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +416 -0
- data/lib/arjdbc/mysql/connection_methods.rb +27 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +68 -33
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +147 -72
- data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +381 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -27
- data/lib/jdbc_adapter/rake_tasks.rb +3 -10
- data/lib/jdbc_adapter/version.rb +3 -5
- data/lib/pg.rb +23 -1
- data/rails_generators/jdbc_generator.rb +2 -2
- data/rails_generators/templates/{jdbc.rb → config/initializers/jdbc.rb} +1 -1
- data/rails_generators/templates/{jdbc.rake → lib/tasks/jdbc.rake} +2 -2
- data/rakelib/compile.rake +5 -3
- data/rakelib/db.rake +19 -0
- data/rakelib/package.rake +12 -6
- data/rakelib/test.rake +24 -14
- data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +63 -34
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/{jdbc_adapter/MssqlRubyJdbcConnection.java → arjdbc/informix/InformixRubyJdbcConnection.java} +15 -12
- data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +21 -8
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +210 -67
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/test/abstract_db_create.rb +98 -19
- data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
- data/test/db/db2.rb +4 -2
- data/test/db/derby.rb +12 -14
- data/test/db/hsqldb.rb +3 -2
- data/test/db/jndi_config.rb +22 -12
- data/test/db/mssql.rb +5 -5
- data/test/db/sqlite3.rb +2 -6
- data/test/db2_simple_test.rb +56 -0
- data/test/derby_migration_test.rb +50 -3
- data/test/derby_simple_test.rb +87 -0
- data/test/generic_jdbc_connection_test.rb +21 -1
- data/test/h2_simple_test.rb +35 -0
- data/test/jdbc_common.rb +4 -5
- data/test/jndi_callbacks_test.rb +3 -1
- data/test/jndi_test.rb +1 -11
- data/test/models/entry.rb +20 -0
- data/test/models/mixed_case.rb +7 -2
- data/test/models/string_id.rb +18 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_simple_test.rb +49 -0
- data/test/mysql_db_create_test.rb +8 -6
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_simple_test.rb +19 -1
- data/test/oracle_simple_test.rb +9 -20
- data/test/oracle_specific_test.rb +83 -0
- data/test/pick_rails_version.rb +3 -0
- data/test/postgres_db_create_test.rb +11 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_mixed_case_test.rb +11 -1
- data/test/postgres_nonseq_pkey_test.rb +0 -2
- data/test/postgres_schema_search_path_test.rb +44 -0
- data/test/postgres_simple_test.rb +53 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/simple.rb +103 -9
- data/test/sqlite3_simple_test.rb +1 -0
- data/test/sybase_jtds_simple_test.rb +22 -0
- metadata +239 -137
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
- data/lib/jdbc_adapter/jdbc_db2.rb +0 -191
- data/lib/jdbc_adapter/jdbc_mssql.rb +0 -333
- data/lib/jdbc_adapter/jdbc_mysql.rb +0 -236
- data/lib/jdbc_adapter/jdbc_sqlite3.rb +0 -379
- data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
- data/src/java/jdbc_adapter/SQLBlock.java +0 -27
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
- data/test/cachedb_simple_test.rb +0 -6
- data/test/db/cachedb.rb +0 -9
- data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
- data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
- data/test/minirunit.rb +0 -109
- data/test/minirunit/testConnect.rb +0 -14
- data/test/minirunit/testH2.rb +0 -73
- data/test/minirunit/testHsqldb.rb +0 -73
- data/test/minirunit/testLoadActiveRecord.rb +0 -3
- data/test/minirunit/testMysql.rb +0 -83
- data/test/minirunit/testRawSelect.rb +0 -24
data/lib/jdbc_adapter.rb
CHANGED
@@ -1,27 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
tried_gem ||= false
|
4
|
-
require 'active_record/version'
|
5
|
-
rescue LoadError
|
6
|
-
raise if tried_gem
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'activerecord'
|
9
|
-
tried_gem = true
|
10
|
-
retry
|
11
|
-
end
|
12
|
-
if ActiveRecord::VERSION::MAJOR < 2
|
13
|
-
if defined?(RAILS_CONNECTION_ADAPTERS)
|
14
|
-
RAILS_CONNECTION_ADAPTERS << %q(jdbc)
|
15
|
-
else
|
16
|
-
RAILS_CONNECTION_ADAPTERS = %w(jdbc)
|
17
|
-
end
|
18
|
-
if ActiveRecord::VERSION::MAJOR == 1 && ActiveRecord::VERSION::MINOR == 14
|
19
|
-
require 'active_record/connection_adapters/jdbc_adapter'
|
20
|
-
end
|
21
|
-
else
|
22
|
-
require 'active_record'
|
23
|
-
require 'active_record/connection_adapters/jdbc_adapter'
|
24
|
-
end
|
25
|
-
else
|
26
|
-
warn "ActiveRecord-JDBC is for use with JRuby only"
|
27
|
-
end
|
1
|
+
warn "DEPRECATED: require 'arjdbc' instead of 'jdbc_adapter'."
|
2
|
+
require 'arjdbc'
|
@@ -1,10 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# rails tasks already defined; load the override tasks now
|
5
|
-
load jdbc_rakefile
|
6
|
-
else
|
7
|
-
# rails tasks not loaded yet; load as an import
|
8
|
-
Rake.application.add_import(jdbc_rakefile)
|
9
|
-
end
|
10
|
-
end
|
1
|
+
warn "DEPRECATED: require 'arjdbc/rake_tasks' instead of 'jdbc_adapter/rake_tasks'."
|
2
|
+
require 'arjdbc/jdbc/rake_tasks'
|
3
|
+
|
data/lib/jdbc_adapter/version.rb
CHANGED
data/lib/pg.rb
CHANGED
@@ -1,4 +1,26 @@
|
|
1
1
|
# Stub library for postgresql -- allows Rails to load
|
2
|
-
# postgresql_adapter without error Other than postgres-pr, there's no
|
2
|
+
# postgresql_adapter without error. Other than postgres-pr, there's no
|
3
3
|
# other way to use PostgreSQL on JRuby anyway, right? If you've
|
4
4
|
# installed ar-jdbc you probably want to use that to connect to pg.
|
5
|
+
#
|
6
|
+
# If by chance this library is installed in another Ruby and this file
|
7
|
+
# got required then we'll just continue to try to load the next pg.rb
|
8
|
+
# in the $LOAD_PATH.
|
9
|
+
|
10
|
+
unless defined?(JRUBY_VERSION)
|
11
|
+
gem 'pg' if respond_to?(:gem) # make sure pg gem is activated
|
12
|
+
after_current_file = false
|
13
|
+
$LOAD_PATH.each do |p|
|
14
|
+
require_file = File.join(p, 'pg.rb')
|
15
|
+
|
16
|
+
if File.expand_path(require_file) == File.expand_path(__FILE__)
|
17
|
+
after_current_file = true
|
18
|
+
next
|
19
|
+
end
|
20
|
+
|
21
|
+
if after_current_file && File.exist?(require_file)
|
22
|
+
load require_file
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -2,9 +2,9 @@ class JdbcGenerator < Rails::Generator::Base
|
|
2
2
|
def manifest
|
3
3
|
record do |m|
|
4
4
|
m.directory 'config/initializers'
|
5
|
-
m.template 'jdbc.rb', File.join('config', 'initializers', 'jdbc.rb')
|
5
|
+
m.template 'config/initializers/jdbc.rb', File.join('config', 'initializers', 'jdbc.rb')
|
6
6
|
m.directory 'lib/tasks'
|
7
|
-
m.template 'jdbc.rake', File.join('lib', 'tasks', 'jdbc.rake')
|
7
|
+
m.template 'lib/tasks/jdbc.rake', File.join('lib', 'tasks', 'jdbc.rake')
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
data/rakelib/compile.rake
CHANGED
@@ -12,12 +12,14 @@ def java_classpath_arg # myriad of ways to discover JRuby classpath
|
|
12
12
|
jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
|
13
13
|
end
|
14
14
|
|
15
|
+
jar_name = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
|
16
|
+
|
15
17
|
desc "Compile the native Java code."
|
16
18
|
task :java_compile do
|
19
|
+
debug = ENV['DEBUG'] ? '-g' : ''
|
17
20
|
pkg_classes = File.join(*%w(pkg classes))
|
18
|
-
jar_name = File.join(*%w(lib jdbc_adapter jdbc_adapter_internal.jar))
|
19
21
|
mkdir_p pkg_classes
|
20
|
-
sh "javac -target 1.5 -source 1.5 -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
22
|
+
sh "javac -target 1.5 -source 1.5 #{debug} -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
21
23
|
sh "jar cf #{jar_name} -C #{pkg_classes} ."
|
22
24
|
end
|
23
|
-
file
|
25
|
+
file jar_name => :java_compile
|
data/rakelib/db.rake
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
namespace :db do
|
2
|
+
task :load_arjdbc do
|
3
|
+
$LOAD_PATH.unshift 'test'
|
4
|
+
$LOAD_PATH.unshift 'lib'
|
5
|
+
require 'abstract_db_create'
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Creates the test database for MySQL."
|
9
|
+
task :mysql => :load_arjdbc do
|
10
|
+
load 'test/db/mysql.rb' rescue nil
|
11
|
+
def db_config
|
12
|
+
MYSQL_CONFIG
|
13
|
+
end
|
14
|
+
extend AbstractDbCreate
|
15
|
+
do_setup('arjdbc', nil)
|
16
|
+
Rake::Task['db:drop'].invoke rescue nil
|
17
|
+
Rake::Task['db:create'].invoke
|
18
|
+
end
|
19
|
+
end
|
data/rakelib/package.rake
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt",
|
2
|
-
"Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/
|
2
|
+
"Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/arjdbc/jdbc/adapter_java.jar", "test/**/*.rb",
|
3
3
|
"lib/**/*.rake", "src/**/*.java", "rakelib/*.rake", "rails_generators/**/*"]
|
4
4
|
|
5
5
|
file "Manifest.txt" => :manifest
|
@@ -8,11 +8,13 @@ task :manifest do
|
|
8
8
|
end
|
9
9
|
Rake::Task['manifest'].invoke # Always regen manifest, so Hoe has up-to-date list of files
|
10
10
|
|
11
|
-
require File.dirname(__FILE__) + "/../lib/
|
11
|
+
require File.dirname(__FILE__) + "/../lib/arjdbc/version"
|
12
12
|
begin
|
13
13
|
require 'hoe'
|
14
|
+
Hoe.plugin :gemcutter
|
14
15
|
hoe = Hoe.spec("activerecord-jdbc-adapter") do |p|
|
15
|
-
p.version =
|
16
|
+
p.version = ArJdbc::Version::VERSION
|
17
|
+
p.spec_extras[:files] = MANIFEST
|
16
18
|
p.rubyforge_name = "jruby-extras"
|
17
19
|
p.url = "http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter"
|
18
20
|
p.author = "Nick Sieger, Ola Bini and JRuby contributors"
|
@@ -21,9 +23,12 @@ begin
|
|
21
23
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
22
24
|
p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
|
23
25
|
end
|
24
|
-
hoe.spec.
|
25
|
-
hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
|
26
|
+
hoe.spec.rdoc_options += ["-SHN", "-f", "darkfish"]
|
26
27
|
|
28
|
+
task :gemspec do
|
29
|
+
File.open("#{hoe.name}.gemspec", "w") {|f| f << hoe.spec.to_ruby }
|
30
|
+
end
|
31
|
+
task :package => :gemspec
|
27
32
|
rescue LoadError => le
|
28
33
|
puts le.to_s, *le.backtrace
|
29
34
|
puts "Problem loading Hoe; please check the error above to ensure that Hoe is installed correctly"
|
@@ -38,12 +43,13 @@ end
|
|
38
43
|
%w(test package install_gem release clean).each do |task|
|
39
44
|
desc "Run rake #{task} on all available adapters and drivers"
|
40
45
|
task "all:#{task}" => task
|
46
|
+
task "adapters:#{task}" => task
|
41
47
|
end
|
42
48
|
|
43
49
|
(Dir["drivers/*/Rakefile"] + Dir["adapters/*/Rakefile"]).each do |rakefile|
|
44
50
|
dir = File.dirname(rakefile)
|
45
51
|
prefix = dir.sub(%r{/}, ':')
|
46
|
-
tasks = %w(package install_gem debug_gem clean)
|
52
|
+
tasks = %w(package install_gem debug_gem clean gemspec)
|
47
53
|
tasks << "test" if File.directory?(File.join(dir, "test"))
|
48
54
|
tasks.each do |task|
|
49
55
|
desc "Run rake #{task} on #{dir}"
|
data/rakelib/test.rake
CHANGED
@@ -1,41 +1,51 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../test/helper', __FILE__)
|
2
2
|
if defined?(JRUBY_VERSION)
|
3
|
-
databases = [:test_mysql, :test_jdbc, :test_derby, :test_hsqldb, :test_h2
|
3
|
+
databases = [:test_mysql, :test_jdbc, :test_sqlite3, :test_derby, :test_hsqldb, :test_h2]
|
4
4
|
if find_executable?("psql") && `psql -c '\\l'` && $?.exitstatus == 0
|
5
5
|
databases << :test_postgres
|
6
6
|
end
|
7
|
+
if File.exist?('test/fscontext.jar')
|
8
|
+
databases << :test_jndi
|
9
|
+
end
|
7
10
|
task :test => databases
|
8
11
|
else
|
9
12
|
task :test => [:test_mysql]
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
if driver == "derby"
|
15
|
+
def declare_test_task_for(adapter, options = {})
|
16
|
+
driver = options[:driver] || adapter
|
17
|
+
Rake::TestTask.new("test_#{adapter}") do |t|
|
18
|
+
files = FileList["test/#{adapter}*test.rb"]
|
19
|
+
if adapter == "derby"
|
18
20
|
files << 'test/activerecord/connection_adapters/type_conversion_test.rb'
|
19
21
|
end
|
20
22
|
t.test_files = files
|
21
23
|
t.libs = []
|
22
24
|
if defined?(JRUBY_VERSION)
|
23
25
|
t.ruby_opts << "-rjdbc/#{driver}"
|
24
|
-
t.libs << "lib" << "
|
25
|
-
t.libs.push *FileList["adapters/#{
|
26
|
+
t.libs << "lib" << "drivers/#{driver}/lib"
|
27
|
+
t.libs.push *FileList["adapters/#{adapter}*/lib"]
|
26
28
|
end
|
27
29
|
t.libs << "test"
|
28
30
|
t.verbose = true
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
declare_test_task_for :derby
|
35
|
+
declare_test_task_for :h2
|
36
|
+
declare_test_task_for :hsqldb
|
37
|
+
declare_test_task_for :mssql, :driver => :jtds
|
38
|
+
declare_test_task_for :mysql
|
39
|
+
declare_test_task_for :postgres
|
40
|
+
declare_test_task_for :sqlite3
|
41
|
+
|
32
42
|
Rake::TestTask.new(:test_jdbc) do |t|
|
33
|
-
t.test_files = FileList['test/generic_jdbc_connection_test.rb'
|
43
|
+
t.test_files = FileList['test/generic_jdbc_connection_test.rb']
|
34
44
|
t.libs << 'test' << 'drivers/mysql/lib'
|
35
45
|
end
|
36
46
|
|
37
47
|
Rake::TestTask.new(:test_jndi) do |t|
|
38
|
-
t.test_files = FileList['test/
|
48
|
+
t.test_files = FileList['test/jndi*_test.rb']
|
39
49
|
t.libs << 'test' << 'drivers/derby/lib'
|
40
50
|
end
|
41
51
|
|
@@ -43,9 +53,9 @@ task :test_postgresql => [:test_postgres]
|
|
43
53
|
task :test_pgsql => [:test_postgres]
|
44
54
|
|
45
55
|
# Ensure driver for these DBs is on your classpath
|
46
|
-
%w(oracle db2 cachedb
|
56
|
+
%w(oracle db2 cachedb informix).each do |d|
|
47
57
|
Rake::TestTask.new("test_#{d}") do |t|
|
48
|
-
t.test_files = FileList["test/#{d}
|
58
|
+
t.test_files = FileList["test/#{d}*_test.rb"]
|
49
59
|
t.libs = []
|
50
60
|
t.libs << 'lib' if defined?(JRUBY_VERSION)
|
51
61
|
t.libs << 'test'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/***** BEGIN LICENSE BLOCK *****
|
2
|
-
* Copyright (c) 2006-2007 Nick Sieger <nick@nicksieger.com>
|
2
|
+
* Copyright (c) 2006-2007, 2010 Nick Sieger <nick@nicksieger.com>
|
3
3
|
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
4
|
-
*
|
4
|
+
*
|
5
5
|
* Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
* a copy of this software and associated documentation files (the
|
7
7
|
* "Software"), to deal in the Software without restriction, including
|
@@ -9,10 +9,10 @@
|
|
9
9
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
10
10
|
* permit persons to whom the Software is furnished to do so, subject to
|
11
11
|
* the following conditions:
|
12
|
-
*
|
12
|
+
*
|
13
13
|
* The above copyright notice and this permission notice shall be
|
14
14
|
* included in all copies or substantial portions of the Software.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
17
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
18
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -22,33 +22,33 @@
|
|
22
22
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
***** END LICENSE BLOCK *****/
|
24
24
|
|
25
|
-
package
|
25
|
+
package arjdbc.derby;
|
26
|
+
|
27
|
+
import java.sql.SQLException;
|
28
|
+
|
29
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
26
30
|
|
27
31
|
import org.jruby.Ruby;
|
28
|
-
import org.jruby.
|
29
|
-
import org.jruby.RubyString;
|
30
|
-
import org.jruby.RubyFloat;
|
31
|
-
import org.jruby.RubyFixnum;
|
32
|
+
import org.jruby.RubyBigDecimal;
|
32
33
|
import org.jruby.RubyBignum;
|
33
34
|
import org.jruby.RubyBoolean;
|
34
|
-
import org.jruby.
|
35
|
-
import org.jruby.
|
35
|
+
import org.jruby.RubyFixnum;
|
36
|
+
import org.jruby.RubyFloat;
|
37
|
+
import org.jruby.RubyModule;
|
36
38
|
import org.jruby.RubyNumeric;
|
37
|
-
|
38
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
39
|
-
|
40
|
-
import org.jruby.util.ByteList;
|
41
|
-
|
42
|
-
import java.sql.SQLException;
|
43
39
|
import org.jruby.RubyObjectAdapter;
|
40
|
+
import org.jruby.RubyRange;
|
41
|
+
import org.jruby.RubyString;
|
44
42
|
import org.jruby.anno.JRubyMethod;
|
45
43
|
import org.jruby.runtime.ThreadContext;
|
44
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
45
|
+
import org.jruby.util.ByteList;
|
46
46
|
|
47
|
-
public class
|
47
|
+
public class DerbyModule {
|
48
48
|
private static RubyObjectAdapter rubyApi;
|
49
|
-
public static void load(RubyModule
|
50
|
-
RubyModule derby =
|
51
|
-
derby.defineAnnotatedMethods(
|
49
|
+
public static void load(RubyModule arJdbc, RubyObjectAdapter adapter) {
|
50
|
+
RubyModule derby = arJdbc.defineModuleUnder("Derby");
|
51
|
+
derby.defineAnnotatedMethods(DerbyModule.class);
|
52
52
|
RubyModule column = derby.defineModuleUnder("Column");
|
53
53
|
column.defineAnnotatedMethods(Column.class);
|
54
54
|
rubyApi = adapter;
|
@@ -111,6 +111,10 @@ public class JdbcDerbySpec {
|
|
111
111
|
if (args.length > 1) {
|
112
112
|
IRubyObject col = args[1];
|
113
113
|
String type = rubyApi.callMethod(col, "type").toString();
|
114
|
+
// intercept and change value, maybe, if the column type is :text or :string
|
115
|
+
if (type.equals("text") || type.equals("string")) {
|
116
|
+
value = make_ruby_string_for_text_column(context, recv, runtime, value);
|
117
|
+
}
|
114
118
|
if (value instanceof RubyString) {
|
115
119
|
if (type.equals("string")) {
|
116
120
|
return quote_string_with_surround(runtime, "'", (RubyString)value, "'");
|
@@ -131,35 +135,60 @@ public class JdbcDerbySpec {
|
|
131
135
|
return quote_string_with_surround(runtime, "'", RubyString.objAsString(context, value), "'");
|
132
136
|
}
|
133
137
|
}
|
134
|
-
}
|
138
|
+
}
|
135
139
|
return super_quote(context, recv, runtime, value, runtime.getNil());
|
136
140
|
}
|
137
141
|
|
138
|
-
|
142
|
+
/*
|
143
|
+
* Derby is not permissive like MySql. Try and send an Integer to a CLOB or VARCHAR column and Derby will vomit.
|
144
|
+
* This method turns non stringy things into strings.
|
145
|
+
*/
|
146
|
+
private static IRubyObject make_ruby_string_for_text_column(ThreadContext context, IRubyObject recv, Ruby runtime, IRubyObject value) {
|
147
|
+
RubyModule multibyteChars = (RubyModule)
|
148
|
+
((RubyModule) ((RubyModule) runtime.getModule("ActiveSupport")).getConstant("Multibyte")).getConstantAt("Chars");
|
149
|
+
if (value instanceof RubyString || rubyApi.isKindOf(value, multibyteChars) || value.isNil()) {
|
150
|
+
return value;
|
151
|
+
}
|
152
|
+
if (value instanceof RubyBoolean) {
|
153
|
+
return value.isTrue() ? runtime.newString("1") : runtime.newString("0");
|
154
|
+
} else if (value instanceof RubyFloat || value instanceof RubyFixnum || value instanceof RubyBignum) {
|
155
|
+
return RubyString.objAsString(context, value);
|
156
|
+
} else if ( value instanceof RubyBigDecimal) {
|
157
|
+
return rubyApi.callMethod(value, "to_s", runtime.newString("F"));
|
158
|
+
} else {
|
159
|
+
if (rubyApi.callMethod(value, "acts_like?", runtime.newString("date")).isTrue() || rubyApi.callMethod(value, "acts_like?", runtime.newString("time")).isTrue()) {
|
160
|
+
return (RubyString)rubyApi.callMethod(recv, "quoted_date", value);
|
161
|
+
} else {
|
162
|
+
return (RubyString)rubyApi.callMethod(value, "to_yaml");
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
private final static ByteList NULL = new ByteList("NULL".getBytes());
|
139
168
|
|
140
169
|
private static IRubyObject super_quote(ThreadContext context, IRubyObject recv, Ruby runtime, IRubyObject value, IRubyObject col) {
|
141
170
|
if (value.respondsTo("quoted_id")) {
|
142
171
|
return rubyApi.callMethod(value, "quoted_id");
|
143
172
|
}
|
144
|
-
|
173
|
+
|
145
174
|
IRubyObject type = (col.isNil()) ? col : rubyApi.callMethod(col, "type");
|
146
|
-
RubyModule multibyteChars = (RubyModule)
|
175
|
+
RubyModule multibyteChars = (RubyModule)
|
147
176
|
((RubyModule) ((RubyModule) runtime.getModule("ActiveSupport")).getConstant("Multibyte")).getConstantAt("Chars");
|
148
177
|
if (value instanceof RubyString || rubyApi.isKindOf(value, multibyteChars)) {
|
149
178
|
RubyString svalue = RubyString.objAsString(context, value);
|
150
179
|
if (type == runtime.newSymbol("binary") && col.getType().respondsTo("string_to_binary")) {
|
151
|
-
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(col.getType(), "string_to_binary", svalue)), "'");
|
180
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(col.getType(), "string_to_binary", svalue)), "'");
|
152
181
|
} else if (type == runtime.newSymbol("integer") || type == runtime.newSymbol("float")) {
|
153
182
|
return RubyString.objAsString(context, ((type == runtime.newSymbol("integer")) ?
|
154
|
-
rubyApi.callMethod(svalue, "to_i") :
|
183
|
+
rubyApi.callMethod(svalue, "to_i") :
|
155
184
|
rubyApi.callMethod(svalue, "to_f")));
|
156
185
|
} else {
|
157
|
-
return quote_string_with_surround(runtime, "'", svalue, "'");
|
186
|
+
return quote_string_with_surround(runtime, "'", svalue, "'");
|
158
187
|
}
|
159
188
|
} else if (value.isNil()) {
|
160
189
|
return runtime.newString(NULL);
|
161
190
|
} else if (value instanceof RubyBoolean) {
|
162
|
-
return (value.isTrue() ?
|
191
|
+
return (value.isTrue() ?
|
163
192
|
(type == runtime.newSymbol(":integer")) ? runtime.newString("1") : rubyApi.callMethod(recv, "quoted_true") :
|
164
193
|
(type == runtime.newSymbol(":integer")) ? runtime.newString("0") : rubyApi.callMethod(recv, "quoted_false"));
|
165
194
|
} else if((value instanceof RubyFloat) || (value instanceof RubyFixnum) || (value instanceof RubyBignum)) {
|
@@ -167,7 +196,7 @@ public class JdbcDerbySpec {
|
|
167
196
|
} else if(value instanceof RubyBigDecimal) {
|
168
197
|
return rubyApi.callMethod(value, "to_s", runtime.newString("F"));
|
169
198
|
} else if (rubyApi.callMethod(value, "acts_like?", runtime.newString("date")).isTrue() || rubyApi.callMethod(value, "acts_like?", runtime.newString("time")).isTrue()) {
|
170
|
-
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(recv, "quoted_date", value)), "'");
|
199
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(recv, "quoted_date", value)), "'");
|
171
200
|
} else {
|
172
201
|
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(value, "to_yaml")), "'");
|
173
202
|
}
|
@@ -231,14 +260,14 @@ public class JdbcDerbySpec {
|
|
231
260
|
public static IRubyObject quote_string(IRubyObject recv, IRubyObject string) {
|
232
261
|
boolean replacementFound = false;
|
233
262
|
ByteList bl = ((RubyString) string).getByteList();
|
234
|
-
|
263
|
+
|
235
264
|
for(int i = bl.begin; i < bl.begin + bl.realSize; i++) {
|
236
265
|
switch (bl.bytes[i]) {
|
237
266
|
case '\'': break;
|
238
267
|
default: continue;
|
239
268
|
}
|
240
|
-
|
241
|
-
// On first replacement allocate a different bytelist so we don't manip original
|
269
|
+
|
270
|
+
// On first replacement allocate a different bytelist so we don't manip original
|
242
271
|
if(!replacementFound) {
|
243
272
|
i-= bl.begin;
|
244
273
|
bl = new ByteList(bl);
|
@@ -284,7 +313,7 @@ public class JdbcDerbySpec {
|
|
284
313
|
}
|
285
314
|
if (sql.startsWith("insert")) {
|
286
315
|
return conn.execute_insert(context, args[0]);
|
287
|
-
} else if (sql.startsWith("select") || sql.startsWith("show")) {
|
316
|
+
} else if (sql.startsWith("select") || sql.startsWith("show") || sql.startsWith("values")) {
|
288
317
|
return conn.execute_query(context, args[0]);
|
289
318
|
} else {
|
290
319
|
return conn.execute_update(context, args[0]);
|