activerecord-jdbc-adapter 1.2.9.1 → 1.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/Appraisals +12 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +19 -19
- data/History.txt +90 -16
- data/LICENSE.txt +2 -1
- data/README.md +14 -1
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/gemfiles/rails23.gemfile +5 -5
- data/gemfiles/rails23.gemfile.lock +27 -27
- data/gemfiles/rails30.gemfile +3 -3
- data/gemfiles/rails30.gemfile.lock +8 -8
- data/gemfiles/rails31.gemfile +4 -4
- data/gemfiles/rails31.gemfile.lock +18 -18
- data/gemfiles/rails32.gemfile +4 -4
- data/gemfiles/rails32.gemfile.lock +17 -17
- data/gemfiles/rails40.gemfile +17 -0
- data/gemfiles/rails40.gemfile.lock +126 -0
- data/lib/activerecord-jdbc-adapter.rb +0 -7
- data/lib/arjdbc.rb +6 -5
- data/lib/arjdbc/db2.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +52 -29
- data/lib/arjdbc/db2/connection_methods.rb +13 -14
- data/lib/arjdbc/derby.rb +1 -1
- data/lib/arjdbc/derby/adapter.rb +29 -9
- data/lib/arjdbc/derby/connection_methods.rb +17 -20
- data/lib/arjdbc/firebird.rb +1 -1
- data/lib/arjdbc/h2.rb +2 -2
- data/lib/arjdbc/h2/adapter.rb +1 -1
- data/lib/arjdbc/h2/connection_methods.rb +12 -16
- data/lib/arjdbc/hsqldb.rb +1 -1
- data/lib/arjdbc/hsqldb/connection_methods.rb +13 -16
- data/lib/arjdbc/informix.rb +1 -1
- data/lib/arjdbc/informix/connection_methods.rb +8 -10
- data/lib/arjdbc/jdbc.rb +1 -1
- data/lib/arjdbc/jdbc/adapter.rb +125 -53
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +34 -9
- data/lib/arjdbc/jdbc/column.rb +15 -2
- data/lib/arjdbc/jdbc/connection.rb +0 -2
- data/lib/arjdbc/jdbc/connection_methods.rb +10 -3
- data/lib/arjdbc/jdbc/driver.rb +2 -2
- data/lib/arjdbc/jdbc/extension.rb +35 -21
- data/lib/arjdbc/jdbc/java.rb +0 -2
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +35 -25
- data/lib/arjdbc/jdbc/railtie.rb +2 -9
- data/lib/arjdbc/mimer.rb +1 -1
- data/lib/arjdbc/mssql.rb +2 -2
- data/lib/arjdbc/mssql/adapter.rb +271 -92
- data/lib/arjdbc/mssql/connection_methods.rb +30 -32
- data/lib/arjdbc/mssql/explain_support.rb +107 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +48 -18
- data/lib/arjdbc/mysql.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +63 -14
- data/lib/arjdbc/mysql/connection_methods.rb +22 -24
- data/lib/arjdbc/mysql/explain_support.rb +2 -5
- data/lib/arjdbc/oracle.rb +1 -1
- data/lib/arjdbc/oracle/adapter.rb +78 -38
- data/lib/arjdbc/oracle/connection_methods.rb +9 -10
- data/lib/arjdbc/postgresql.rb +1 -1
- data/lib/arjdbc/postgresql/adapter.rb +964 -380
- data/lib/arjdbc/postgresql/column_cast.rb +136 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +19 -21
- data/lib/arjdbc/postgresql/explain_support.rb +3 -6
- data/lib/arjdbc/railtie.rb +9 -0
- data/lib/arjdbc/sqlite3.rb +1 -1
- data/lib/arjdbc/sqlite3/adapter.rb +73 -26
- data/lib/arjdbc/sqlite3/connection_methods.rb +27 -28
- data/lib/arjdbc/sqlite3/explain_support.rb +2 -5
- data/lib/arjdbc/sybase.rb +1 -1
- data/lib/arjdbc/version.rb +5 -4
- data/pom.xml +8 -0
- data/rakelib/02-test.rake +57 -51
- data/rakelib/compile.rake +17 -5
- data/rakelib/rails.rake +42 -31
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +4 -3
- data/src/java/arjdbc/derby/DerbyModule.java +98 -85
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +0 -4
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +26 -15
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +10 -2
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1675 -834
- data/src/java/arjdbc/jdbc/SQLBlock.java +9 -3
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +73 -36
- data/src/java/arjdbc/mysql/MySQLModule.java +11 -10
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +86 -80
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +27 -7
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +25 -67
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +52 -49
- data/src/java/arjdbc/util/QuotingUtils.java +6 -6
- data/test/abstract_db_create.rb +11 -11
- data/test/activerecord/connection_adapters/type_conversion_test.rb +18 -12
- data/test/db/db2.rb +1 -1
- data/test/{db2_binary_test.rb → db/db2/binary_test.rb} +0 -0
- data/test/db/db2/has_many_through_test.rb +6 -0
- data/test/{db2_reset_column_information_test.rb → db/db2/reset_column_information_test.rb} +1 -2
- data/test/{db2_serialize_test.rb → db/db2/serialize_test.rb} +0 -0
- data/test/{db2_simple_test.rb → db/db2/simple_test.rb} +1 -8
- data/test/db/db2/test_helper.rb +6 -0
- data/test/{db2_test.rb → db/db2/unit_test.rb} +1 -1
- data/test/db/derby.rb +1 -1
- data/test/{derby_binary_test.rb → db/derby/binary_test.rb} +0 -0
- data/test/{derby_migration_test.rb → db/derby/migration_test.rb} +0 -0
- data/test/{derby_reset_column_information_test.rb → db/derby/reset_column_information_test.rb} +0 -0
- data/test/{derby_row_locking_test.rb → db/derby/row_locking_test.rb} +1 -4
- data/test/db/derby/schema_dump_test.rb +5 -0
- data/test/{derby_serialize_test.rb → db/derby/serialize_test.rb} +0 -0
- data/test/{derby_simple_test.rb → db/derby/simple_test.rb} +23 -38
- data/test/db/derby/test_helper.rb +6 -0
- data/test/db/derby/unit_test.rb +32 -0
- data/test/db/derby/xml_column_test.rb +17 -0
- data/test/db/h2.rb +1 -1
- data/test/{h2_binary_test.rb → db/h2/binary_test.rb} +0 -0
- data/test/{h2_change_column_test.rb → db/h2/change_column_test.rb} +1 -0
- data/test/{h2_schema_dump_test.rb → db/h2/schema_dump_test.rb} +0 -0
- data/test/{h2_serialize_test.rb → db/h2/serialize_test.rb} +0 -0
- data/test/{h2_simple_test.rb → db/h2/simple_test.rb} +3 -1
- data/test/db/hsqldb.rb +1 -1
- data/test/{hsqldb_binary_test.rb → db/hsqldb/binary_test.rb} +0 -0
- data/test/{hsqldb_schema_dump_test.rb → db/hsqldb/schema_dump_test.rb} +0 -0
- data/test/{hsqldb_serialize_test.rb → db/hsqldb/serialize_test.rb} +0 -0
- data/test/{hsqldb_simple_test.rb → db/hsqldb/simple_test.rb} +3 -1
- data/test/db/informix.rb +1 -1
- data/test/db/jdbc.rb +3 -2
- data/test/db/jdbc_derby.rb +1 -1
- data/test/db/jdbc_h2.rb +1 -1
- data/test/db/jdbc_mysql.rb +1 -1
- data/test/db/jdbc_postgres.rb +1 -1
- data/test/db/jndi_config.rb +1 -2
- data/test/db/jndi_pooled_config.rb +2 -3
- data/test/db/mssql.rb +2 -2
- data/test/{mssql_binary_test.rb → db/mssql/binary_test.rb} +0 -0
- data/test/{mssql_db_create_test.rb → db/mssql/db_create_test.rb} +1 -1
- data/test/db/mssql/exec_proc_test.rb +46 -0
- data/test/{mssql_identity_insert_test.rb → db/mssql/identity_insert_test.rb} +0 -0
- data/test/db/mssql/ignore_system_views_test.rb +40 -0
- data/test/{mssql_limit_offset_test.rb → db/mssql/limit_offset_test.rb} +10 -1
- data/test/{mssql_multibyte_test.rb → db/mssql/multibyte_test.rb} +0 -0
- data/test/db/mssql/multiple_connections_test.rb +71 -0
- data/test/{mssql_reset_column_information_test.rb → db/mssql/reset_column_information_test.rb} +0 -0
- data/test/{mssql_row_locking_test.rb → db/mssql/row_locking_test.rb} +0 -0
- data/test/{mssql_serialize_test.rb → db/mssql/serialize_test.rb} +1 -1
- data/test/db/mssql/simple_test.rb +140 -0
- data/test/db/mssql/transaction_test.rb +6 -0
- data/test/db/mssql/types_test.rb +205 -0
- data/test/{mssql_test.rb → db/mssql/unit_test.rb} +2 -2
- data/test/db/mysql.rb +1 -2
- data/test/db/mysql/_rails_test_mysql.32.out +6768 -0
- data/test/{mysql_binary_test.rb → db/mysql/binary_test.rb} +0 -0
- data/test/db/mysql/connection_test.rb +51 -0
- data/test/{mysql_db_create_test.rb → db/mysql/db_create_test.rb} +0 -0
- data/test/{mysql_index_length_test.rb → db/mysql/index_length_test.rb} +0 -0
- data/test/{mysql_multibyte_test.rb → db/mysql/multibyte_test.rb} +0 -0
- data/test/{mysql_nonstandard_primary_key_test.rb → db/mysql/nonstandard_primary_key_test.rb} +0 -0
- data/test/{mysql_reset_column_information_test.rb → db/mysql/reset_column_information_test.rb} +0 -0
- data/test/{mysql_schema_dump_test.rb → db/mysql/schema_dump_test.rb} +9 -1
- data/test/{mysql_serialize_test.rb → db/mysql/serialize_test.rb} +0 -0
- data/test/{mysql_simple_test.rb → db/mysql/simple_test.rb} +16 -8
- data/test/db/mysql/transaction_test.rb +6 -0
- data/test/db/mysql/types_test.rb +30 -0
- data/test/{mysql_test.rb → db/mysql/unit_test.rb} +1 -1
- data/test/db/mysql_config.rb +1 -1
- data/test/db/oracle.rb +1 -1
- data/test/{oracle_binary_test.rb → db/oracle/binary_test.rb} +0 -0
- data/test/{oracle_limit_test.rb → db/oracle/limit_test.rb} +0 -0
- data/test/db/oracle/multibyte_test.rb +22 -0
- data/test/{oracle_reset_column_information_test.rb → db/oracle/reset_column_information_test.rb} +0 -0
- data/test/{oracle_serialize_test.rb → db/oracle/serialize_test.rb} +0 -0
- data/test/{oracle_simple_test.rb → db/oracle/simple_test.rb} +14 -19
- data/test/{oracle_specific_test.rb → db/oracle/specific_test.rb} +62 -16
- data/test/db/oracle/transaction_test.rb +31 -0
- data/test/db/oracle/unit_test.rb +31 -0
- data/test/db/postgres.rb +1 -1
- data/test/db/postgres/_rails_test_postgres.32.out +6777 -0
- data/test/db/postgres/a_custom_primary_key_test.rb +50 -0
- data/test/db/postgres/array_type_test.rb +101 -0
- data/test/{postgres_binary_test.rb → db/postgres/binary_test.rb} +0 -0
- data/test/db/postgres/connection_test.rb +55 -0
- data/test/db/postgres/data_types_test.rb +703 -0
- data/test/{postgres_db_create_test.rb → db/postgres/db_create_test.rb} +1 -1
- data/test/{postgres_drop_db_test.rb → db/postgres/db_drop_test.rb} +2 -0
- data/test/db/postgres/hstore_test.rb +200 -0
- data/test/db/postgres/information_schema_leak_test.rb +30 -0
- data/test/db/postgres/json_test.rb +86 -0
- data/test/db/postgres/ltree_test.rb +50 -0
- data/test/{postgres_mixed_case_test.rb → db/postgres/mixed_case_test.rb} +0 -0
- data/test/db/postgres/native_types_test.rb +128 -0
- data/test/{postgres_reserved_test.rb → db/postgres/reserved_test.rb} +0 -0
- data/test/{postgres_reset_column_information_test.rb → db/postgres/reset_column_information_test.rb} +0 -0
- data/test/{postgres_row_locking_test.rb → db/postgres/row_locking_test.rb} +0 -0
- data/test/{postgres_schema_dump_test.rb → db/postgres/schema_dump_test.rb} +4 -4
- data/test/db/postgres/schema_test.rb +113 -0
- data/test/{postgres_simple_test.rb → db/postgres/simple_test.rb} +48 -8
- data/test/{postgres_table_alias_length_test.rb → db/postgres/table_alias_length_test.rb} +2 -1
- data/test/db/postgres/transaction_test.rb +6 -0
- data/test/{postgres_test.rb → db/postgres/unit_test.rb} +3 -3
- data/test/db/sqlite3.rb +1 -1
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +6502 -0
- data/test/db/sqlite3/has_many_though_test.rb +6 -0
- data/test/{sqlite3_reset_column_information_test.rb → db/sqlite3/reset_column_information_test.rb} +0 -0
- data/test/{sqlite3_schema_dump_test.rb → db/sqlite3/schema_dump_test.rb} +0 -0
- data/test/{sqlite3_serialize_test.rb → db/sqlite3/serialize_test.rb} +0 -0
- data/test/{sqlite3_simple_test.rb → db/sqlite3/simple_test.rb} +63 -63
- data/test/db/sqlite3/transaction_test.rb +32 -0
- data/test/{sqlite3_type_conversion_test.rb → db/sqlite3/type_conversion_test.rb} +0 -0
- data/test/has_many_through.rb +29 -64
- data/test/jdbc/oracle.rb +11 -0
- data/test/jndi_test.rb +16 -4
- data/test/models/auto_id.rb +1 -1
- data/test/models/rights_and_roles.rb +57 -0
- data/test/row_locking.rb +3 -0
- data/test/schema_dump.rb +24 -10
- data/test/simple.rb +359 -104
- data/test/test_helper.rb +4 -2
- data/test/transaction.rb +109 -0
- metadata +119 -86
- data/lib/arjdbc/jdbc/compatibility.rb +0 -51
- data/lib/arjdbc/jdbc/core_ext.rb +0 -24
- data/lib/arjdbc/jdbc/discover.rb +0 -18
- data/test/derby_schema_dump_test.rb +0 -9
- data/test/mssql_ignore_system_views_test.rb +0 -30
- data/test/mssql_legacy_types_test.rb +0 -58
- data/test/mssql_null_test.rb +0 -14
- data/test/mssql_simple_test.rb +0 -51
- data/test/postgres_information_schema_leak_test.rb +0 -28
- data/test/postgres_native_type_mapping_test.rb +0 -93
- data/test/postgres_nonseq_pkey_test.rb +0 -38
- data/test/postgres_schema_search_path_test.rb +0 -48
- data/test/postgres_type_conversion_test.rb +0 -33
@@ -0,0 +1,136 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module PostgreSQL
|
3
|
+
module Column
|
4
|
+
# based on active_record/connection_adapters/postgresql/cast.rb
|
5
|
+
module Cast
|
6
|
+
|
7
|
+
def string_to_time(string)
|
8
|
+
return string unless String === string
|
9
|
+
|
10
|
+
case string
|
11
|
+
when 'infinity'; 1.0 / 0.0
|
12
|
+
when '-infinity'; -1.0 / 0.0
|
13
|
+
when / BC$/
|
14
|
+
super("-" + string.sub(/ BC$/, ""))
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def hstore_to_string(object)
|
21
|
+
if Hash === object
|
22
|
+
object.map { |k,v|
|
23
|
+
"#{escape_hstore(k)}=>#{escape_hstore(v)}"
|
24
|
+
}.join ','
|
25
|
+
else
|
26
|
+
object
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def string_to_hstore(string)
|
31
|
+
if string.nil?
|
32
|
+
nil
|
33
|
+
elsif String === string
|
34
|
+
Hash[string.scan(HstorePair).map { |k,v|
|
35
|
+
v = v.upcase == 'NULL' ? nil : v.gsub(/^"(.*)"$/,'\1').gsub(/\\(.)/, '\1')
|
36
|
+
k = k.gsub(/^"(.*)"$/,'\1').gsub(/\\(.)/, '\1')
|
37
|
+
[k,v]
|
38
|
+
}]
|
39
|
+
else
|
40
|
+
string
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def json_to_string(object)
|
45
|
+
if Hash === object
|
46
|
+
ActiveSupport::JSON.encode(object)
|
47
|
+
else
|
48
|
+
object
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def array_to_string(value, column, adapter, should_be_quoted = false)
|
53
|
+
casted_values = value.map do |val|
|
54
|
+
if String === val
|
55
|
+
if val == "NULL"
|
56
|
+
"\"#{val}\""
|
57
|
+
else
|
58
|
+
quote_and_escape(adapter.type_cast(val, column, true))
|
59
|
+
end
|
60
|
+
else
|
61
|
+
adapter.type_cast(val, column, true)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
"{#{casted_values.join(',')}}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def range_to_string(object)
|
68
|
+
from = object.begin.respond_to?(:infinite?) && object.begin.infinite? ? '' : object.begin
|
69
|
+
to = object.end.respond_to?(:infinite?) && object.end.infinite? ? '' : object.end
|
70
|
+
"[#{from},#{to}#{object.exclude_end? ? ')' : ']'}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def string_to_json(string)
|
74
|
+
if String === string
|
75
|
+
ActiveSupport::JSON.decode(string)
|
76
|
+
else
|
77
|
+
string
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def string_to_cidr(string)
|
82
|
+
if string.nil?
|
83
|
+
nil
|
84
|
+
elsif String === string
|
85
|
+
IPAddr.new(string)
|
86
|
+
else
|
87
|
+
string
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def cidr_to_string(object)
|
92
|
+
if IPAddr === object
|
93
|
+
"#{object.to_s}/#{object.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
|
94
|
+
else
|
95
|
+
object
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# NOTE: not used - we get "parsed" array value from connection
|
100
|
+
#def string_to_array(string, oid)
|
101
|
+
# parse_pg_array(string).map { |val| oid.type_cast val }
|
102
|
+
#end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
HstorePair = begin
|
107
|
+
quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"/
|
108
|
+
unquoted_string = /(?:\\.|[^\s,])[^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*/
|
109
|
+
/(#{quoted_string}|#{unquoted_string})\s*=>\s*(#{quoted_string}|#{unquoted_string})/
|
110
|
+
end
|
111
|
+
|
112
|
+
def escape_hstore(value)
|
113
|
+
if value.nil?
|
114
|
+
'NULL'
|
115
|
+
else
|
116
|
+
if value == ""
|
117
|
+
'""'
|
118
|
+
else
|
119
|
+
'"%s"' % value.to_s.gsub(/(["\\])/, '\\\\\1')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def quote_and_escape(value)
|
125
|
+
case value
|
126
|
+
when "NULL"
|
127
|
+
value
|
128
|
+
else
|
129
|
+
"\"#{value.gsub(/"/,"\\\"")}\""
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -1,24 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
rescue LoadError # assuming driver.jar is on the class-path
|
8
|
-
end
|
9
|
-
|
10
|
-
config[:username] ||= Java::JavaLang::System.get_property("user.name")
|
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] ||= defined?(::Jdbc::Postgres.driver_name) ? ::Jdbc::Postgres.driver_name : 'org.postgresql.Driver'
|
16
|
-
config[:adapter_class] = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
17
|
-
config[:adapter_spec] = ::ArJdbc::PostgreSQL
|
18
|
-
conn = jdbc_connection(config)
|
19
|
-
conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path]
|
20
|
-
conn
|
1
|
+
ArJdbc::ConnectionMethods.module_eval do
|
2
|
+
def postgresql_connection(config)
|
3
|
+
begin
|
4
|
+
require 'jdbc/postgres'
|
5
|
+
::Jdbc::Postgres.load_driver(:require) if defined?(::Jdbc::Postgres.load_driver)
|
6
|
+
rescue LoadError # assuming driver.jar is on the class-path
|
21
7
|
end
|
22
|
-
|
8
|
+
|
9
|
+
config[:username] ||= Java::JavaLang::System.get_property("user.name")
|
10
|
+
config[:host] ||= "localhost"
|
11
|
+
config[:port] ||= 5432
|
12
|
+
config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
|
13
|
+
config[:url] << config[:pg_params] if config[:pg_params]
|
14
|
+
config[:driver] ||= defined?(::Jdbc::Postgres.driver_name) ? ::Jdbc::Postgres.driver_name : 'org.postgresql.Driver'
|
15
|
+
config[:adapter_class] = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
16
|
+
config[:adapter_spec] = ::ArJdbc::PostgreSQL
|
17
|
+
conn = jdbc_connection(config)
|
18
|
+
conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path]
|
19
|
+
conn
|
23
20
|
end
|
21
|
+
alias_method :jdbcpostgresql_connection, :postgresql_connection
|
24
22
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ArJdbc
|
2
2
|
module PostgreSQL
|
3
3
|
module ExplainSupport
|
4
4
|
def supports_explain?
|
@@ -7,11 +7,8 @@ module ::ArJdbc
|
|
7
7
|
|
8
8
|
def explain(arel, binds = [])
|
9
9
|
sql = "EXPLAIN #{to_sql(arel, binds)}"
|
10
|
-
|
11
|
-
#
|
12
|
-
keys = raw_result[0] ? raw_result[0].keys : {}
|
13
|
-
rows = raw_result.map { |hash| hash.values }
|
14
|
-
ExplainPrettyPrinter.new.pp ActiveRecord::Result.new(keys, rows)
|
10
|
+
result = exec_query(sql, "EXPLAIN", binds)
|
11
|
+
ExplainPrettyPrinter.new.pp result # we can assume AR >= 3.1
|
15
12
|
end
|
16
13
|
|
17
14
|
class ExplainPrettyPrinter # :nodoc:
|
data/lib/arjdbc/sqlite3.rb
CHANGED
@@ -157,6 +157,30 @@ module ::ArJdbc
|
|
157
157
|
def supports_index_sort_order? # :nodoc:
|
158
158
|
sqlite_version >= '3.3.0'
|
159
159
|
end
|
160
|
+
|
161
|
+
def supports_migrations? # :nodoc:
|
162
|
+
true
|
163
|
+
end
|
164
|
+
|
165
|
+
def supports_primary_key? # :nodoc:
|
166
|
+
true
|
167
|
+
end
|
168
|
+
|
169
|
+
def supports_add_column? # :nodoc:
|
170
|
+
true
|
171
|
+
end
|
172
|
+
|
173
|
+
def supports_count_distinct? # :nodoc:
|
174
|
+
true
|
175
|
+
end
|
176
|
+
|
177
|
+
def supports_autoincrement? # :nodoc:
|
178
|
+
true
|
179
|
+
end
|
180
|
+
|
181
|
+
def supports_index_sort_order? # :nodoc:
|
182
|
+
true
|
183
|
+
end
|
160
184
|
|
161
185
|
def sqlite_version
|
162
186
|
@sqlite_version ||= select_value('SELECT sqlite_version(*)')
|
@@ -197,9 +221,12 @@ module ::ArJdbc
|
|
197
221
|
end
|
198
222
|
|
199
223
|
def tables(name = nil, table_name = nil) # :nodoc:
|
200
|
-
sql = "SELECT name FROM sqlite_master "
|
201
|
-
|
202
|
-
|
224
|
+
sql = "SELECT name FROM sqlite_master WHERE type = 'table'"
|
225
|
+
if table_name
|
226
|
+
sql << " AND name = #{quote_table_name(table_name)}"
|
227
|
+
else
|
228
|
+
sql << " AND NOT name = 'sqlite_sequence'"
|
229
|
+
end
|
203
230
|
|
204
231
|
select_rows(sql, name).map { |row| row[0] }
|
205
232
|
end
|
@@ -223,6 +250,13 @@ module ::ArJdbc
|
|
223
250
|
IndexDefinition.new(table_name, name, unique, columns)
|
224
251
|
end
|
225
252
|
end
|
253
|
+
|
254
|
+
# Returns 62. SQLite supports index names up to 64
|
255
|
+
# characters. The rest is used by rails internally to perform
|
256
|
+
# temporary rename operations
|
257
|
+
def allowed_index_name_length
|
258
|
+
index_name_length - 2
|
259
|
+
end
|
226
260
|
|
227
261
|
def create_savepoint
|
228
262
|
execute("SAVEPOINT #{current_savepoint_name}")
|
@@ -239,49 +273,60 @@ module ::ArJdbc
|
|
239
273
|
def recreate_database(name, options = {})
|
240
274
|
tables.each { |table| drop_table(table) }
|
241
275
|
end
|
242
|
-
|
276
|
+
|
243
277
|
def select(sql, name = nil, binds = [])
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
278
|
+
result = super # AR::Result (4.0) or Array (<= 3.2)
|
279
|
+
if result.respond_to?(:columns) # 4.0
|
280
|
+
result.columns.map! do |key| # [ [ 'id', ... ]
|
281
|
+
key.is_a?(String) ? key.sub(/^"?\w+"?\./, '') : key
|
282
|
+
end
|
283
|
+
else
|
284
|
+
result.map! do |row| # [ { 'id' => ... }, {...} ]
|
285
|
+
record = {}
|
286
|
+
row.each_key do |key|
|
287
|
+
if key.is_a?(String)
|
288
|
+
record[key.sub(/^"?\w+"?\./, '')] = row[key]
|
289
|
+
end
|
249
290
|
end
|
291
|
+
record
|
250
292
|
end
|
251
|
-
record
|
252
293
|
end
|
294
|
+
result
|
253
295
|
end
|
254
296
|
|
297
|
+
# @override as <code>execute_insert</code> not implemented by SQLite JDBC
|
298
|
+
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) # :nodoc:
|
299
|
+
execute(sql, name, binds)
|
300
|
+
end
|
301
|
+
|
255
302
|
def table_structure(table_name)
|
256
303
|
sql = "PRAGMA table_info(#{quote_table_name(table_name)})"
|
257
|
-
log(sql, 'SCHEMA') { @connection.
|
304
|
+
log(sql, 'SCHEMA') { @connection.execute_query_raw(sql) }
|
258
305
|
rescue ActiveRecord::JDBCError => error
|
259
306
|
e = ActiveRecord::StatementInvalid.new("Could not find table '#{table_name}'")
|
260
307
|
e.set_backtrace error.backtrace
|
261
308
|
raise e
|
262
309
|
end
|
263
310
|
|
264
|
-
def jdbc_columns(table_name, name = nil)
|
311
|
+
def jdbc_columns(table_name, name = nil) # :nodoc:
|
312
|
+
klass = ::ActiveRecord::ConnectionAdapters::SQLite3Column
|
265
313
|
table_structure(table_name).map do |field|
|
266
|
-
|
267
|
-
@config, field['name'], field['dflt_value'], field['type'], field['notnull'] == 0
|
268
|
-
)
|
314
|
+
klass.new(field['name'], field['dflt_value'], field['type'], field['notnull'] == 0)
|
269
315
|
end
|
270
316
|
end
|
271
317
|
|
272
318
|
def primary_key(table_name) #:nodoc:
|
273
|
-
column = table_structure(table_name).find { |field|
|
274
|
-
field['pk'].to_i == 1
|
275
|
-
}
|
319
|
+
column = table_structure(table_name).find { |field| field['pk'].to_i == 1 }
|
276
320
|
column && column['name']
|
277
321
|
end
|
278
322
|
|
279
|
-
def remove_index!(table_name, index_name)
|
323
|
+
def remove_index!(table_name, index_name) # :nodoc:
|
280
324
|
execute "DROP INDEX #{quote_column_name(index_name)}"
|
281
325
|
end
|
282
326
|
|
283
|
-
def rename_table(
|
284
|
-
execute "ALTER TABLE #{quote_table_name(
|
327
|
+
def rename_table(table_name, new_name)
|
328
|
+
execute "ALTER TABLE #{quote_table_name(table_name)} RENAME TO #{quote_table_name(new_name)}"
|
329
|
+
rename_table_indexes(table_name, new_name) if respond_to?(:rename_table_indexes) # AR-4.0 SchemaStatements
|
285
330
|
end
|
286
331
|
|
287
332
|
# See: http://www.sqlite.org/lang_altertable.html
|
@@ -349,6 +394,7 @@ module ::ArJdbc
|
|
349
394
|
raise ActiveRecord::ActiveRecordError, "Missing column #{table_name}.#{column_name}"
|
350
395
|
end
|
351
396
|
alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s})
|
397
|
+
rename_column_indexes(table_name, column_name, new_column_name) if respond_to?(:rename_column_indexes) # AR-4.0 SchemaStatements
|
352
398
|
end
|
353
399
|
|
354
400
|
# SELECT ... FOR UPDATE is redundant since the table is locked.
|
@@ -357,9 +403,13 @@ module ::ArJdbc
|
|
357
403
|
end
|
358
404
|
|
359
405
|
def empty_insert_statement_value
|
360
|
-
"VALUES(
|
406
|
+
# inherited (default) on 3.2 : "VALUES(DEFAULT)"
|
407
|
+
# inherited (default) on 4.0 : "DEFAULT VALUES"
|
408
|
+
# re-defined in native adapter on 3.2 "VALUES(NULL)"
|
409
|
+
# on 4.0 no longer re-defined (thus inherits default)
|
410
|
+
"DEFAULT VALUES"
|
361
411
|
end
|
362
|
-
|
412
|
+
|
363
413
|
protected
|
364
414
|
|
365
415
|
include ArJdbc::MissingFunctionalityHelper
|
@@ -406,9 +456,6 @@ module ActiveRecord::ConnectionAdapters
|
|
406
456
|
end
|
407
457
|
end
|
408
458
|
|
409
|
-
def call_discovered_column_callbacks(*)
|
410
|
-
end
|
411
|
-
|
412
459
|
def self.string_to_binary(value)
|
413
460
|
value
|
414
461
|
end
|
@@ -1,34 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
rescue LoadError # assuming driver.jar is on the class-path
|
8
|
-
end
|
9
|
-
|
10
|
-
parse_sqlite3_config!(config)
|
11
|
-
database = config[:database]
|
12
|
-
database = '' if database == ':memory:'
|
13
|
-
config[:url] ||= "jdbc:sqlite:#{database}"
|
14
|
-
config[:driver] ||= defined?(::Jdbc::SQLite3.driver_name) ? ::Jdbc::SQLite3.driver_name : 'org.sqlite.JDBC'
|
15
|
-
config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
16
|
-
config[:adapter_spec] = ::ArJdbc::SQLite3
|
17
|
-
jdbc_connection(config)
|
1
|
+
ArJdbc::ConnectionMethods.module_eval do
|
2
|
+
def sqlite3_connection(config)
|
3
|
+
begin
|
4
|
+
require 'jdbc/sqlite3'
|
5
|
+
::Jdbc::SQLite3.load_driver(:require) if defined?(::Jdbc::SQLite3.load_driver)
|
6
|
+
rescue LoadError # assuming driver.jar is on the class-path
|
18
7
|
end
|
19
|
-
alias_method :jdbcsqlite3_connection, :sqlite3_connection
|
20
8
|
|
21
|
-
|
22
|
-
|
9
|
+
parse_sqlite3_config!(config)
|
10
|
+
database = config[:database]
|
11
|
+
database = '' if database == ':memory:'
|
12
|
+
config[:url] ||= "jdbc:sqlite:#{database}"
|
13
|
+
config[:driver] ||= defined?(::Jdbc::SQLite3.driver_name) ? ::Jdbc::SQLite3.driver_name : 'org.sqlite.JDBC'
|
14
|
+
config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
15
|
+
config[:adapter_spec] = ::ArJdbc::SQLite3
|
16
|
+
jdbc_connection(config)
|
17
|
+
end
|
18
|
+
alias_method :jdbcsqlite3_connection, :sqlite3_connection
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
private
|
21
|
+
def parse_sqlite3_config!(config)
|
22
|
+
config[:database] ||= config[:dbfile]
|
23
|
+
|
24
|
+
# Allow database path relative to RAILS_ROOT, but only if
|
25
|
+
# the database path is not the special path that tells
|
26
|
+
# Sqlite to build a database only in memory.
|
27
|
+
rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
|
28
|
+
if rails_root_defined && ':memory:' != config[:database]
|
29
|
+
rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
|
30
|
+
config[:database] = File.expand_path(config[:database], rails_root)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|