intentmedia-activerecord-jdbc-adapter 1.1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +404 -0
- data/LICENSE.txt +21 -0
- data/README.txt +181 -0
- data/Rakefile +10 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- 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 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -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/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +21 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +46 -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/arjdbc/derby/adapter.rb +348 -0
- 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/arjdbc/firebird/adapter.rb +131 -0
- 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/arjdbc/hsqldb/adapter.rb +184 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +138 -0
- 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/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/arjdbc/jdbc/jdbc.rake +127 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +87 -0
- 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 +127 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- 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/arjdbc/mssql/tsql_helper.rb +61 -0
- 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/arjdbc/oracle/adapter.rb +412 -0
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +579 -0
- 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 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/compile.rake +25 -0
- data/rakelib/db.rake +19 -0
- data/rakelib/package.rake +91 -0
- data/rakelib/rails.rake +41 -0
- data/rakelib/test.rake +81 -0
- data/src/java/arjdbc/derby/DerbyModule.java +322 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +66 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1305 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +57 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/test/abstract_db_create.rb +124 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +11 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +9 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_simple_test.rb +99 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +5 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +25 -0
- data/test/jndi_callbacks_test.rb +40 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +12 -0
- data/test/models/auto_id.rb +18 -0
- data/test/models/data_types.rb +28 -0
- data/test/models/entry.rb +43 -0
- data/test/models/mixed_case.rb +25 -0
- data/test/models/reserved_word.rb +18 -0
- data/test/models/string_id.rb +18 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -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 +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_simple_test.rb +49 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/pick_rails_version.rb +3 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_schema_search_path_test.rb +44 -0
- data/test/postgres_simple_test.rb +65 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/simple.rb +546 -0
- data/test/sqlite3_simple_test.rb +233 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- metadata +259 -0
data/lib/jdbc_adapter.rb
ADDED
data/lib/pg.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Stub library for postgresql -- allows Rails to load
|
2
|
+
# postgresql_adapter without error. Other than postgres-pr, there's no
|
3
|
+
# other way to use PostgreSQL on JRuby anyway, right? If you've
|
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
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class JdbcGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.directory 'config/initializers'
|
5
|
+
m.template 'config/initializers/jdbc.rb', File.join('config', 'initializers', 'jdbc.rb')
|
6
|
+
m.directory 'lib/tasks'
|
7
|
+
m.template 'lib/tasks/jdbc.rake', File.join('lib', 'tasks', 'jdbc.rake')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def banner
|
13
|
+
"Usage: #{$0} jdbc\nGenerate JDBC bootstrapping files for your Rails application."
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided
|
2
|
+
# by the activerecord-jdbc-adapter gem.
|
3
|
+
#
|
4
|
+
# This file allows the JDBC drivers to be hooked into ActiveRecord
|
5
|
+
# such that you don't have to change anything else in your Rails
|
6
|
+
# application.
|
7
|
+
require 'arjdbc' if defined?(JRUBY_VERSION)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided
|
2
|
+
# by the activerecord-jdbc-adapter gem.
|
3
|
+
#
|
4
|
+
# This file allows you to use Rails' various db:* tasks with JDBC.
|
5
|
+
if defined?(JRUBY_VERSION)
|
6
|
+
require 'arjdbc'
|
7
|
+
require 'arjdbc/jdbc/rake_tasks'
|
8
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
def java_classpath_arg # myriad of ways to discover JRuby classpath
|
2
|
+
begin
|
3
|
+
cpath = Java::java.lang.System.getProperty('java.class.path').split(File::PATH_SEPARATOR)
|
4
|
+
cpath += Java::java.lang.System.getProperty('sun.boot.class.path').split(File::PATH_SEPARATOR)
|
5
|
+
jruby_cpath = cpath.compact.join(File::PATH_SEPARATOR)
|
6
|
+
rescue => e
|
7
|
+
end
|
8
|
+
unless jruby_cpath
|
9
|
+
jruby_cpath = ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] &&
|
10
|
+
FileList["#{ENV['JRUBY_HOME']}/lib/*.jar"].join(File::PATH_SEPARATOR)
|
11
|
+
end
|
12
|
+
jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
|
13
|
+
end
|
14
|
+
|
15
|
+
jar_name = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
|
16
|
+
|
17
|
+
desc "Compile the native Java code."
|
18
|
+
task :java_compile do
|
19
|
+
debug = ENV['DEBUG'] ? '-g' : ''
|
20
|
+
pkg_classes = File.join(*%w(pkg classes))
|
21
|
+
mkdir_p pkg_classes
|
22
|
+
sh "javac -target 1.5 -source 1.5 #{debug} -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
23
|
+
sh "jar cf #{jar_name} -C #{pkg_classes} ."
|
24
|
+
end
|
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
|
@@ -0,0 +1,91 @@
|
|
1
|
+
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt",
|
2
|
+
"Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/arjdbc/jdbc/adapter_java.jar", "test/**/*.rb",
|
3
|
+
"lib/**/*.rake", "src/**/*.java", "rakelib/*.rake", "rails_generators/**/*"]
|
4
|
+
|
5
|
+
file "Manifest.txt" => :manifest
|
6
|
+
task :manifest do
|
7
|
+
File.open("Manifest.txt", "w") {|f| MANIFEST.each {|n| f << "#{n}\n"} }
|
8
|
+
end
|
9
|
+
Rake::Task['manifest'].invoke # Always regen manifest, so Hoe has up-to-date list of files
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + "/../lib/arjdbc/version"
|
12
|
+
begin
|
13
|
+
require 'hoe'
|
14
|
+
Hoe.plugin :gemcutter
|
15
|
+
hoe = Hoe.spec("activerecord-jdbc-adapter") do |p|
|
16
|
+
p.version = ArJdbc::Version::VERSION
|
17
|
+
p.spec_extras[:files] = MANIFEST
|
18
|
+
p.rubyforge_name = "jruby-extras"
|
19
|
+
p.url = "http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter"
|
20
|
+
p.author = "Nick Sieger, Ola Bini and JRuby contributors"
|
21
|
+
p.email = "nick@nicksieger.com, ola.bini@gmail.com"
|
22
|
+
p.summary = "JDBC adapter for ActiveRecord, for use within JRuby on Rails."
|
23
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
24
|
+
p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
|
25
|
+
end
|
26
|
+
hoe.spec.rdoc_options += ["-SHN", "-f", "darkfish"]
|
27
|
+
|
28
|
+
task :gemspec do
|
29
|
+
File.open("#{hoe.name}.gemspec", "w") {|f| f << hoe.spec.to_ruby }
|
30
|
+
end
|
31
|
+
task :package => :gemspec
|
32
|
+
rescue LoadError => le
|
33
|
+
puts le.to_s, *le.backtrace
|
34
|
+
puts "Problem loading Hoe; please check the error above to ensure that Hoe is installed correctly"
|
35
|
+
rescue => e
|
36
|
+
puts "ignoring error while loading Hoe: #{e.to_s}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def rake(*args)
|
40
|
+
ruby "-S", "rake", *args
|
41
|
+
end
|
42
|
+
|
43
|
+
%w(test package install_gem release clean).each do |task|
|
44
|
+
desc "Run rake #{task} on all available adapters and drivers"
|
45
|
+
task "all:#{task}" => task
|
46
|
+
task "adapters:#{task}" => task
|
47
|
+
end
|
48
|
+
|
49
|
+
(Dir["drivers/*/Rakefile"] + Dir["adapters/*/Rakefile"]).each do |rakefile|
|
50
|
+
dir = File.dirname(rakefile)
|
51
|
+
prefix = dir.sub(%r{/}, ':')
|
52
|
+
tasks = %w(package install_gem debug_gem clean gemspec)
|
53
|
+
tasks << "test" if File.directory?(File.join(dir, "test"))
|
54
|
+
tasks.each do |task|
|
55
|
+
desc "Run rake #{task} on #{dir}"
|
56
|
+
task "#{prefix}:#{task}" do
|
57
|
+
Dir.chdir(dir) do
|
58
|
+
rake task
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
task "#{File.dirname(dir)}:#{task}" => "#{prefix}:#{task}"
|
63
|
+
task "all:#{task}" => "#{prefix}:#{task}"
|
64
|
+
end
|
65
|
+
|
66
|
+
# Copy all generated gems to the top-level pkg directory for convenience
|
67
|
+
task "#{prefix}:package" do
|
68
|
+
FileList["#{dir}/pkg/*.gem"].each {|gem| cp gem, "pkg"}
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Run rake release on #{dir}"
|
72
|
+
task "#{prefix}:release" do
|
73
|
+
Dir.chdir(dir) do
|
74
|
+
version = nil
|
75
|
+
if dir =~ /adapters/
|
76
|
+
version = ENV['VERSION']
|
77
|
+
else
|
78
|
+
Dir["lib/**/*.rb"].each do |file|
|
79
|
+
version ||= File.open(file) {|f| f.read =~ /VERSION = "([^"]+)"/ && $1}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
rake "release", "VERSION=#{version}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
# Only release adapters synchronously with main release. Drivers are versioned
|
86
|
+
# according to their JDBC driver versions.
|
87
|
+
if dir =~ /adapters/
|
88
|
+
task "adapters:release" => "#{prefix}:release"
|
89
|
+
task "all:release" => "#{prefix}:release"
|
90
|
+
end
|
91
|
+
end
|
data/rakelib/rails.rake
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
namespace :rails do
|
2
|
+
def _adapter(n)
|
3
|
+
case n
|
4
|
+
when /postgres/
|
5
|
+
'postgresql'
|
6
|
+
else
|
7
|
+
n
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def _driver(n)
|
12
|
+
case n
|
13
|
+
when /postgres/
|
14
|
+
'postgres'
|
15
|
+
else
|
16
|
+
n
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def _target(n)
|
21
|
+
case n
|
22
|
+
when /postgres/
|
23
|
+
'test_jdbcpostgresql'
|
24
|
+
else
|
25
|
+
"test_jdbc#{n}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
task :test => "java_compile" do
|
30
|
+
driver = ENV['DRIVER']
|
31
|
+
raise "need a DRIVER" unless driver
|
32
|
+
activerecord = ENV['RAILS']
|
33
|
+
raise "need location of RAILS source code" unless activerecord
|
34
|
+
activerecord = File.join(activerecord, 'activerecord') unless activerecord =~ /activerecord$/
|
35
|
+
ar_jdbc = File.expand_path(File.dirname(__FILE__) + '/..')
|
36
|
+
rubylib = "#{ar_jdbc}/lib:#{ar_jdbc}/drivers/#{_driver(driver)}/lib:#{ar_jdbc}/adapters/#{_adapter(driver)}/lib"
|
37
|
+
Dir.chdir(activerecord) do
|
38
|
+
rake "RUBYLIB=#{rubylib}", "#{_target(driver)}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/rakelib/test.rake
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path('../../test/helper', __FILE__)
|
2
|
+
if defined?(JRUBY_VERSION)
|
3
|
+
databases = [:test_mysql, :test_jdbc, :test_sqlite3, :test_derby, :test_hsqldb, :test_h2]
|
4
|
+
if find_executable?("psql") && `psql -c '\\l'` && $?.exitstatus == 0
|
5
|
+
databases << :test_postgres
|
6
|
+
end
|
7
|
+
if File.exist?('test/fscontext.jar')
|
8
|
+
databases << :test_jndi
|
9
|
+
end
|
10
|
+
task :test => databases
|
11
|
+
else
|
12
|
+
task :test => [:test_mysql]
|
13
|
+
end
|
14
|
+
|
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"
|
20
|
+
files << 'test/activerecord/connection_adapters/type_conversion_test.rb'
|
21
|
+
end
|
22
|
+
t.test_files = files
|
23
|
+
t.libs = []
|
24
|
+
if defined?(JRUBY_VERSION)
|
25
|
+
t.ruby_opts << "-rjdbc/#{driver}"
|
26
|
+
t.libs << "lib" << "drivers/#{driver}/lib"
|
27
|
+
t.libs.push *FileList["adapters/#{adapter}*/lib"]
|
28
|
+
end
|
29
|
+
t.libs << "test"
|
30
|
+
t.verbose = true
|
31
|
+
end
|
32
|
+
end
|
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
|
+
|
42
|
+
Rake::TestTask.new(:test_jdbc) do |t|
|
43
|
+
t.test_files = FileList['test/generic_jdbc_connection_test.rb']
|
44
|
+
t.libs << 'test' << 'drivers/mysql/lib'
|
45
|
+
end
|
46
|
+
|
47
|
+
Rake::TestTask.new(:test_jndi) do |t|
|
48
|
+
t.test_files = FileList['test/jndi*_test.rb']
|
49
|
+
t.libs << 'test' << 'drivers/derby/lib'
|
50
|
+
end
|
51
|
+
|
52
|
+
task :test_postgresql => [:test_postgres]
|
53
|
+
task :test_pgsql => [:test_postgres]
|
54
|
+
|
55
|
+
# Ensure driver for these DBs is on your classpath
|
56
|
+
%w(oracle db2 cachedb informix).each do |d|
|
57
|
+
Rake::TestTask.new("test_#{d}") do |t|
|
58
|
+
t.test_files = FileList["test/#{d}*_test.rb"]
|
59
|
+
t.libs = []
|
60
|
+
t.libs << 'lib' if defined?(JRUBY_VERSION)
|
61
|
+
t.libs << 'test'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Tests for JDBC adapters that don't require a database.
|
66
|
+
Rake::TestTask.new(:test_jdbc_adapters) do | t |
|
67
|
+
t.test_files = FileList[ 'test/jdbc_adapter/jdbc_sybase_test.rb' ]
|
68
|
+
t.libs << 'test'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Ensure that the jTDS driver is in your classpath before launching rake
|
72
|
+
Rake::TestTask.new(:test_sybase_jtds) do |t|
|
73
|
+
t.test_files = FileList['test/sybase_jtds_simple_test.rb']
|
74
|
+
t.libs << 'test'
|
75
|
+
end
|
76
|
+
|
77
|
+
# Ensure that the jConnect driver is in your classpath before launching rake
|
78
|
+
Rake::TestTask.new(:test_sybase_jconnect) do |t|
|
79
|
+
t.test_files = FileList['test/sybase_jconnect_simple_test.rb']
|
80
|
+
t.libs << 'test'
|
81
|
+
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Copyright (c) 2006-2007, 2010 Nick Sieger <nick@nicksieger.com>
|
3
|
+
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
* a copy of this software and associated documentation files (the
|
7
|
+
* "Software"), to deal in the Software without restriction, including
|
8
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
* the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be
|
14
|
+
* included in all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
***** END LICENSE BLOCK *****/
|
24
|
+
|
25
|
+
package arjdbc.derby;
|
26
|
+
|
27
|
+
import java.sql.SQLException;
|
28
|
+
|
29
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
30
|
+
|
31
|
+
import org.jruby.Ruby;
|
32
|
+
import org.jruby.RubyBigDecimal;
|
33
|
+
import org.jruby.RubyBignum;
|
34
|
+
import org.jruby.RubyBoolean;
|
35
|
+
import org.jruby.RubyFixnum;
|
36
|
+
import org.jruby.RubyFloat;
|
37
|
+
import org.jruby.RubyModule;
|
38
|
+
import org.jruby.RubyNumeric;
|
39
|
+
import org.jruby.RubyObjectAdapter;
|
40
|
+
import org.jruby.RubyRange;
|
41
|
+
import org.jruby.RubyString;
|
42
|
+
import org.jruby.anno.JRubyMethod;
|
43
|
+
import org.jruby.runtime.ThreadContext;
|
44
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
45
|
+
import org.jruby.util.ByteList;
|
46
|
+
|
47
|
+
public class DerbyModule {
|
48
|
+
private static RubyObjectAdapter rubyApi;
|
49
|
+
public static void load(RubyModule arJdbc, RubyObjectAdapter adapter) {
|
50
|
+
RubyModule derby = arJdbc.defineModuleUnder("Derby");
|
51
|
+
derby.defineAnnotatedMethods(DerbyModule.class);
|
52
|
+
RubyModule column = derby.defineModuleUnder("Column");
|
53
|
+
column.defineAnnotatedMethods(Column.class);
|
54
|
+
rubyApi = adapter;
|
55
|
+
}
|
56
|
+
|
57
|
+
public static class Column {
|
58
|
+
@JRubyMethod(name = "type_cast", required = 1)
|
59
|
+
public static IRubyObject type_cast(IRubyObject recv, IRubyObject value) {
|
60
|
+
Ruby runtime = recv.getRuntime();
|
61
|
+
|
62
|
+
if (value.isNil() || ((value instanceof RubyString) && value.toString().trim().equalsIgnoreCase("null"))) {
|
63
|
+
return runtime.getNil();
|
64
|
+
}
|
65
|
+
|
66
|
+
String type = rubyApi.getInstanceVariable(recv, "@type").toString();
|
67
|
+
|
68
|
+
switch (type.charAt(0)) {
|
69
|
+
case 's': //string
|
70
|
+
return value;
|
71
|
+
case 't': //text, timestamp, time
|
72
|
+
if (type.equals("text")) {
|
73
|
+
return value;
|
74
|
+
} else if (type.equals("timestamp")) {
|
75
|
+
return rubyApi.callMethod(recv.getMetaClass(), "string_to_time", value);
|
76
|
+
} else { //time
|
77
|
+
return rubyApi.callMethod(recv.getMetaClass(), "string_to_dummy_time", value);
|
78
|
+
}
|
79
|
+
case 'i': //integer
|
80
|
+
case 'p': //primary key
|
81
|
+
if (value.respondsTo("to_i")) {
|
82
|
+
return rubyApi.callMethod(value, "to_i");
|
83
|
+
} else {
|
84
|
+
return runtime.newFixnum(value.isTrue() ? 1 : 0);
|
85
|
+
}
|
86
|
+
case 'd': //decimal, datetime, date
|
87
|
+
if (type.equals("datetime")) {
|
88
|
+
return rubyApi.callMethod(recv.getMetaClass(), "string_to_time", value);
|
89
|
+
} else if (type.equals("date")) {
|
90
|
+
return rubyApi.callMethod(recv.getMetaClass(), "string_to_date", value);
|
91
|
+
} else {
|
92
|
+
return rubyApi.callMethod(recv.getMetaClass(), "value_to_decimal", value);
|
93
|
+
}
|
94
|
+
case 'f': //float
|
95
|
+
return rubyApi.callMethod(value, "to_f");
|
96
|
+
case 'b': //binary, boolean
|
97
|
+
if (type.equals("binary")) {
|
98
|
+
return rubyApi.callMethod(recv.getMetaClass(), "binary_to_string", value);
|
99
|
+
} else {
|
100
|
+
return rubyApi.callMethod(recv.getMetaClass(), "value_to_boolean", value);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return value;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
@JRubyMethod(name = "quote", required = 1, optional = 1)
|
108
|
+
public static IRubyObject quote(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
109
|
+
Ruby runtime = recv.getRuntime();
|
110
|
+
IRubyObject value = args[0];
|
111
|
+
if (args.length > 1) {
|
112
|
+
IRubyObject col = args[1];
|
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
|
+
}
|
118
|
+
if (value instanceof RubyString) {
|
119
|
+
if (type.equals("string")) {
|
120
|
+
return quote_string_with_surround(runtime, "'", (RubyString)value, "'");
|
121
|
+
} else if (type.equals("text")) {
|
122
|
+
return quote_string_with_surround(runtime, "CAST('", (RubyString)value, "' AS CLOB)");
|
123
|
+
} else if (type.equals("binary")) {
|
124
|
+
return hexquote_string_with_surround(runtime, "CAST(X'", (RubyString)value, "' AS BLOB)");
|
125
|
+
} else {
|
126
|
+
// column type :integer or other numeric or date version
|
127
|
+
if (only_digits((RubyString)value)) {
|
128
|
+
return value;
|
129
|
+
} else {
|
130
|
+
return super_quote(context, recv, runtime, value, col);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
} else if ((value instanceof RubyFloat) || (value instanceof RubyFixnum) || (value instanceof RubyBignum)) {
|
134
|
+
if (type.equals("string")) {
|
135
|
+
return quote_string_with_surround(runtime, "'", RubyString.objAsString(context, value), "'");
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
return super_quote(context, recv, runtime, value, runtime.getNil());
|
140
|
+
}
|
141
|
+
|
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());
|
168
|
+
|
169
|
+
private static IRubyObject super_quote(ThreadContext context, IRubyObject recv, Ruby runtime, IRubyObject value, IRubyObject col) {
|
170
|
+
if (value.respondsTo("quoted_id")) {
|
171
|
+
return rubyApi.callMethod(value, "quoted_id");
|
172
|
+
}
|
173
|
+
|
174
|
+
IRubyObject type = (col.isNil()) ? col : rubyApi.callMethod(col, "type");
|
175
|
+
RubyModule multibyteChars = (RubyModule)
|
176
|
+
((RubyModule) ((RubyModule) runtime.getModule("ActiveSupport")).getConstant("Multibyte")).getConstantAt("Chars");
|
177
|
+
if (value instanceof RubyString || rubyApi.isKindOf(value, multibyteChars)) {
|
178
|
+
RubyString svalue = RubyString.objAsString(context, value);
|
179
|
+
if (type == runtime.newSymbol("binary") && col.getType().respondsTo("string_to_binary")) {
|
180
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(col.getType(), "string_to_binary", svalue)), "'");
|
181
|
+
} else if (type == runtime.newSymbol("integer") || type == runtime.newSymbol("float")) {
|
182
|
+
return RubyString.objAsString(context, ((type == runtime.newSymbol("integer")) ?
|
183
|
+
rubyApi.callMethod(svalue, "to_i") :
|
184
|
+
rubyApi.callMethod(svalue, "to_f")));
|
185
|
+
} else {
|
186
|
+
return quote_string_with_surround(runtime, "'", svalue, "'");
|
187
|
+
}
|
188
|
+
} else if (value.isNil()) {
|
189
|
+
return runtime.newString(NULL);
|
190
|
+
} else if (value instanceof RubyBoolean) {
|
191
|
+
return (value.isTrue() ?
|
192
|
+
(type == runtime.newSymbol(":integer")) ? runtime.newString("1") : rubyApi.callMethod(recv, "quoted_true") :
|
193
|
+
(type == runtime.newSymbol(":integer")) ? runtime.newString("0") : rubyApi.callMethod(recv, "quoted_false"));
|
194
|
+
} else if((value instanceof RubyFloat) || (value instanceof RubyFixnum) || (value instanceof RubyBignum)) {
|
195
|
+
return RubyString.objAsString(context, value);
|
196
|
+
} else if(value instanceof RubyBigDecimal) {
|
197
|
+
return rubyApi.callMethod(value, "to_s", runtime.newString("F"));
|
198
|
+
} else if (rubyApi.callMethod(value, "acts_like?", runtime.newString("date")).isTrue() || rubyApi.callMethod(value, "acts_like?", runtime.newString("time")).isTrue()) {
|
199
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(recv, "quoted_date", value)), "'");
|
200
|
+
} else {
|
201
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(value, "to_yaml")), "'");
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
private final static ByteList TWO_SINGLE = new ByteList(new byte[]{'\'','\''});
|
206
|
+
|
207
|
+
private static IRubyObject quote_string_with_surround(Ruby runtime, String before, RubyString string, String after) {
|
208
|
+
ByteList input = string.getByteList();
|
209
|
+
ByteList output = new ByteList(before.getBytes());
|
210
|
+
for(int i = input.begin; i< input.begin + input.realSize; i++) {
|
211
|
+
switch(input.bytes[i]) {
|
212
|
+
case '\'':
|
213
|
+
output.append(input.bytes[i]);
|
214
|
+
//FALLTHROUGH
|
215
|
+
default:
|
216
|
+
output.append(input.bytes[i]);
|
217
|
+
}
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
output.append(after.getBytes());
|
222
|
+
|
223
|
+
return runtime.newString(output);
|
224
|
+
}
|
225
|
+
|
226
|
+
private final static byte[] HEX = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
227
|
+
|
228
|
+
private static IRubyObject hexquote_string_with_surround(Ruby runtime, String before, RubyString string, String after) {
|
229
|
+
ByteList input = string.getByteList();
|
230
|
+
ByteList output = new ByteList(before.getBytes());
|
231
|
+
int written = 0;
|
232
|
+
for(int i = input.begin; i< input.begin + input.realSize; i++) {
|
233
|
+
byte b1 = input.bytes[i];
|
234
|
+
byte higher = HEX[(((char)b1)>>4)%16];
|
235
|
+
byte lower = HEX[((char)b1)%16];
|
236
|
+
output.append(higher);
|
237
|
+
output.append(lower);
|
238
|
+
written += 2;
|
239
|
+
if(written >= 16334) { // max hex length = 16334
|
240
|
+
output.append("'||X'".getBytes());
|
241
|
+
written = 0;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
output.append(after.getBytes());
|
246
|
+
return runtime.newStringShared(output);
|
247
|
+
}
|
248
|
+
|
249
|
+
private static boolean only_digits(RubyString inp) {
|
250
|
+
ByteList input = inp.getByteList();
|
251
|
+
for(int i = input.begin; i< input.begin + input.realSize; i++) {
|
252
|
+
if(input.bytes[i] < '0' || input.bytes[i] > '9') {
|
253
|
+
return false;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return true;
|
257
|
+
}
|
258
|
+
|
259
|
+
@JRubyMethod(name = "quote_string", required = 1)
|
260
|
+
public static IRubyObject quote_string(IRubyObject recv, IRubyObject string) {
|
261
|
+
boolean replacementFound = false;
|
262
|
+
ByteList bl = ((RubyString) string).getByteList();
|
263
|
+
|
264
|
+
for(int i = bl.begin; i < bl.begin + bl.realSize; i++) {
|
265
|
+
switch (bl.bytes[i]) {
|
266
|
+
case '\'': break;
|
267
|
+
default: continue;
|
268
|
+
}
|
269
|
+
|
270
|
+
// On first replacement allocate a different bytelist so we don't manip original
|
271
|
+
if(!replacementFound) {
|
272
|
+
i-= bl.begin;
|
273
|
+
bl = new ByteList(bl);
|
274
|
+
replacementFound = true;
|
275
|
+
}
|
276
|
+
|
277
|
+
bl.replace(i, 1, TWO_SINGLE);
|
278
|
+
i+=1;
|
279
|
+
}
|
280
|
+
if(replacementFound) {
|
281
|
+
return recv.getRuntime().newStringShared(bl);
|
282
|
+
} else {
|
283
|
+
return string;
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
@JRubyMethod(name = "select_all", rest = true)
|
288
|
+
public static IRubyObject select_all(IRubyObject recv, IRubyObject[] args) {
|
289
|
+
return rubyApi.callMethod(recv, "execute", args);
|
290
|
+
}
|
291
|
+
|
292
|
+
@JRubyMethod(name = "select_one", rest = true)
|
293
|
+
public static IRubyObject select_one(IRubyObject recv, IRubyObject[] args) {
|
294
|
+
IRubyObject limit = rubyApi.getInstanceVariable(recv, "@limit");
|
295
|
+
if (limit == null || limit.isNil()) {
|
296
|
+
rubyApi.setInstanceVariable(recv, "@limit", recv.getRuntime().newFixnum(1));
|
297
|
+
}
|
298
|
+
try {
|
299
|
+
IRubyObject result = rubyApi.callMethod(recv, "execute", args);
|
300
|
+
return rubyApi.callMethod(result, "first");
|
301
|
+
} finally {
|
302
|
+
rubyApi.setInstanceVariable(recv, "@limit", recv.getRuntime().getNil());
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
@JRubyMethod(name = "_execute", required = 1, optional = 1)
|
307
|
+
public static IRubyObject _execute(ThreadContext context, IRubyObject recv, IRubyObject[] args) throws SQLException, java.io.IOException {
|
308
|
+
Ruby runtime = recv.getRuntime();
|
309
|
+
RubyJdbcConnection conn = (RubyJdbcConnection) rubyApi.getInstanceVariable(recv, "@connection");
|
310
|
+
String sql = args[0].toString().trim().toLowerCase();
|
311
|
+
if (sql.charAt(0) == '(') {
|
312
|
+
sql = sql.substring(1).trim();
|
313
|
+
}
|
314
|
+
if (sql.startsWith("insert")) {
|
315
|
+
return conn.execute_insert(context, args[0]);
|
316
|
+
} else if (sql.startsWith("select") || sql.startsWith("show") || sql.startsWith("values")) {
|
317
|
+
return conn.execute_query(context, args[0]);
|
318
|
+
} else {
|
319
|
+
return conn.execute_update(context, args[0]);
|
320
|
+
}
|
321
|
+
}
|
322
|
+
}
|