activerecord-jdbc-adapter 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +33 -0
- data/Manifest.txt +17 -0
- data/README.txt +48 -20
- data/Rakefile +2 -169
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +11 -5
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +12 -0
- data/lib/jdbc_adapter.rb +1 -1
- data/lib/jdbc_adapter/jdbc.rake +43 -30
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_db2.rb +2 -2
- data/lib/jdbc_adapter/jdbc_derby.rb +11 -0
- data/lib/jdbc_adapter/jdbc_hsqldb.rb +6 -1
- data/lib/jdbc_adapter/jdbc_mimer.rb +14 -7
- data/lib/jdbc_adapter/jdbc_mssql.rb +18 -2
- data/lib/jdbc_adapter/jdbc_mysql.rb +3 -0
- data/lib/jdbc_adapter/jdbc_oracle.rb +24 -14
- data/lib/jdbc_adapter/jdbc_postgre.rb +38 -18
- data/lib/jdbc_adapter/jdbc_sqlite3.rb +96 -26
- data/lib/jdbc_adapter/missing_functionality_helper.rb +40 -34
- data/lib/jdbc_adapter/rake_tasks.rb +1 -1
- data/lib/jdbc_adapter/tsql_helper.rb +1 -0
- data/lib/jdbc_adapter/version.rb +1 -1
- data/lib/pg.rb +4 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/jdbc.rake +8 -0
- data/rails_generators/templates/jdbc.rb +7 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/package.rake +85 -0
- data/rakelib/rails.rake +41 -0
- data/rakelib/test.rake +71 -0
- data/src/java/jdbc_adapter/JdbcAdapterInternalService.java +1 -0
- data/src/java/jdbc_adapter/JdbcDerbySpec.java +11 -46
- data/src/java/jdbc_adapter/JdbcMySQLSpec.java +3 -2
- data/src/java/jdbc_adapter/MssqlRubyJdbcConnection.java +71 -0
- data/src/java/jdbc_adapter/PostgresRubyJdbcConnection.java +24 -4
- data/src/java/jdbc_adapter/RubyJdbcConnection.java +57 -44
- data/test/abstract_db_create.rb +45 -0
- data/test/db/mysql.rb +2 -2
- data/test/db/postgres.rb +2 -2
- data/test/helper.rb +5 -0
- data/test/jdbc_adapter/jdbc_db2_test.rb +5 -0
- data/test/jdbc_common.rb +2 -0
- data/test/models/entry.rb +3 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mysql_db_create_test.rb +25 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_simple_test.rb +5 -0
- data/test/postgres_db_create_test.rb +21 -0
- data/test/postgres_nonseq_pkey_test.rb +40 -0
- data/test/simple.rb +62 -1
- data/test/sqlite3_simple_test.rb +153 -10
- metadata +26 -5
@@ -8,7 +8,10 @@ module JdbcSpec
|
|
8
8
|
caller = lambda {|definition| yield definition if block_given?}
|
9
9
|
|
10
10
|
transaction do
|
11
|
-
|
11
|
+
# A temporary table might improve performance here, but
|
12
|
+
# it doesn't seem to maintain indices across the whole move.
|
13
|
+
move_table(table_name, altered_table_name,
|
14
|
+
options)
|
12
15
|
move_table(altered_table_name, table_name, &caller)
|
13
16
|
end
|
14
17
|
end
|
@@ -19,28 +22,30 @@ module JdbcSpec
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def copy_table(from, to, options = {}) #:nodoc:
|
22
|
-
|
25
|
+
options = options.merge(:id => (!columns(from).detect{|c| c.name == 'id'}.nil? && 'id' == primary_key(from).to_s))
|
26
|
+
create_table(to, options) do |definition|
|
27
|
+
@definition = definition
|
23
28
|
columns(from).each do |column|
|
24
29
|
column_name = options[:rename] ?
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@definition.column(column_name, column.type,
|
30
|
-
|
31
|
-
|
30
|
+
(options[:rename][column.name] ||
|
31
|
+
options[:rename][column.name.to_sym] ||
|
32
|
+
column.name) : column.name
|
33
|
+
|
34
|
+
@definition.column(column_name, column.type,
|
35
|
+
:limit => column.limit, :default => column.default,
|
36
|
+
:null => column.null)
|
32
37
|
end
|
33
|
-
@definition.primary_key(primary_key(from))
|
38
|
+
@definition.primary_key(primary_key(from)) if primary_key(from)
|
34
39
|
yield @definition if block_given?
|
35
40
|
end
|
36
|
-
|
37
|
-
copy_table_indexes(from, to, options)
|
38
|
-
copy_table_contents(from, to,
|
39
|
-
|
40
|
-
|
41
|
+
|
42
|
+
copy_table_indexes(from, to, options[:rename] || {})
|
43
|
+
copy_table_contents(from, to,
|
44
|
+
@definition.columns.map {|column| column.name},
|
45
|
+
options[:rename] || {})
|
41
46
|
end
|
42
47
|
|
43
|
-
def copy_table_indexes(from, to,
|
48
|
+
def copy_table_indexes(from, to, rename = {}) #:nodoc:
|
44
49
|
indexes(from).each do |index|
|
45
50
|
name = index.name.downcase
|
46
51
|
if to == "altered_#{from}"
|
@@ -48,31 +53,32 @@ module JdbcSpec
|
|
48
53
|
elsif from == "altered_#{to}"
|
49
54
|
name = name[5..-1]
|
50
55
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
new_columns = index.columns
|
56
|
+
|
57
|
+
to_column_names = columns(to).map(&:name)
|
58
|
+
columns = index.columns.map {|c| rename[c] || c }.select do |column|
|
59
|
+
to_column_names.include?(column)
|
60
|
+
end
|
61
|
+
|
62
|
+
unless columns.empty?
|
63
|
+
# index name can't be the same
|
64
|
+
opts = { :name => name.gsub(/(_?)(#{from})_/, "\\1#{to}_") }
|
65
|
+
opts[:unique] = true if index.unique
|
66
|
+
add_index(to, columns, opts)
|
63
67
|
end
|
64
|
-
add_index(to, new_columns, opts)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
68
71
|
def copy_table_contents(from, to, columns, rename = {}) #:nodoc:
|
69
|
-
column_mappings = Hash[*columns.map {|
|
72
|
+
column_mappings = Hash[*columns.map {|name| [name, name]}.flatten]
|
70
73
|
rename.inject(column_mappings) {|map, a| map[a.last] = a.first; map}
|
71
74
|
from_columns = columns(from).collect {|col| col.name}
|
72
|
-
columns = columns.find_all{|col| from_columns.include?(column_mappings[col
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
columns = columns.find_all{|col| from_columns.include?(column_mappings[col])}
|
76
|
+
quoted_columns = columns.map { |col| quote_column_name(col) } * ','
|
77
|
+
|
78
|
+
quoted_to = quote_table_name(to)
|
79
|
+
execute("SELECT * FROM #{quote_table_name(from)}").each do |row|
|
80
|
+
sql = "INSERT INTO #{quoted_to} (#{quoted_columns}) VALUES ("
|
81
|
+
sql << columns.map {|col| quote row[column_mappings[col]]} * ', '
|
76
82
|
sql << ')'
|
77
83
|
execute sql
|
78
84
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
if defined?(Rake.application) && Rake.application && ENV["SKIP_AR_JDBC_RAKE_REDEFINES"].nil?
|
2
2
|
jdbc_rakefile = File.dirname(__FILE__) + "/jdbc.rake"
|
3
|
-
if Rake.application.lookup("
|
3
|
+
if Rake.application.lookup("db:create")
|
4
4
|
# rails tasks already defined; load the override tasks now
|
5
5
|
load jdbc_rakefile
|
6
6
|
else
|
data/lib/jdbc_adapter/version.rb
CHANGED
data/lib/pg.rb
ADDED
@@ -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 'jdbc.rb', File.join('config', 'initializers', 'jdbc.rb')
|
6
|
+
m.directory 'lib/tasks'
|
7
|
+
m.template '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,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 'jdbc_adapter'
|
7
|
+
require 'jdbc_adapter/rake_tasks'
|
8
|
+
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 'jdbc_adapter' if defined?(JRUBY_VERSION)
|
@@ -0,0 +1,23 @@
|
|
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
|
+
desc "Compile the native Java code."
|
16
|
+
task :java_compile do
|
17
|
+
pkg_classes = File.join(*%w(pkg classes))
|
18
|
+
jar_name = File.join(*%w(lib jdbc_adapter jdbc_adapter_internal.jar))
|
19
|
+
mkdir_p pkg_classes
|
20
|
+
sh "javac -target 1.5 -source 1.5 -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
21
|
+
sh "jar cf #{jar_name} -C #{pkg_classes} ."
|
22
|
+
end
|
23
|
+
file "lib/jdbc_adapter/jdbc_adapter_internal.jar" => :java_compile
|
@@ -0,0 +1,85 @@
|
|
1
|
+
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt",
|
2
|
+
"Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/jdbc_adapter/jdbc_adapter_internal.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/jdbc_adapter/version"
|
12
|
+
begin
|
13
|
+
require 'hoe'
|
14
|
+
hoe = Hoe.spec("activerecord-jdbc-adapter") do |p|
|
15
|
+
p.version = JdbcAdapter::Version::VERSION
|
16
|
+
p.rubyforge_name = "jruby-extras"
|
17
|
+
p.url = "http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter"
|
18
|
+
p.author = "Nick Sieger, Ola Bini and JRuby contributors"
|
19
|
+
p.email = "nick@nicksieger.com, ola.bini@gmail.com"
|
20
|
+
p.summary = "JDBC adapter for ActiveRecord, for use within JRuby on Rails."
|
21
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
22
|
+
p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
|
23
|
+
end
|
24
|
+
hoe.spec.files = MANIFEST
|
25
|
+
hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
|
26
|
+
|
27
|
+
rescue LoadError => le
|
28
|
+
puts le.to_s, *le.backtrace
|
29
|
+
puts "Problem loading Hoe; please check the error above to ensure that Hoe is installed correctly"
|
30
|
+
rescue => e
|
31
|
+
puts "ignoring error while loading Hoe: #{e.to_s}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def rake(*args)
|
35
|
+
ruby "-S", "rake", *args
|
36
|
+
end
|
37
|
+
|
38
|
+
%w(test package install_gem release clean).each do |task|
|
39
|
+
desc "Run rake #{task} on all available adapters and drivers"
|
40
|
+
task "all:#{task}" => task
|
41
|
+
end
|
42
|
+
|
43
|
+
(Dir["drivers/*/Rakefile"] + Dir["adapters/*/Rakefile"]).each do |rakefile|
|
44
|
+
dir = File.dirname(rakefile)
|
45
|
+
prefix = dir.sub(%r{/}, ':')
|
46
|
+
tasks = %w(package install_gem debug_gem clean)
|
47
|
+
tasks << "test" if File.directory?(File.join(dir, "test"))
|
48
|
+
tasks.each do |task|
|
49
|
+
desc "Run rake #{task} on #{dir}"
|
50
|
+
task "#{prefix}:#{task}" do
|
51
|
+
Dir.chdir(dir) do
|
52
|
+
rake task
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
task "#{File.dirname(dir)}:#{task}" => "#{prefix}:#{task}"
|
57
|
+
task "all:#{task}" => "#{prefix}:#{task}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# Copy all generated gems to the top-level pkg directory for convenience
|
61
|
+
task "#{prefix}:package" do
|
62
|
+
FileList["#{dir}/pkg/*.gem"].each {|gem| cp gem, "pkg"}
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "Run rake release on #{dir}"
|
66
|
+
task "#{prefix}:release" do
|
67
|
+
Dir.chdir(dir) do
|
68
|
+
version = nil
|
69
|
+
if dir =~ /adapters/
|
70
|
+
version = ENV['VERSION']
|
71
|
+
else
|
72
|
+
Dir["lib/**/*.rb"].each do |file|
|
73
|
+
version ||= File.open(file) {|f| f.read =~ /VERSION = "([^"]+)"/ && $1}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
rake "release", "VERSION=#{version}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
# Only release adapters synchronously with main release. Drivers are versioned
|
80
|
+
# according to their JDBC driver versions.
|
81
|
+
if dir =~ /adapters/
|
82
|
+
task "adapters:release" => "#{prefix}:release"
|
83
|
+
task "all:release" => "#{prefix}:release"
|
84
|
+
end
|
85
|
+
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,71 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test/helper'
|
2
|
+
if defined?(JRUBY_VERSION)
|
3
|
+
databases = [:test_mysql, :test_jdbc, :test_derby, :test_hsqldb, :test_h2, :test_sqlite3]
|
4
|
+
if find_executable?("psql") && `psql -c '\\l'` && $?.exitstatus == 0
|
5
|
+
databases << :test_postgres
|
6
|
+
end
|
7
|
+
task :test => databases
|
8
|
+
else
|
9
|
+
task :test => [:test_mysql]
|
10
|
+
end
|
11
|
+
|
12
|
+
FileList['drivers/*'].each do |d|
|
13
|
+
next unless File.directory?(d)
|
14
|
+
driver = File.basename(d)
|
15
|
+
Rake::TestTask.new("test_#{driver}") do |t|
|
16
|
+
files = FileList["test/#{driver}*test.rb"]
|
17
|
+
if driver == "derby"
|
18
|
+
files << 'test/activerecord/connection_adapters/type_conversion_test.rb'
|
19
|
+
end
|
20
|
+
t.test_files = files
|
21
|
+
t.libs = []
|
22
|
+
if defined?(JRUBY_VERSION)
|
23
|
+
t.ruby_opts << "-rjdbc/#{driver}"
|
24
|
+
t.libs << "lib" << "#{d}/lib"
|
25
|
+
t.libs.push *FileList["adapters/#{driver}*/lib"]
|
26
|
+
end
|
27
|
+
t.libs << "test"
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test_jdbc) do |t|
|
33
|
+
t.test_files = FileList['test/generic_jdbc_connection_test.rb', 'test/jndi_callbacks_test.rb']
|
34
|
+
t.libs << 'test' << 'drivers/mysql/lib'
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::TestTask.new(:test_jndi) do |t|
|
38
|
+
t.test_files = FileList['test/jndi_test.rb']
|
39
|
+
t.libs << 'test' << 'drivers/derby/lib'
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test_postgresql => [:test_postgres]
|
43
|
+
task :test_pgsql => [:test_postgres]
|
44
|
+
|
45
|
+
# Ensure driver for these DBs is on your classpath
|
46
|
+
%w(oracle db2 cachedb mssql informix).each do |d|
|
47
|
+
Rake::TestTask.new("test_#{d}") do |t|
|
48
|
+
t.test_files = FileList["test/#{d}_simple_test.rb"]
|
49
|
+
t.libs = []
|
50
|
+
t.libs << 'lib' if defined?(JRUBY_VERSION)
|
51
|
+
t.libs << 'test'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Tests for JDBC adapters that don't require a database.
|
56
|
+
Rake::TestTask.new(:test_jdbc_adapters) do | t |
|
57
|
+
t.test_files = FileList[ 'test/jdbc_adapter/jdbc_sybase_test.rb' ]
|
58
|
+
t.libs << 'test'
|
59
|
+
end
|
60
|
+
|
61
|
+
# Ensure that the jTDS driver is in your classpath before launching rake
|
62
|
+
Rake::TestTask.new(:test_sybase_jtds) do |t|
|
63
|
+
t.test_files = FileList['test/sybase_jtds_simple_test.rb']
|
64
|
+
t.libs << 'test'
|
65
|
+
end
|
66
|
+
|
67
|
+
# Ensure that the jConnect driver is in your classpath before launching rake
|
68
|
+
Rake::TestTask.new(:test_sybase_jconnect) do |t|
|
69
|
+
t.test_files = FileList['test/sybase_jconnect_simple_test.rb']
|
70
|
+
t.libs << 'test'
|
71
|
+
end
|
@@ -41,6 +41,7 @@ public class JdbcAdapterInternalService implements BasicLibraryService {
|
|
41
41
|
public boolean basicLoad(final Ruby runtime) throws IOException {
|
42
42
|
RubyClass jdbcConnection = RubyJdbcConnection.createJdbcConnectionClass(runtime);
|
43
43
|
PostgresRubyJdbcConnection.createPostgresJdbcConnectionClass(runtime, jdbcConnection);
|
44
|
+
MssqlRubyJdbcConnection.createMssqlJdbcConnectionClass(runtime, jdbcConnection);
|
44
45
|
Sqlite3RubyJdbcConnection.createSqlite3JdbcConnectionClass(runtime, jdbcConnection);
|
45
46
|
RubyModule jdbcSpec = runtime.getOrCreateModule("JdbcSpec");
|
46
47
|
|
@@ -274,55 +274,20 @@ public class JdbcDerbySpec {
|
|
274
274
|
}
|
275
275
|
}
|
276
276
|
|
277
|
-
@JRubyMethod(name = "add_limit_offset!", required = 2)
|
278
|
-
public static IRubyObject add_limit_offset(IRubyObject recv, IRubyObject sql, IRubyObject options) {
|
279
|
-
IRubyObject limit = rubyApi.callMethod(options, "[]", recv.getRuntime().newSymbol("limit"));
|
280
|
-
rubyApi.setInstanceVariable(recv, "@limit",limit);
|
281
|
-
IRubyObject offset = rubyApi.callMethod(options, "[]", recv.getRuntime().newSymbol("offset"));
|
282
|
-
return rubyApi.setInstanceVariable(recv, "@offset",offset);
|
283
|
-
}
|
284
|
-
|
285
277
|
@JRubyMethod(name = "_execute", required = 1, optional = 1)
|
286
278
|
public static IRubyObject _execute(ThreadContext context, IRubyObject recv, IRubyObject[] args) throws SQLException, java.io.IOException {
|
287
279
|
Ruby runtime = recv.getRuntime();
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
if(offset == null || offset.isNil()) {
|
300
|
-
offset = RubyFixnum.zero(runtime);
|
301
|
-
}
|
302
|
-
IRubyObject limit = rubyApi.getInstanceVariable(recv, "@limit");
|
303
|
-
IRubyObject range;
|
304
|
-
IRubyObject max;
|
305
|
-
if (limit == null || limit.isNil() || RubyNumeric.fix2int(limit) == -1) {
|
306
|
-
range = RubyRange.newRange(runtime, context, offset, runtime.newFixnum(-1), false);
|
307
|
-
max = RubyFixnum.zero(runtime);
|
308
|
-
} else {
|
309
|
-
IRubyObject v1 = rubyApi.callMethod(offset, "+", limit);
|
310
|
-
range = RubyRange.newRange(runtime, context, offset, v1, true);
|
311
|
-
max = rubyApi.callMethod(v1, "+", RubyFixnum.one(runtime));
|
312
|
-
}
|
313
|
-
IRubyObject result = conn.execute_query(context, args[0], max);
|
314
|
-
IRubyObject ret = rubyApi.callMethod(result, "[]", range);
|
315
|
-
if (ret.isNil()) {
|
316
|
-
return runtime.newArray();
|
317
|
-
} else {
|
318
|
-
return ret;
|
319
|
-
}
|
320
|
-
} else {
|
321
|
-
return conn.execute_update(context, args[0]);
|
322
|
-
}
|
323
|
-
} finally {
|
324
|
-
rubyApi.setInstanceVariable(recv, "@limit", runtime.getNil());
|
325
|
-
rubyApi.setInstanceVariable(recv, "@offset", runtime.getNil());
|
280
|
+
RubyJdbcConnection conn = (RubyJdbcConnection) rubyApi.getInstanceVariable(recv, "@connection");
|
281
|
+
String sql = args[0].toString().trim().toLowerCase();
|
282
|
+
if (sql.charAt(0) == '(') {
|
283
|
+
sql = sql.substring(1).trim();
|
284
|
+
}
|
285
|
+
if (sql.startsWith("insert")) {
|
286
|
+
return conn.execute_insert(context, args[0]);
|
287
|
+
} else if (sql.startsWith("select") || sql.startsWith("show")) {
|
288
|
+
return conn.execute_query(context, args[0]);
|
289
|
+
} else {
|
290
|
+
return conn.execute_update(context, args[0]);
|
326
291
|
}
|
327
292
|
}
|
328
293
|
}
|