activerecord-jdbc-adapter 0.9.7-java → 1.0.0.beta1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +71 -38
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -661
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
- data/lib/activerecord-jdbc-adapter.rb +2 -2
- data/lib/arjdbc.rb +29 -0
- data/lib/arjdbc/cachedb.rb +3 -0
- data/lib/arjdbc/cachedb/adapter.rb +20 -0
- data/lib/arjdbc/cachedb/connection_methods.rb +10 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_db2.rb → arjdbc/db2/adapter.rb} +1 -17
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +8 -26
- data/lib/arjdbc/derby/connection_methods.rb +18 -0
- data/lib/arjdbc/discover.rb +99 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +12 -16
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +15 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +6 -58
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +6 -19
- data/lib/arjdbc/informix/connection_methods.rb +10 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +235 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +38 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +97 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +0 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/railtie.rb +1 -1
- data/lib/{jdbc_adapter → arjdbc/jdbc}/rake_tasks.rb +0 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +119 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +16 -19
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_mssql.rb → arjdbc/mssql/adapter.rb} +19 -31
- data/lib/arjdbc/mssql/connection_methods.rb +13 -0
- data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +1 -1
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +388 -0
- data/lib/arjdbc/mysql/connection_methods.rb +26 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +9 -17
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +7 -36
- data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_sqlite3.rb → arjdbc/sqlite3/adapter.rb} +106 -104
- data/lib/arjdbc/sqlite3/connection_methods.rb +33 -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/jdbc_adapter.rb +2 -27
- data/lib/jdbc_adapter/version.rb +3 -5
- data/rails_generators/templates/config/initializers/jdbc.rb +1 -1
- data/rakelib/compile.rake +3 -2
- data/rakelib/package.rake +3 -3
- data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +32 -32
- data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +13 -7
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +91 -16
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/{jdbc_adapter → arjdbc/mssql}/MssqlRubyJdbcConnection.java +5 -2
- data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
- data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/test/abstract_db_create.rb +4 -1
- data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
- data/test/db/cachedb.rb +0 -0
- data/test/db/derby.rb +12 -14
- data/test/db/hsqldb.rb +3 -2
- data/test/db/jndi_config.rb +4 -4
- data/test/db/sqlite3.rb +2 -6
- data/test/db2_simple_test.rb +23 -0
- data/test/derby_migration_test.rb +50 -3
- data/test/jdbc_common.rb +1 -1
- data/test/jndi_callbacks_test.rb +1 -0
- data/test/postgres_nonseq_pkey_test.rb +0 -2
- data/test/postgres_schema_search_path_test.rb +0 -2
- data/test/simple.rb +3 -3
- data/test/sybase_jtds_simple_test.rb +22 -0
- metadata +82 -46
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
- data/lib/jdbc_adapter/jdbc_mysql.rb +0 -260
- data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
- data/src/java/jdbc_adapter/SQLBlock.java +0 -27
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
- data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
- data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
- data/test/minirunit.rb +0 -109
- data/test/minirunit/testConnect.rb +0 -14
- data/test/minirunit/testH2.rb +0 -73
- data/test/minirunit/testHsqldb.rb +0 -73
- data/test/minirunit/testLoadActiveRecord.rb +0 -3
- data/test/minirunit/testMysql.rb +0 -83
- data/test/minirunit/testRawSelect.rb +0 -24
@@ -0,0 +1,26 @@
|
|
1
|
+
# Don't need to load native mysql adapter
|
2
|
+
$LOADED_FEATURES << "active_record/connection_adapters/mysql_adapter.rb"
|
3
|
+
|
4
|
+
class ActiveRecord::Base
|
5
|
+
class << self
|
6
|
+
def mysql_connection(config)
|
7
|
+
require "arjdbc/mysql"
|
8
|
+
config[:port] ||= 3306
|
9
|
+
url_options = "zeroDateTimeBehavior=convertToNull&jdbcCompliantTruncation=false&useUnicode=true&characterEncoding="
|
10
|
+
url_options << (config[:encoding] || 'utf8')
|
11
|
+
if config[:url]
|
12
|
+
config[:url] = config[:url]['?'] ? "#{config[:url]}&#{url_options}" : "#{config[:url]}?#{url_options}"
|
13
|
+
else
|
14
|
+
config[:url] = "jdbc:mysql://#{config[:host]}:#{config[:port]}/#{config[:database]}?#{url_options}"
|
15
|
+
end
|
16
|
+
config[:driver] ||= "com.mysql.jdbc.Driver"
|
17
|
+
config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter
|
18
|
+
connection = jdbc_connection(config)
|
19
|
+
::ArJdbc::MySQL.kill_cancel_timer(connection.raw_connection)
|
20
|
+
connection
|
21
|
+
end
|
22
|
+
alias_method :jdbcmysql_connection, :mysql_connection
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
@@ -1,13 +1,8 @@
|
|
1
|
-
module ::
|
2
|
-
|
3
|
-
|
4
|
-
config[:port] ||= 1521
|
5
|
-
config[:url] ||= "jdbc:oracle:thin:@#{config[:host]}:#{config[:port]}:#{config[:database]}"
|
6
|
-
config[:driver] ||= "oracle.jdbc.driver.OracleDriver"
|
7
|
-
jdbc_connection(config)
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module ActiveRecord::ConnectionAdapters
|
2
|
+
OracleAdapter = Class.new(AbstractAdapter) unless const_defined?(:OracleAdapter)
|
3
|
+
end
|
10
4
|
|
5
|
+
module ::ArJdbc
|
11
6
|
module Oracle
|
12
7
|
def self.extended(mod)
|
13
8
|
unless @lob_callback_added
|
@@ -26,19 +21,16 @@ module ::JdbcSpec
|
|
26
21
|
ActiveRecord::Base.after_save :after_save_with_oracle_lob
|
27
22
|
@lob_callback_added = true
|
28
23
|
end
|
29
|
-
|
24
|
+
require 'arjdbc/jdbc/quoted_primary_key'
|
25
|
+
ActiveRecord::Base.extend ArJdbc::QuotedPrimaryKeyExtension
|
30
26
|
mod.class.class_eval do
|
31
27
|
alias_chained_method :insert, :query_dirty, :insert
|
32
28
|
alias_chained_method :columns, :query_cache, :columns
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
36
|
-
def self.adapter_matcher(name, *)
|
37
|
-
name =~ /oracle/i ? self : false
|
38
|
-
end
|
39
|
-
|
40
32
|
def self.column_selector
|
41
|
-
[/oracle/i, lambda {|cfg,col| col.extend(::
|
33
|
+
[/oracle/i, lambda {|cfg,col| col.extend(::ArJdbc::Oracle::Column)}]
|
42
34
|
end
|
43
35
|
|
44
36
|
module Column
|
@@ -52,7 +44,7 @@ module ::JdbcSpec
|
|
52
44
|
def type_cast(value)
|
53
45
|
return nil if value.nil?
|
54
46
|
case type
|
55
|
-
when :datetime then
|
47
|
+
when :datetime then ArJdbc::Oracle::Column.string_to_time(value, self.class)
|
56
48
|
else
|
57
49
|
super
|
58
50
|
end
|
@@ -60,7 +52,7 @@ module ::JdbcSpec
|
|
60
52
|
|
61
53
|
def type_cast_code(var_name)
|
62
54
|
case type
|
63
|
-
when :datetime then "
|
55
|
+
when :datetime then "ArJdbc::Oracle::Column.string_to_time(#{var_name}, self.class)"
|
64
56
|
else
|
65
57
|
super
|
66
58
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
class << self
|
3
|
+
def oracle_connection(config)
|
4
|
+
config[:port] ||= 1521
|
5
|
+
config[:url] ||= "jdbc:oracle:thin:@#{config[:host]}:#{config[:port]}:#{config[:database]}"
|
6
|
+
config[:driver] ||= "oracle.jdbc.driver.OracleDriver"
|
7
|
+
jdbc_connection(config)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -1,24 +1,8 @@
|
|
1
|
+
module ActiveRecord::ConnectionAdapters
|
2
|
+
PostgreSQLAdapter = Class.new(AbstractAdapter) unless const_defined?(:PostgreSQLAdapter)
|
3
|
+
end
|
1
4
|
|
2
|
-
module ::
|
3
|
-
# Don't need to load native postgres adapter
|
4
|
-
$LOADED_FEATURES << "active_record/connection_adapters/postgresql_adapter.rb"
|
5
|
-
|
6
|
-
module ActiveRecordExtensions
|
7
|
-
add_method_to_remove_from_ar_base(:postgresql_connection)
|
8
|
-
|
9
|
-
def postgresql_connection(config)
|
10
|
-
require File.dirname(__FILE__) + "/../active_record/connection_adapters/postgresql_adapter"
|
11
|
-
config[:host] ||= "localhost"
|
12
|
-
config[:port] ||= 5432
|
13
|
-
config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
|
14
|
-
config[:url] << config[:pg_params] if config[:pg_params]
|
15
|
-
config[:driver] ||= "org.postgresql.Driver"
|
16
|
-
conn = jdbc_connection(config)
|
17
|
-
conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path]
|
18
|
-
conn
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
5
|
+
module ::ArJdbc
|
22
6
|
module PostgreSQL
|
23
7
|
def self.extended(mod)
|
24
8
|
mod.class.class_eval do
|
@@ -26,12 +10,8 @@ module ::JdbcSpec
|
|
26
10
|
end
|
27
11
|
end
|
28
12
|
|
29
|
-
def self.adapter_matcher(name, *)
|
30
|
-
name =~ /postgre/i ? self : false
|
31
|
-
end
|
32
|
-
|
33
13
|
def self.column_selector
|
34
|
-
[/postgre/i, lambda {|cfg,col| col.extend(::
|
14
|
+
[/postgre/i, lambda {|cfg,col| col.extend(::ArJdbc::PostgreSQL::Column)}]
|
35
15
|
end
|
36
16
|
|
37
17
|
def self.jdbc_connection_class
|
@@ -188,9 +168,9 @@ module ::JdbcSpec
|
|
188
168
|
end
|
189
169
|
|
190
170
|
def quote_regclass(table_name)
|
191
|
-
table_name.to_s.split('.').map do |part|
|
171
|
+
table_name.to_s.split('.').map do |part|
|
192
172
|
part =~ /".*"/i ? part : quote_table_name(part)
|
193
|
-
end.join('.')
|
173
|
+
end.join('.')
|
194
174
|
end
|
195
175
|
|
196
176
|
# Find a table's primary key and sequence.
|
@@ -381,15 +361,6 @@ module ::JdbcSpec
|
|
381
361
|
end
|
382
362
|
end
|
383
363
|
|
384
|
-
def _execute(sql, name = nil)
|
385
|
-
case sql.strip
|
386
|
-
when /\A\(?\s*(select|show)/i then
|
387
|
-
@connection.execute_query(sql)
|
388
|
-
else
|
389
|
-
@connection.execute_update(sql)
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
364
|
# SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
|
394
365
|
#
|
395
366
|
# PostgreSQL requires the ORDER BY columns in the select list for distinct queries, and
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Don't need to load native postgres adapter
|
2
|
+
$LOADED_FEATURES << "active_record/connection_adapters/postgresql_adapter.rb"
|
3
|
+
|
4
|
+
class ActiveRecord::Base
|
5
|
+
class << self
|
6
|
+
def postgresql_connection(config)
|
7
|
+
require "arjdbc/postgresql"
|
8
|
+
config[:host] ||= "localhost"
|
9
|
+
config[:port] ||= 5432
|
10
|
+
config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
|
11
|
+
config[:url] << config[:pg_params] if config[:pg_params]
|
12
|
+
config[:driver] ||= "org.postgresql.Driver"
|
13
|
+
conn = jdbc_connection(config)
|
14
|
+
conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path]
|
15
|
+
conn
|
16
|
+
end
|
17
|
+
alias_method :jdbcpostgresql_connection, :postgresql_connection
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -1,47 +1,13 @@
|
|
1
|
-
|
2
|
-
# Don't need to load native postgres adapter
|
3
|
-
$LOADED_FEATURES << "active_record/connection_adapters/sqlite3_adapter.rb"
|
1
|
+
require 'arjdbc/jdbc/missing_functionality_helper'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def sqlite3_connection(config)
|
9
|
-
require File.dirname(__FILE__) + "/../active_record/connection_adapters/sqlite3_adapter"
|
10
|
-
|
11
|
-
parse_sqlite3_config!(config)
|
12
|
-
|
13
|
-
config[:url] ||= "jdbc:sqlite:#{config[:database]}"
|
14
|
-
config[:driver] ||= "org.sqlite.JDBC"
|
15
|
-
jdbc_connection(config)
|
16
|
-
end
|
17
|
-
|
18
|
-
def parse_sqlite3_config!(config)
|
19
|
-
config[:database] ||= config[:dbfile]
|
20
|
-
|
21
|
-
# Allow database path relative to RAILS_ROOT, but only if
|
22
|
-
# the database path is not the special path that tells
|
23
|
-
# Sqlite to build a database only in memory.
|
24
|
-
rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
|
25
|
-
if rails_root_defined && ':memory:' != config[:database]
|
26
|
-
rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
|
27
|
-
config[:database] = File.expand_path(config[:database], rails_root)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
3
|
+
module ActiveRecord::ConnectionAdapters
|
4
|
+
Sqlite3Adapter = Class.new(AbstractAdapter) unless const_defined?(:Sqlite3Adapter)
|
5
|
+
end
|
31
6
|
|
7
|
+
module ::ArJdbc
|
32
8
|
module SQLite3
|
33
|
-
def self.extended(base)
|
34
|
-
base.class.class_eval do
|
35
|
-
alias_chained_method :insert, :query_dirty, :insert
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.adapter_matcher(name, *)
|
40
|
-
name =~ /sqlite/i ? self : false
|
41
|
-
end
|
42
|
-
|
43
9
|
def self.column_selector
|
44
|
-
[/sqlite/i, lambda {|cfg,col| col.extend(::
|
10
|
+
[/sqlite/i, lambda {|cfg,col| col.extend(::ArJdbc::SQLite3::Column)}]
|
45
11
|
end
|
46
12
|
|
47
13
|
def self.jdbc_connection_class
|
@@ -57,12 +23,12 @@ module ::JdbcSpec
|
|
57
23
|
return nil if value.nil?
|
58
24
|
case type
|
59
25
|
when :string then value
|
60
|
-
when :integer then
|
26
|
+
when :integer then ArJdbc::SQLite3::Column.cast_to_integer(value)
|
61
27
|
when :primary_key then defined?(value.to_i) ? value.to_i : (value ? 1 : 0)
|
62
28
|
when :float then value.to_f
|
63
|
-
when :datetime then
|
64
|
-
when :date then
|
65
|
-
when :time then
|
29
|
+
when :datetime then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
|
30
|
+
when :date then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
|
31
|
+
when :time then ArJdbc::SQLite3::Column.cast_to_time(value)
|
66
32
|
when :decimal then self.class.value_to_decimal(value)
|
67
33
|
when :boolean then self.class.value_to_boolean(value)
|
68
34
|
else value
|
@@ -71,10 +37,10 @@ module ::JdbcSpec
|
|
71
37
|
|
72
38
|
def type_cast_code(var_name)
|
73
39
|
case type
|
74
|
-
when :integer then "
|
75
|
-
when :datetime then "
|
76
|
-
when :date then "
|
77
|
-
when :time then "
|
40
|
+
when :integer then "ArJdbc::SQLite3::Column.cast_to_integer(#{var_name})"
|
41
|
+
when :datetime then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
|
42
|
+
when :date then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
|
43
|
+
when :time then "ArJdbc::SQLite3::Column.cast_to_time(#{var_name})"
|
78
44
|
else
|
79
45
|
super
|
80
46
|
end
|
@@ -98,11 +64,11 @@ module ::JdbcSpec
|
|
98
64
|
|
99
65
|
def extract_precision(sql_type)
|
100
66
|
case sql_type
|
101
|
-
when /^(real)\((\d+)(,\d+)?\)/i then $2.to_i
|
67
|
+
when /^(real)\((\d+)(,\d+)?\)/i then $2.to_i
|
102
68
|
else super
|
103
|
-
end
|
69
|
+
end
|
104
70
|
end
|
105
|
-
|
71
|
+
|
106
72
|
def extract_scale(sql_type)
|
107
73
|
case sql_type
|
108
74
|
when /^(real)\((\d+)\)/i then 0
|
@@ -190,14 +156,7 @@ module ::JdbcSpec
|
|
190
156
|
end
|
191
157
|
|
192
158
|
def quote_column_name(name) #:nodoc:
|
193
|
-
name
|
194
|
-
# Did not find reference on values needing quoting, but these
|
195
|
-
# happen in AR unit tests
|
196
|
-
if name == "references" || name =~ /-/
|
197
|
-
%Q("#{name}")
|
198
|
-
else
|
199
|
-
name
|
200
|
-
end
|
159
|
+
%Q("#{name}")
|
201
160
|
end
|
202
161
|
|
203
162
|
def quote_string(str)
|
@@ -262,23 +221,13 @@ module ::JdbcSpec
|
|
262
221
|
execute "ALTER TABLE #{name} RENAME TO #{new_name}"
|
263
222
|
end
|
264
223
|
|
265
|
-
def
|
266
|
-
|
267
|
-
|
268
|
-
end
|
269
|
-
table = sql.split(" ", 4)[2]
|
270
|
-
id_value || last_insert_id(table, nil)
|
271
|
-
end
|
272
|
-
|
273
|
-
def last_insert_id(table, sequence_name)
|
274
|
-
Integer(select_value("SELECT SEQ FROM SQLITE_SEQUENCE WHERE NAME = '#{table}'"))
|
224
|
+
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
|
225
|
+
@connection.execute_update(sql)
|
226
|
+
id_value || last_insert_id
|
275
227
|
end
|
276
228
|
|
277
|
-
def
|
278
|
-
|
279
|
-
sql << " LIMIT #{options[:limit]}"
|
280
|
-
sql << " OFFSET #{options[:offset]}" if options[:offset]
|
281
|
-
end
|
229
|
+
def last_insert_id
|
230
|
+
Integer(select_value("SELECT last_insert_rowid()"))
|
282
231
|
end
|
283
232
|
|
284
233
|
def tables(name = nil) #:nodoc:
|
@@ -304,11 +253,13 @@ module ::JdbcSpec
|
|
304
253
|
name = row[0]
|
305
254
|
index_sql = row[1]
|
306
255
|
unique = (index_sql =~ /unique/i)
|
307
|
-
cols = index_sql.match(/\((.*)\)/)[1].gsub(/,/,' ').split
|
256
|
+
cols = index_sql.match(/\((.*)\)/)[1].gsub(/,/,' ').split.map do |c|
|
257
|
+
match = /^"(.+)"$/.match(c); match ? match[1] : c
|
258
|
+
end
|
308
259
|
::ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, name, unique, cols)
|
309
260
|
end
|
310
261
|
end
|
311
|
-
|
262
|
+
|
312
263
|
def primary_key(table_name) #:nodoc:
|
313
264
|
column = table_structure(table_name).find {|field| field['pk'].to_i == 1}
|
314
265
|
column ? column['name'] : nil
|
@@ -319,14 +270,10 @@ module ::JdbcSpec
|
|
319
270
|
end
|
320
271
|
|
321
272
|
def _execute(sql, name = nil)
|
322
|
-
|
323
|
-
|
324
|
-
else
|
325
|
-
affected_rows = @connection.execute_update(sql)
|
326
|
-
ActiveRecord::ConnectionAdapters::JdbcConnection::insert?(sql) ? last_insert_id(sql.split(" ", 4)[2], nil) : affected_rows
|
327
|
-
end
|
273
|
+
result = super
|
274
|
+
ActiveRecord::ConnectionAdapters::JdbcConnection::insert?(sql) ? last_insert_id : result
|
328
275
|
end
|
329
|
-
|
276
|
+
|
330
277
|
def select(sql, name=nil)
|
331
278
|
execute(sql, name).map do |row|
|
332
279
|
record = {}
|
@@ -338,49 +285,104 @@ module ::JdbcSpec
|
|
338
285
|
record
|
339
286
|
end
|
340
287
|
end
|
341
|
-
|
288
|
+
|
342
289
|
def table_structure(table_name)
|
343
290
|
structure = @connection.execute_query("PRAGMA table_info(#{quote_table_name(table_name)})")
|
344
291
|
raise ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'" if structure.empty?
|
345
292
|
structure
|
346
293
|
end
|
347
|
-
|
348
|
-
def columns(table_name, name = nil) #:nodoc:
|
294
|
+
|
295
|
+
def columns(table_name, name = nil) #:nodoc:
|
349
296
|
table_structure(table_name).map do |field|
|
350
297
|
::ActiveRecord::ConnectionAdapters::JdbcColumn.new(@config, field['name'], field['dflt_value'], field['type'], field['notnull'] == 0)
|
351
298
|
end
|
352
299
|
end
|
353
|
-
|
300
|
+
|
354
301
|
# SELECT ... FOR UPDATE is redundant since the table is locked.
|
355
302
|
def add_lock!(sql, options) #:nodoc:
|
356
303
|
sql
|
357
304
|
end
|
358
|
-
|
305
|
+
|
359
306
|
protected
|
360
|
-
|
307
|
+
include ArJdbc::MissingFunctionalityHelper
|
308
|
+
|
309
|
+
def translate_exception(exception, message)
|
310
|
+
case exception.message
|
311
|
+
when /column(s)? .* (is|are) not unique/
|
312
|
+
ActiveRecord::RecordNotUnique.new(message, exception)
|
313
|
+
else
|
314
|
+
super
|
315
|
+
end
|
316
|
+
end
|
361
317
|
end
|
362
318
|
end
|
363
319
|
|
364
|
-
module ActiveRecord
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
320
|
+
module ActiveRecord::ConnectionAdapters
|
321
|
+
class SQLiteColumn < JdbcColumn
|
322
|
+
include ArJdbc::SQLite3::Column
|
323
|
+
|
324
|
+
def initialize(name, *args)
|
325
|
+
if Hash === name
|
326
|
+
super
|
327
|
+
else
|
328
|
+
super(nil, name, *args)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
def call_discovered_column_callbacks(*)
|
333
|
+
end
|
334
|
+
|
335
|
+
def self.string_to_binary(value)
|
336
|
+
value.gsub(/\0|%/n) do |b|
|
337
|
+
case b
|
338
|
+
when "\0" then "%00"
|
339
|
+
when "\%" then "%25"
|
373
340
|
end
|
374
341
|
end
|
342
|
+
end
|
375
343
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
end
|
344
|
+
def self.binary_to_string(value)
|
345
|
+
value.gsub(/%00|%25/n) do |b|
|
346
|
+
case b
|
347
|
+
when "%00" then "\0"
|
348
|
+
when "%25" then "%"
|
382
349
|
end
|
383
350
|
end
|
384
351
|
end
|
352
|
+
|
353
|
+
def self.cast_to_integer(value)
|
354
|
+
return nil if value =~ /NULL/ or value.to_s.empty? or value.nil?
|
355
|
+
return (value.to_i) ? value.to_i : (value ? 1 : 0)
|
356
|
+
end
|
357
|
+
|
358
|
+
def self.cast_to_date_or_time(value)
|
359
|
+
return value if value.is_a? Date
|
360
|
+
return nil if value.blank?
|
361
|
+
guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value))
|
362
|
+
end
|
363
|
+
|
364
|
+
def self.cast_to_time(value)
|
365
|
+
return value if value.is_a? Time
|
366
|
+
time_array = ParseDate.parsedate value
|
367
|
+
time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
|
368
|
+
Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
|
369
|
+
end
|
370
|
+
|
371
|
+
def self.guess_date_or_time(value)
|
372
|
+
(value.hour == 0 and value.min == 0 and value.sec == 0) ?
|
373
|
+
Date.new(value.year, value.month, value.day) : value
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
class SQLite3Adapter < JdbcAdapter
|
378
|
+
include ArJdbc::SQLite3
|
379
|
+
|
380
|
+
def adapter_spec(config)
|
381
|
+
# return nil to avoid extending ArJdbc::SQLite3, which we've already done
|
382
|
+
end
|
383
|
+
|
384
|
+
def jdbc_column_class
|
385
|
+
ActiveRecord::ConnectionAdapters::SQLiteColumn
|
386
|
+
end
|
385
387
|
end
|
386
388
|
end
|