saturnflyer-activerecord-jdbc-adapter 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/History.txt +225 -0
- data/LICENSE.txt +21 -0
- data/README.txt +161 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/activerecord-jdbc-adapter.gemspec +277 -0
- data/adapters/derby/LICENSE.txt +21 -0
- data/adapters/derby/README.txt +5 -0
- data/adapters/derby/Rakefile +31 -0
- data/adapters/derby/lib/active_record/connection_adapters/jdbcderby_adapter.rb +30 -0
- data/adapters/h2/History.txt +0 -0
- data/adapters/h2/LICENSE.txt +21 -0
- data/adapters/h2/README.txt +5 -0
- data/adapters/h2/Rakefile +31 -0
- data/adapters/h2/lib/active_record/connection_adapters/jdbch2_adapter.rb +30 -0
- data/adapters/hsqldb/History.txt +0 -0
- data/adapters/hsqldb/LICENSE.txt +21 -0
- data/adapters/hsqldb/README.txt +5 -0
- data/adapters/hsqldb/Rakefile +31 -0
- data/adapters/hsqldb/lib/active_record/connection_adapters/jdbchsqldb_adapter.rb +30 -0
- data/adapters/mysql/History.txt +0 -0
- data/adapters/mysql/LICENSE.txt +21 -0
- data/adapters/mysql/README.txt +5 -0
- data/adapters/mysql/Rakefile +31 -0
- data/adapters/mysql/lib/active_record/connection_adapters/jdbcmysql_adapter.rb +30 -0
- data/adapters/postgresql/History.txt +0 -0
- data/adapters/postgresql/LICENSE.txt +21 -0
- data/adapters/postgresql/README.txt +5 -0
- data/adapters/postgresql/Rakefile +31 -0
- data/adapters/postgresql/lib/active_record/connection_adapters/jdbcpostgresql_adapter.rb +30 -0
- data/adapters/sqlite3/LICENSE.txt +21 -0
- data/adapters/sqlite3/README.txt +5 -0
- data/adapters/sqlite3/Rakefile +31 -0
- data/adapters/sqlite3/lib/active_record/connection_adapters/jdbcsqlite3_adapter.rb +30 -0
- data/bench/bench_attributes.rb +13 -0
- data/bench/bench_attributes_new.rb +14 -0
- data/bench/bench_create.rb +12 -0
- data/bench/bench_find_all.rb +12 -0
- data/bench/bench_find_all_mt.rb +25 -0
- data/bench/bench_model.rb +85 -0
- data/bench/bench_new.rb +12 -0
- data/bench/bench_new_valid.rb +12 -0
- data/bench/bench_valid.rb +13 -0
- data/drivers/derby/LICENSE.txt +1 -0
- data/drivers/derby/README.txt +6 -0
- data/drivers/derby/Rakefile +26 -0
- data/drivers/derby/lib/derby-10.5.3.0.jar +0 -0
- data/drivers/derby/lib/jdbc/derby.rb +11 -0
- data/drivers/h2/History.txt +0 -0
- data/drivers/h2/LICENSE.txt +2 -0
- data/drivers/h2/README.txt +6 -0
- data/drivers/h2/Rakefile +26 -0
- data/drivers/h2/lib/h2-1.1.107.jar +0 -0
- data/drivers/h2/lib/jdbc/h2.rb +10 -0
- data/drivers/hsqldb/History.txt +0 -0
- data/drivers/hsqldb/LICENSE.txt +2 -0
- data/drivers/hsqldb/README.txt +6 -0
- data/drivers/hsqldb/Rakefile +26 -0
- data/drivers/hsqldb/lib/hsqldb-1.8.0.7.jar +0 -0
- data/drivers/hsqldb/lib/jdbc/hsqldb.rb +10 -0
- data/drivers/mysql/History.txt +0 -0
- data/drivers/mysql/LICENSE.txt +1 -0
- data/drivers/mysql/README.txt +6 -0
- data/drivers/mysql/Rakefile +26 -0
- data/drivers/mysql/lib/jdbc/mysql.rb +10 -0
- data/drivers/mysql/lib/mysql-connector-java-5.0.4-bin.jar +0 -0
- data/drivers/postgres/History.txt +7 -0
- data/drivers/postgres/LICENSE.txt +12 -0
- data/drivers/postgres/README.txt +5 -0
- data/drivers/postgres/Rakefile +27 -0
- data/drivers/postgres/lib/jdbc/postgres.rb +25 -0
- data/drivers/postgres/lib/postgresql-8.3-604.jdbc3.jar +0 -0
- data/drivers/postgres/lib/postgresql-8.3-604.jdbc4.jar +0 -0
- data/drivers/sqlite3/LICENSE.txt +13 -0
- data/drivers/sqlite3/README.txt +6 -0
- data/drivers/sqlite3/Rakefile +26 -0
- data/drivers/sqlite3/lib/jdbc/sqlite3.rb +10 -0
- data/drivers/sqlite3/lib/sqlitejdbc-3.6.3.054.jar +0 -0
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +637 -0
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +14 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +13 -0
- data/lib/jdbc_adapter.rb +27 -0
- data/lib/jdbc_adapter/jdbc.rake +104 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +33 -0
- data/lib/jdbc_adapter/jdbc_db2.rb +191 -0
- data/lib/jdbc_adapter/jdbc_derby.rb +421 -0
- data/lib/jdbc_adapter/jdbc_firebird.rb +109 -0
- data/lib/jdbc_adapter/jdbc_hsqldb.rb +210 -0
- data/lib/jdbc_adapter/jdbc_informix.rb +147 -0
- data/lib/jdbc_adapter/jdbc_mimer.rb +141 -0
- data/lib/jdbc_adapter/jdbc_mssql.rb +333 -0
- data/lib/jdbc_adapter/jdbc_mysql.rb +233 -0
- data/lib/jdbc_adapter/jdbc_oracle.rb +374 -0
- data/lib/jdbc_adapter/jdbc_postgre.rb +483 -0
- data/lib/jdbc_adapter/jdbc_sqlite3.rb +360 -0
- data/lib/jdbc_adapter/jdbc_sybase.rb +50 -0
- data/lib/jdbc_adapter/missing_functionality_helper.rb +85 -0
- data/lib/jdbc_adapter/rake_tasks.rb +10 -0
- data/lib/jdbc_adapter/tsql_helper.rb +60 -0
- data/lib/jdbc_adapter/version.rb +5 -0
- data/pom.xml +57 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/rails.rake +41 -0
- data/src/java/jdbc_adapter/JdbcAdapterInternalService.java +53 -0
- data/src/java/jdbc_adapter/JdbcConnectionFactory.java +36 -0
- data/src/java/jdbc_adapter/JdbcDerbySpec.java +293 -0
- data/src/java/jdbc_adapter/JdbcMySQLSpec.java +133 -0
- data/src/java/jdbc_adapter/MssqlRubyJdbcConnection.java +71 -0
- data/src/java/jdbc_adapter/PostgresRubyJdbcConnection.java +55 -0
- data/src/java/jdbc_adapter/RubyJdbcConnection.java +1163 -0
- data/src/java/jdbc_adapter/SQLBlock.java +27 -0
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +41 -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/activerecord/jall.sh +7 -0
- data/test/activerecord/jtest.sh +3 -0
- data/test/cachedb_simple_test.rb +6 -0
- data/test/db/cachedb.rb +9 -0
- data/test/db/db2.rb +9 -0
- data/test/db/derby.rb +14 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +12 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +11 -0
- data/test/db/jndi_config.rb +30 -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 +15 -0
- data/test/db2_simple_test.rb +10 -0
- data/test/derby_migration_test.rb +21 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_simple_test.rb +12 -0
- data/test/generic_jdbc_connection_test.rb +9 -0
- data/test/h2_simple_test.rb +6 -0
- data/test/has_many_through.rb +79 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_adapter/jdbc_db2_test.rb +26 -0
- data/test/jdbc_adapter/jdbc_sybase_test.rb +33 -0
- data/test/jdbc_common.rb +24 -0
- data/test/jndi_callbacks_test.rb +38 -0
- data/test/jndi_test.rb +35 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/minirunit.rb +109 -0
- data/test/minirunit/testConnect.rb +14 -0
- data/test/minirunit/testH2.rb +73 -0
- data/test/minirunit/testHsqldb.rb +73 -0
- data/test/minirunit/testLoadActiveRecord.rb +3 -0
- data/test/minirunit/testMysql.rb +83 -0
- data/test/minirunit/testRawSelect.rb +24 -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 +23 -0
- data/test/models/mixed_case.rb +20 -0
- data/test/models/reserved_word.rb +18 -0
- data/test/mssql_simple_test.rb +6 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +43 -0
- data/test/mysql_simple_test.rb +26 -0
- data/test/oracle_simple_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +19 -0
- data/test/postgres_nonseq_pkey_test.rb +40 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_simple_test.rb +12 -0
- data/test/simple.rb +397 -0
- data/test/sqlite3_simple_test.rb +179 -0
- data/test/sybase_jtds_simple_test.rb +6 -0
- metadata +294 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
if defined?(Rake.application) && Rake.application && ENV["SKIP_AR_JDBC_RAKE_REDEFINES"].nil?
|
2
|
+
jdbc_rakefile = File.dirname(__FILE__) + "/jdbc.rake"
|
3
|
+
if Rake.application.lookup("environment")
|
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
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Common methods for handling TSQL databases.
|
2
|
+
module TSqlMethods
|
3
|
+
|
4
|
+
def modify_types(tp) #:nodoc:
|
5
|
+
tp[:primary_key] = "int NOT NULL IDENTITY(1, 1) PRIMARY KEY"
|
6
|
+
tp[:integer][:limit] = nil
|
7
|
+
tp[:boolean] = {:name => "bit"}
|
8
|
+
tp[:binary] = { :name => "image"}
|
9
|
+
tp
|
10
|
+
end
|
11
|
+
|
12
|
+
def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
|
13
|
+
return 'uniqueidentifier' if (type.to_s == 'uniqueidentifier')
|
14
|
+
return super unless type.to_s == 'integer'
|
15
|
+
|
16
|
+
if limit.nil? || limit == 4
|
17
|
+
'int'
|
18
|
+
elsif limit == 2
|
19
|
+
'smallint'
|
20
|
+
elsif limit == 1
|
21
|
+
'tinyint'
|
22
|
+
else
|
23
|
+
'bigint'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_limit_offset!(sql, options)
|
28
|
+
if options[:limit] and options[:offset]
|
29
|
+
total_rows = select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/\bSELECT(\s+DISTINCT)?\b/i, "SELECT\\1 TOP 1000000000")}) tally")[0]["TotalRows"].to_i
|
30
|
+
if (options[:limit] + options[:offset]) >= total_rows
|
31
|
+
options[:limit] = (total_rows - options[:offset] >= 0) ? (total_rows - options[:offset]) : 0
|
32
|
+
end
|
33
|
+
sql.sub!(/^\s*SELECT(\s+DISTINCT)?/i, "SELECT * FROM (SELECT TOP #{options[:limit]} * FROM (SELECT\\1 TOP #{options[:limit] + options[:offset]} ")
|
34
|
+
sql << ") AS tmp1"
|
35
|
+
if options[:order]
|
36
|
+
options[:order] = options[:order].split(',').map do |field|
|
37
|
+
parts = field.split(" ")
|
38
|
+
tc = parts[0]
|
39
|
+
if sql =~ /\.\[/ and tc =~ /\./ # if column quoting used in query
|
40
|
+
tc.gsub!(/\./, '\\.\\[')
|
41
|
+
tc << '\\]'
|
42
|
+
end
|
43
|
+
if sql =~ /#{tc} AS (t\d_r\d\d?)/
|
44
|
+
parts[0] = $1
|
45
|
+
elsif parts[0] =~ /\w+\.(\w+)/
|
46
|
+
parts[0] = $1
|
47
|
+
end
|
48
|
+
parts.join(' ')
|
49
|
+
end.join(', ')
|
50
|
+
sql << " ORDER BY #{change_order_direction(options[:order])}) AS tmp2 ORDER BY #{options[:order]}"
|
51
|
+
else
|
52
|
+
sql << " ) AS tmp2"
|
53
|
+
end
|
54
|
+
elsif sql !~ /^\s*SELECT (@@|COUNT\()/i
|
55
|
+
sql.sub!(/^\s*SELECT(\s+DISTINCT)?/i) do
|
56
|
+
"SELECT#{$1} TOP #{options[:limit]}"
|
57
|
+
end unless options[:limit].nil?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/pom.xml
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
2
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
<groupId>org.jruby.activerecord-jdbc</groupId>
|
5
|
+
<artifactId>activerecord-jdbc</artifactId>
|
6
|
+
<packaging>jar</packaging>
|
7
|
+
<version>0.9.2</version>
|
8
|
+
<name>activerecord-jdbc</name>
|
9
|
+
<description>
|
10
|
+
This POM for activerecord-jdbc is just for bootstrapping IDEs. You
|
11
|
+
can't use it to build the project at the moment.
|
12
|
+
</description>
|
13
|
+
<url>http://activerecord-jdbc.kenai.com/</url>
|
14
|
+
|
15
|
+
<issueManagement>
|
16
|
+
<system>JIRA</system>
|
17
|
+
<url>http://kenai.com/jira/browse/ACTIVERECORD_JDBC</url>
|
18
|
+
</issueManagement>
|
19
|
+
|
20
|
+
<scm>
|
21
|
+
<connection>scm:git:git://github.com/nicksieger/activerecord-jdbc-adapter.git</connection>
|
22
|
+
<developerConnection>scm:git:git@github.com:nicksieger/activerecord-jdbc-adapter.git</developerConnection>
|
23
|
+
<url>http://github.com/nicksieger/activerecord-jdbc-adapter</url>
|
24
|
+
</scm>
|
25
|
+
|
26
|
+
<licenses>
|
27
|
+
<license>
|
28
|
+
<name>BSD</name>
|
29
|
+
<url>http://www.opensource.org/licenses/bsd-license.php</url>
|
30
|
+
<distribution>repo</distribution>
|
31
|
+
</license>
|
32
|
+
</licenses>
|
33
|
+
|
34
|
+
<dependencies>
|
35
|
+
<dependency>
|
36
|
+
<groupId>org.jruby</groupId>
|
37
|
+
<artifactId>jruby-complete</artifactId>
|
38
|
+
<version>1.1.6</version>
|
39
|
+
</dependency>
|
40
|
+
</dependencies>
|
41
|
+
|
42
|
+
<build>
|
43
|
+
<outputDirectory>pkg/classes</outputDirectory>
|
44
|
+
<sourceDirectory>src/java</sourceDirectory>
|
45
|
+
<plugins>
|
46
|
+
<plugin>
|
47
|
+
<groupId>org.apache.maven.plugins</groupId>
|
48
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
49
|
+
<configuration>
|
50
|
+
<source>1.5</source>
|
51
|
+
<target>1.5</target>
|
52
|
+
</configuration>
|
53
|
+
</plugin>
|
54
|
+
</plugins>
|
55
|
+
</build>
|
56
|
+
|
57
|
+
</project>
|
@@ -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,73 @@
|
|
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"]
|
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.new("activerecord-jdbc-adapter", JdbcAdapter::Version::VERSION) do |p|
|
15
|
+
p.rubyforge_name = "jruby-extras"
|
16
|
+
p.url = "http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter"
|
17
|
+
p.author = "Nick Sieger, Ola Bini and JRuby contributors"
|
18
|
+
p.email = "nick@nicksieger.com, ola.bini@gmail.com"
|
19
|
+
p.summary = "JDBC adapter for ActiveRecord, for use within JRuby on Rails."
|
20
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
21
|
+
p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
|
22
|
+
end.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
|
23
|
+
rescue LoadError
|
24
|
+
puts "You really need Hoe installed to be able to package this gem"
|
25
|
+
rescue => e
|
26
|
+
puts "ignoring error while loading hoe: #{e.to_s}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def rake(*args)
|
30
|
+
ruby "-S", "rake", *args
|
31
|
+
end
|
32
|
+
|
33
|
+
%w(test package install_gem release clean).each do |task|
|
34
|
+
desc "Run rake #{task} on all available adapters and drivers"
|
35
|
+
task "all:#{task}" => task
|
36
|
+
end
|
37
|
+
|
38
|
+
(Dir["drivers/*/Rakefile"] + Dir["adapters/*/Rakefile"]).each do |rakefile|
|
39
|
+
dir = File.dirname(rakefile)
|
40
|
+
prefix = dir.sub(%r{/}, ':')
|
41
|
+
tasks = %w(package install_gem debug_gem clean)
|
42
|
+
tasks << "test" if File.directory?(File.join(dir, "test"))
|
43
|
+
tasks.each do |task|
|
44
|
+
desc "Run rake #{task} on #{dir}"
|
45
|
+
task "#{prefix}:#{task}" do
|
46
|
+
Dir.chdir(dir) do
|
47
|
+
rake task
|
48
|
+
end
|
49
|
+
end
|
50
|
+
task "#{File.dirname(dir)}:#{task}" => "#{prefix}:#{task}"
|
51
|
+
task "all:#{task}" => "#{prefix}:#{task}"
|
52
|
+
end
|
53
|
+
desc "Run rake release on #{dir}"
|
54
|
+
task "#{prefix}:release" do
|
55
|
+
Dir.chdir(dir) do
|
56
|
+
version = nil
|
57
|
+
if dir =~ /adapters/
|
58
|
+
version = ENV['VERSION']
|
59
|
+
else
|
60
|
+
Dir["lib/**/*.rb"].each do |file|
|
61
|
+
version ||= File.open(file) {|f| f.read =~ /VERSION = "([^"]+)"/ && $1}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
rake "release", "VERSION=#{version}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
# Only release adapters synchronously with main release. Drivers are versioned
|
68
|
+
# according to their JDBC driver versions.
|
69
|
+
if dir =~ /adapters/
|
70
|
+
task "adapters:release" => "#{prefix}:release"
|
71
|
+
task "all:release" => "#{prefix}:release"
|
72
|
+
end
|
73
|
+
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
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
**** BEGIN LICENSE BLOCK *****
|
3
|
+
* Copyright (c) 2006-2009 Nick Sieger <nick@nicksieger.com>
|
4
|
+
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
5
|
+
* Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
* a copy of this software and associated documentation files (the
|
9
|
+
* "Software"), to deal in the Software without restriction, including
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
* the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be
|
16
|
+
* included in all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
***** END LICENSE BLOCK *****/
|
26
|
+
|
27
|
+
package jdbc_adapter;
|
28
|
+
|
29
|
+
import java.io.IOException;
|
30
|
+
|
31
|
+
import org.jruby.Ruby;
|
32
|
+
import org.jruby.RubyClass;
|
33
|
+
import org.jruby.RubyModule;
|
34
|
+
import org.jruby.RubyObjectAdapter;
|
35
|
+
import org.jruby.javasupport.JavaEmbedUtils;
|
36
|
+
import org.jruby.runtime.load.BasicLibraryService;
|
37
|
+
|
38
|
+
public class JdbcAdapterInternalService implements BasicLibraryService {
|
39
|
+
private static RubyObjectAdapter rubyApi;
|
40
|
+
|
41
|
+
public boolean basicLoad(final Ruby runtime) throws IOException {
|
42
|
+
RubyClass jdbcConnection = RubyJdbcConnection.createJdbcConnectionClass(runtime);
|
43
|
+
PostgresRubyJdbcConnection.createPostgresJdbcConnectionClass(runtime, jdbcConnection);
|
44
|
+
MssqlRubyJdbcConnection.createMssqlJdbcConnectionClass(runtime, jdbcConnection);
|
45
|
+
Sqlite3RubyJdbcConnection.createSqlite3JdbcConnectionClass(runtime, jdbcConnection);
|
46
|
+
RubyModule jdbcSpec = runtime.getOrCreateModule("JdbcSpec");
|
47
|
+
|
48
|
+
rubyApi = JavaEmbedUtils.newObjectAdapter();
|
49
|
+
JdbcMySQLSpec.load(jdbcSpec);
|
50
|
+
JdbcDerbySpec.load(jdbcSpec, rubyApi);
|
51
|
+
return true;
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Copyright (c) 2006-2007 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 jdbc_adapter;
|
26
|
+
|
27
|
+
import java.sql.Connection;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Interface to be implemented in Ruby for retrieving a new connection
|
31
|
+
*
|
32
|
+
* @author nicksieger
|
33
|
+
*/
|
34
|
+
public interface JdbcConnectionFactory {
|
35
|
+
Connection newConnection();
|
36
|
+
}
|
@@ -0,0 +1,293 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Copyright (c) 2006-2007 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 jdbc_adapter;
|
26
|
+
|
27
|
+
import org.jruby.Ruby;
|
28
|
+
import org.jruby.RubyModule;
|
29
|
+
import org.jruby.RubyString;
|
30
|
+
import org.jruby.RubyFloat;
|
31
|
+
import org.jruby.RubyFixnum;
|
32
|
+
import org.jruby.RubyBignum;
|
33
|
+
import org.jruby.RubyBoolean;
|
34
|
+
import org.jruby.RubyBigDecimal;
|
35
|
+
import org.jruby.RubyRange;
|
36
|
+
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
|
+
import org.jruby.RubyObjectAdapter;
|
44
|
+
import org.jruby.anno.JRubyMethod;
|
45
|
+
import org.jruby.runtime.ThreadContext;
|
46
|
+
|
47
|
+
public class JdbcDerbySpec {
|
48
|
+
private static RubyObjectAdapter rubyApi;
|
49
|
+
public static void load(RubyModule jdbcSpec, RubyObjectAdapter adapter) {
|
50
|
+
RubyModule derby = jdbcSpec.defineModuleUnder("Derby");
|
51
|
+
derby.defineAnnotatedMethods(JdbcDerbySpec.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
|
+
if (value instanceof RubyString) {
|
115
|
+
if (type.equals("string")) {
|
116
|
+
return quote_string_with_surround(runtime, "'", (RubyString)value, "'");
|
117
|
+
} else if (type.equals("text")) {
|
118
|
+
return quote_string_with_surround(runtime, "CAST('", (RubyString)value, "' AS CLOB)");
|
119
|
+
} else if (type.equals("binary")) {
|
120
|
+
return hexquote_string_with_surround(runtime, "CAST(X'", (RubyString)value, "' AS BLOB)");
|
121
|
+
} else {
|
122
|
+
// column type :integer or other numeric or date version
|
123
|
+
if (only_digits((RubyString)value)) {
|
124
|
+
return value;
|
125
|
+
} else {
|
126
|
+
return super_quote(context, recv, runtime, value, col);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
} else if ((value instanceof RubyFloat) || (value instanceof RubyFixnum) || (value instanceof RubyBignum)) {
|
130
|
+
if (type.equals("string")) {
|
131
|
+
return quote_string_with_surround(runtime, "'", RubyString.objAsString(context, value), "'");
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return super_quote(context, recv, runtime, value, runtime.getNil());
|
136
|
+
}
|
137
|
+
|
138
|
+
private final static ByteList NULL = new ByteList("NULL".getBytes());
|
139
|
+
|
140
|
+
private static IRubyObject super_quote(ThreadContext context, IRubyObject recv, Ruby runtime, IRubyObject value, IRubyObject col) {
|
141
|
+
if (value.respondsTo("quoted_id")) {
|
142
|
+
return rubyApi.callMethod(value, "quoted_id");
|
143
|
+
}
|
144
|
+
|
145
|
+
IRubyObject type = (col.isNil()) ? col : rubyApi.callMethod(col, "type");
|
146
|
+
RubyModule multibyteChars = (RubyModule)
|
147
|
+
((RubyModule) ((RubyModule) runtime.getModule("ActiveSupport")).getConstant("Multibyte")).getConstantAt("Chars");
|
148
|
+
if (value instanceof RubyString || rubyApi.isKindOf(value, multibyteChars)) {
|
149
|
+
RubyString svalue = RubyString.objAsString(context, value);
|
150
|
+
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)), "'");
|
152
|
+
} else if (type == runtime.newSymbol("integer") || type == runtime.newSymbol("float")) {
|
153
|
+
return RubyString.objAsString(context, ((type == runtime.newSymbol("integer")) ?
|
154
|
+
rubyApi.callMethod(svalue, "to_i") :
|
155
|
+
rubyApi.callMethod(svalue, "to_f")));
|
156
|
+
} else {
|
157
|
+
return quote_string_with_surround(runtime, "'", svalue, "'");
|
158
|
+
}
|
159
|
+
} else if (value.isNil()) {
|
160
|
+
return runtime.newString(NULL);
|
161
|
+
} else if (value instanceof RubyBoolean) {
|
162
|
+
return (value.isTrue() ?
|
163
|
+
(type == runtime.newSymbol(":integer")) ? runtime.newString("1") : rubyApi.callMethod(recv, "quoted_true") :
|
164
|
+
(type == runtime.newSymbol(":integer")) ? runtime.newString("0") : rubyApi.callMethod(recv, "quoted_false"));
|
165
|
+
} else if((value instanceof RubyFloat) || (value instanceof RubyFixnum) || (value instanceof RubyBignum)) {
|
166
|
+
return RubyString.objAsString(context, value);
|
167
|
+
} else if(value instanceof RubyBigDecimal) {
|
168
|
+
return rubyApi.callMethod(value, "to_s", runtime.newString("F"));
|
169
|
+
} 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)), "'");
|
171
|
+
} else {
|
172
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(value, "to_yaml")), "'");
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
private final static ByteList TWO_SINGLE = new ByteList(new byte[]{'\'','\''});
|
177
|
+
|
178
|
+
private static IRubyObject quote_string_with_surround(Ruby runtime, String before, RubyString string, String after) {
|
179
|
+
ByteList input = string.getByteList();
|
180
|
+
ByteList output = new ByteList(before.getBytes());
|
181
|
+
for(int i = input.begin; i< input.begin + input.realSize; i++) {
|
182
|
+
switch(input.bytes[i]) {
|
183
|
+
case '\'':
|
184
|
+
output.append(input.bytes[i]);
|
185
|
+
//FALLTHROUGH
|
186
|
+
default:
|
187
|
+
output.append(input.bytes[i]);
|
188
|
+
}
|
189
|
+
|
190
|
+
}
|
191
|
+
|
192
|
+
output.append(after.getBytes());
|
193
|
+
|
194
|
+
return runtime.newString(output);
|
195
|
+
}
|
196
|
+
|
197
|
+
private final static byte[] HEX = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
198
|
+
|
199
|
+
private static IRubyObject hexquote_string_with_surround(Ruby runtime, String before, RubyString string, String after) {
|
200
|
+
ByteList input = string.getByteList();
|
201
|
+
ByteList output = new ByteList(before.getBytes());
|
202
|
+
int written = 0;
|
203
|
+
for(int i = input.begin; i< input.begin + input.realSize; i++) {
|
204
|
+
byte b1 = input.bytes[i];
|
205
|
+
byte higher = HEX[(((char)b1)>>4)%16];
|
206
|
+
byte lower = HEX[((char)b1)%16];
|
207
|
+
output.append(higher);
|
208
|
+
output.append(lower);
|
209
|
+
written += 2;
|
210
|
+
if(written >= 16334) { // max hex length = 16334
|
211
|
+
output.append("'||X'".getBytes());
|
212
|
+
written = 0;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
output.append(after.getBytes());
|
217
|
+
return runtime.newStringShared(output);
|
218
|
+
}
|
219
|
+
|
220
|
+
private static boolean only_digits(RubyString inp) {
|
221
|
+
ByteList input = inp.getByteList();
|
222
|
+
for(int i = input.begin; i< input.begin + input.realSize; i++) {
|
223
|
+
if(input.bytes[i] < '0' || input.bytes[i] > '9') {
|
224
|
+
return false;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
return true;
|
228
|
+
}
|
229
|
+
|
230
|
+
@JRubyMethod(name = "quote_string", required = 1)
|
231
|
+
public static IRubyObject quote_string(IRubyObject recv, IRubyObject string) {
|
232
|
+
boolean replacementFound = false;
|
233
|
+
ByteList bl = ((RubyString) string).getByteList();
|
234
|
+
|
235
|
+
for(int i = bl.begin; i < bl.begin + bl.realSize; i++) {
|
236
|
+
switch (bl.bytes[i]) {
|
237
|
+
case '\'': break;
|
238
|
+
default: continue;
|
239
|
+
}
|
240
|
+
|
241
|
+
// On first replacement allocate a different bytelist so we don't manip original
|
242
|
+
if(!replacementFound) {
|
243
|
+
i-= bl.begin;
|
244
|
+
bl = new ByteList(bl);
|
245
|
+
replacementFound = true;
|
246
|
+
}
|
247
|
+
|
248
|
+
bl.replace(i, 1, TWO_SINGLE);
|
249
|
+
i+=1;
|
250
|
+
}
|
251
|
+
if(replacementFound) {
|
252
|
+
return recv.getRuntime().newStringShared(bl);
|
253
|
+
} else {
|
254
|
+
return string;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
@JRubyMethod(name = "select_all", rest = true)
|
259
|
+
public static IRubyObject select_all(IRubyObject recv, IRubyObject[] args) {
|
260
|
+
return rubyApi.callMethod(recv, "execute", args);
|
261
|
+
}
|
262
|
+
|
263
|
+
@JRubyMethod(name = "select_one", rest = true)
|
264
|
+
public static IRubyObject select_one(IRubyObject recv, IRubyObject[] args) {
|
265
|
+
IRubyObject limit = rubyApi.getInstanceVariable(recv, "@limit");
|
266
|
+
if (limit == null || limit.isNil()) {
|
267
|
+
rubyApi.setInstanceVariable(recv, "@limit", recv.getRuntime().newFixnum(1));
|
268
|
+
}
|
269
|
+
try {
|
270
|
+
IRubyObject result = rubyApi.callMethod(recv, "execute", args);
|
271
|
+
return rubyApi.callMethod(result, "first");
|
272
|
+
} finally {
|
273
|
+
rubyApi.setInstanceVariable(recv, "@limit", recv.getRuntime().getNil());
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
@JRubyMethod(name = "_execute", required = 1, optional = 1)
|
278
|
+
public static IRubyObject _execute(ThreadContext context, IRubyObject recv, IRubyObject[] args) throws SQLException, java.io.IOException {
|
279
|
+
Ruby runtime = recv.getRuntime();
|
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]);
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|