activerecord-jdbc-adapter 1.3.0.beta2 → 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -8
- data/.travis.yml +40 -31
- data/.yardopts +4 -0
- data/Appraisals +2 -5
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +21 -4
- data/Gemfile.lock +42 -17
- data/{History.txt → History.md} +142 -75
- data/README.md +102 -104
- data/RUNNING_TESTS.md +76 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +35 -18
- data/gemfiles/rails23.gemfile +4 -3
- data/gemfiles/rails23.gemfile.lock +9 -6
- data/gemfiles/rails30.gemfile +4 -3
- data/gemfiles/rails30.gemfile.lock +9 -6
- data/gemfiles/rails31.gemfile +4 -3
- data/gemfiles/rails31.gemfile.lock +9 -6
- data/gemfiles/rails32.gemfile +4 -3
- data/gemfiles/rails32.gemfile.lock +17 -14
- data/gemfiles/rails40.gemfile +5 -5
- data/gemfiles/rails40.gemfile.lock +17 -69
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +22 -3
- data/lib/arel/visitors/db2.rb +8 -4
- data/lib/arel/visitors/derby.rb +14 -13
- data/lib/arel/visitors/firebird.rb +5 -4
- data/lib/arel/visitors/hsqldb.rb +11 -9
- data/lib/arel/visitors/sql_server.rb +89 -61
- data/lib/arjdbc.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +181 -212
- data/lib/arjdbc/db2/as400.rb +31 -18
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +2 -0
- data/lib/arjdbc/derby/adapter.rb +206 -107
- data/lib/arjdbc/derby/connection_methods.rb +4 -9
- data/lib/arjdbc/firebird.rb +1 -0
- data/lib/arjdbc/firebird/adapter.rb +202 -64
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2/adapter.rb +56 -36
- data/lib/arjdbc/hsqldb/adapter.rb +99 -68
- data/lib/arjdbc/jdbc/adapter.rb +474 -265
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +8 -7
- data/lib/arjdbc/jdbc/arel_support.rb +132 -0
- data/lib/arjdbc/jdbc/base_ext.rb +8 -7
- data/lib/arjdbc/jdbc/callbacks.rb +16 -10
- data/lib/arjdbc/jdbc/column.rb +25 -3
- data/lib/arjdbc/jdbc/connection.rb +28 -55
- data/lib/arjdbc/jdbc/extension.rb +14 -14
- data/lib/arjdbc/jdbc/java.rb +6 -3
- data/lib/arjdbc/jdbc/jdbc.rake +1 -1
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +2 -2
- data/lib/arjdbc/jdbc/rake_tasks.rb +1 -1
- data/lib/arjdbc/jdbc/type_converter.rb +5 -2
- data/lib/arjdbc/mssql/adapter.rb +160 -280
- data/lib/arjdbc/mssql/column.rb +182 -0
- data/lib/arjdbc/mssql/connection_methods.rb +37 -4
- data/lib/arjdbc/mssql/explain_support.rb +13 -21
- data/lib/arjdbc/mssql/limit_helpers.rb +79 -42
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/utils.rb +11 -11
- data/lib/arjdbc/mysql/adapter.rb +165 -247
- data/lib/arjdbc/mysql/column.rb +123 -0
- data/lib/arjdbc/mysql/connection_methods.rb +3 -6
- data/lib/arjdbc/oracle/adapter.rb +282 -288
- data/lib/arjdbc/oracle/column.rb +122 -0
- data/lib/arjdbc/oracle/connection_methods.rb +3 -0
- data/lib/arjdbc/postgresql/adapter.rb +336 -574
- data/lib/arjdbc/postgresql/column.rb +458 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +1 -2
- data/lib/arjdbc/postgresql/schema_creation.rb +38 -0
- data/lib/arjdbc/sqlite3/adapter.rb +189 -145
- data/lib/arjdbc/sqlite3/explain_support.rb +1 -1
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +8 -8
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +6 -7
- data/pom.xml +56 -2
- data/rakelib/02-test.rake +72 -83
- data/rakelib/db.rake +29 -17
- data/src/java/arjdbc/ArJdbcModule.java +21 -18
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +84 -12
- data/src/java/arjdbc/derby/DerbyModule.java +140 -143
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +58 -7
- data/src/java/arjdbc/h2/H2Module.java +43 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1223 -648
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +24 -23
- data/src/java/arjdbc/mysql/MySQLModule.java +33 -32
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +147 -30
- data/src/java/arjdbc/oracle/OracleModule.java +13 -13
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +114 -6
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +166 -36
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +101 -19
- data/src/java/arjdbc/util/QuotingUtils.java +19 -19
- metadata +240 -394
- data/bench/bench_attributes.rb +0 -13
- data/bench/bench_attributes_new.rb +0 -14
- data/bench/bench_create.rb +0 -12
- data/bench/bench_find_all.rb +0 -12
- data/bench/bench_find_all_mt.rb +0 -25
- data/bench/bench_model.rb +0 -85
- data/bench/bench_new.rb +0 -12
- data/bench/bench_new_valid.rb +0 -12
- data/bench/bench_valid.rb +0 -13
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -98
- data/lib/arjdbc/mssql/lock_helpers.rb +0 -76
- data/lib/arjdbc/mssql/tsql_methods.rb +0 -58
- data/lib/arjdbc/postgresql/column_cast.rb +0 -134
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/activerecord/jall.sh +0 -7
- data/test/activerecord/jtest.sh +0 -3
- data/test/assets/flowers.jpg +0 -0
- data/test/binary.rb +0 -67
- data/test/db/db2.rb +0 -43
- data/test/db/db2/binary_test.rb +0 -6
- data/test/db/db2/has_many_through_test.rb +0 -6
- data/test/db/db2/rake_test.rb +0 -82
- data/test/db/db2/rake_test_data.sql +0 -35
- data/test/db/db2/reset_column_information_test.rb +0 -5
- data/test/db/db2/serialize_test.rb +0 -6
- data/test/db/db2/simple_test.rb +0 -81
- data/test/db/db2/test_helper.rb +0 -6
- data/test/db/db2/unit_test.rb +0 -73
- data/test/db/derby.rb +0 -12
- data/test/db/derby/binary_test.rb +0 -6
- data/test/db/derby/migration_test.rb +0 -74
- data/test/db/derby/rake_test.rb +0 -96
- data/test/db/derby/reset_column_information_test.rb +0 -6
- data/test/db/derby/row_locking_test.rb +0 -20
- data/test/db/derby/schema_dump_test.rb +0 -5
- data/test/db/derby/serialize_test.rb +0 -6
- data/test/db/derby/simple_test.rb +0 -173
- data/test/db/derby/test_helper.rb +0 -6
- data/test/db/derby/unit_test.rb +0 -32
- data/test/db/derby/xml_column_test.rb +0 -17
- data/test/db/h2.rb +0 -11
- data/test/db/h2/binary_test.rb +0 -6
- data/test/db/h2/change_column_test.rb +0 -68
- data/test/db/h2/identity_column_test.rb +0 -35
- data/test/db/h2/offset_test.rb +0 -49
- data/test/db/h2/rake_test.rb +0 -98
- data/test/db/h2/schema_dump_test.rb +0 -29
- data/test/db/h2/serialize_test.rb +0 -6
- data/test/db/h2/simple_test.rb +0 -56
- data/test/db/hsqldb.rb +0 -11
- data/test/db/hsqldb/binary_test.rb +0 -6
- data/test/db/hsqldb/rake_test.rb +0 -101
- data/test/db/hsqldb/schema_dump_test.rb +0 -19
- data/test/db/hsqldb/serialize_test.rb +0 -6
- data/test/db/hsqldb/simple_test.rb +0 -17
- data/test/db/informix.rb +0 -13
- data/test/db/jdbc.rb +0 -16
- data/test/db/jdbc_derby.rb +0 -14
- data/test/db/jdbc_h2.rb +0 -17
- data/test/db/jdbc_mysql.rb +0 -13
- data/test/db/jdbc_postgres.rb +0 -23
- data/test/db/jndi_config.rb +0 -32
- data/test/db/jndi_pooled_config.rb +0 -32
- data/test/db/mssql.rb +0 -11
- data/test/db/mssql/binary_test.rb +0 -6
- data/test/db/mssql/exec_proc_test.rb +0 -46
- data/test/db/mssql/identity_insert_test.rb +0 -18
- data/test/db/mssql/ignore_system_views_test.rb +0 -40
- data/test/db/mssql/limit_offset_test.rb +0 -190
- data/test/db/mssql/multibyte_test.rb +0 -16
- data/test/db/mssql/multiple_connections_test.rb +0 -71
- data/test/db/mssql/rake_test.rb +0 -143
- data/test/db/mssql/reset_column_information_test.rb +0 -6
- data/test/db/mssql/row_locking_test.rb +0 -7
- data/test/db/mssql/serialize_test.rb +0 -6
- data/test/db/mssql/simple_test.rb +0 -140
- data/test/db/mssql/transaction_test.rb +0 -6
- data/test/db/mssql/types_test.rb +0 -205
- data/test/db/mssql/unit_test.rb +0 -249
- data/test/db/mysql.rb +0 -4
- data/test/db/mysql/_rails_test_mysql.32.out +0 -6585
- data/test/db/mysql/binary_test.rb +0 -6
- data/test/db/mysql/connection_test.rb +0 -51
- data/test/db/mysql/index_length_test.rb +0 -58
- data/test/db/mysql/multibyte_test.rb +0 -10
- data/test/db/mysql/nonstandard_primary_key_test.rb +0 -39
- data/test/db/mysql/rake_test.rb +0 -97
- data/test/db/mysql/reset_column_information_test.rb +0 -6
- data/test/db/mysql/schema_dump_test.rb +0 -228
- data/test/db/mysql/serialize_test.rb +0 -6
- data/test/db/mysql/simple_test.rb +0 -187
- data/test/db/mysql/statement_escaping_test.rb +0 -46
- data/test/db/mysql/transaction_test.rb +0 -6
- data/test/db/mysql/types_test.rb +0 -30
- data/test/db/mysql/unit_test.rb +0 -93
- data/test/db/mysql_config.rb +0 -7
- data/test/db/oracle.rb +0 -27
- data/test/db/oracle/binary_test.rb +0 -6
- data/test/db/oracle/limit_test.rb +0 -24
- data/test/db/oracle/multibyte_test.rb +0 -22
- data/test/db/oracle/rake_test.rb +0 -100
- data/test/db/oracle/reset_column_information_test.rb +0 -6
- data/test/db/oracle/serialize_test.rb +0 -6
- data/test/db/oracle/simple_test.rb +0 -140
- data/test/db/oracle/specific_test.rb +0 -180
- data/test/db/oracle/transaction_test.rb +0 -31
- data/test/db/oracle/unit_test.rb +0 -31
- data/test/db/postgres.rb +0 -11
- data/test/db/postgres/_rails_test_postgres.32.out +0 -6405
- data/test/db/postgres/a_custom_primary_key_test.rb +0 -50
- data/test/db/postgres/active_schema_unit_test.rb +0 -68
- data/test/db/postgres/array_type_test.rb +0 -101
- data/test/db/postgres/binary_test.rb +0 -6
- data/test/db/postgres/connection_test.rb +0 -63
- data/test/db/postgres/data_types_test.rb +0 -703
- data/test/db/postgres/hstore_test.rb +0 -200
- data/test/db/postgres/information_schema_leak_test.rb +0 -30
- data/test/db/postgres/json_test.rb +0 -86
- data/test/db/postgres/ltree_test.rb +0 -51
- data/test/db/postgres/mixed_case_test.rb +0 -29
- data/test/db/postgres/native_types_test.rb +0 -124
- data/test/db/postgres/rake_test.rb +0 -117
- data/test/db/postgres/reserved_test.rb +0 -22
- data/test/db/postgres/reset_column_information_test.rb +0 -6
- data/test/db/postgres/row_locking_test.rb +0 -21
- data/test/db/postgres/schema_dump_test.rb +0 -95
- data/test/db/postgres/schema_test.rb +0 -115
- data/test/db/postgres/simple_test.rb +0 -260
- data/test/db/postgres/table_alias_length_test.rb +0 -16
- data/test/db/postgres/transaction_test.rb +0 -6
- data/test/db/postgres/unit_test.rb +0 -31
- data/test/db/postgres_config.rb +0 -10
- data/test/db/sqlite3.rb +0 -6
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +0 -6274
- data/test/db/sqlite3/has_many_though_test.rb +0 -6
- data/test/db/sqlite3/rake_test.rb +0 -71
- data/test/db/sqlite3/reset_column_information_test.rb +0 -6
- data/test/db/sqlite3/schema_dump_test.rb +0 -6
- data/test/db/sqlite3/serialize_test.rb +0 -6
- data/test/db/sqlite3/simple_test.rb +0 -268
- data/test/db/sqlite3/transaction_test.rb +0 -32
- data/test/db/sqlite3/type_conversion_test.rb +0 -104
- data/test/has_many_through.rb +0 -61
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc/db2.rb +0 -36
- data/test/jdbc/oracle.rb +0 -34
- data/test/jdbc_column_test.rb +0 -23
- data/test/jdbc_common.rb +0 -16
- data/test/jdbc_connection_test.rb +0 -196
- data/test/jndi_callbacks_test.rb +0 -33
- data/test/jndi_test.rb +0 -55
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -9
- data/test/models/auto_id.rb +0 -15
- data/test/models/binary.rb +0 -18
- data/test/models/custom_pk_name.rb +0 -15
- data/test/models/data_types.rb +0 -40
- data/test/models/entry.rb +0 -41
- data/test/models/mixed_case.rb +0 -22
- data/test/models/reserved_word.rb +0 -15
- data/test/models/rights_and_roles.rb +0 -57
- data/test/models/string_id.rb +0 -17
- data/test/models/thing.rb +0 -17
- data/test/models/topic.rb +0 -32
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/rails/mysql.rb +0 -13
- data/test/rails/sqlite3/version.rb +0 -6
- data/test/rails_stub.rb +0 -31
- data/test/rake_test_support.rb +0 -298
- data/test/row_locking.rb +0 -102
- data/test/schema_dump.rb +0 -182
- data/test/serialize.rb +0 -275
- data/test/shared_helper.rb +0 -35
- data/test/simple.rb +0 -1317
- data/test/sybase_jtds_simple_test.rb +0 -28
- data/test/sybase_reset_column_information_test.rb +0 -6
- data/test/test_helper.rb +0 -304
- data/test/transaction.rb +0 -109
@@ -14,8 +14,7 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
14
14
|
config[:driver] ||= defined?(::Jdbc::Postgres.driver_name) ? ::Jdbc::Postgres.driver_name : 'org.postgresql.Driver'
|
15
15
|
config[:adapter_spec] ||= ::ArJdbc::PostgreSQL
|
16
16
|
config[:adapter_class] = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter unless config.key?(:adapter_class)
|
17
|
-
|
18
|
-
|
17
|
+
|
19
18
|
jdbc_connection(config)
|
20
19
|
end
|
21
20
|
alias_method :jdbcpostgresql_connection, :postgresql_connection
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# NOTE: kindly borrowed from AR 4.0.0 (rc1) - only to be used on AR >= 4.0 !
|
2
|
+
module ArJdbc
|
3
|
+
module PostgreSQL
|
4
|
+
class SchemaCreation < ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def visit_AddColumn(o)
|
9
|
+
sql_type = type_to_sql(o.type.to_sym, o.limit, o.precision, o.scale)
|
10
|
+
sql = "ADD COLUMN #{quote_column_name(o.name)} #{sql_type}"
|
11
|
+
add_column_options!(sql, column_options(o))
|
12
|
+
end
|
13
|
+
|
14
|
+
def visit_ColumnDefinition(o)
|
15
|
+
sql = super
|
16
|
+
if o.primary_key? && o.type == :uuid
|
17
|
+
sql << " PRIMARY KEY "
|
18
|
+
add_column_options!(sql, column_options(o))
|
19
|
+
end
|
20
|
+
sql
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_column_options!(sql, options)
|
24
|
+
if options[:array] || options[:column].try(:array)
|
25
|
+
sql << '[]'
|
26
|
+
end
|
27
|
+
|
28
|
+
column = options.fetch(:column) { return super }
|
29
|
+
if column.type == :uuid && options[:default] =~ /\(\)/
|
30
|
+
sql << " DEFAULT #{options[:default]}"
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,22 +1,26 @@
|
|
1
1
|
ArJdbc.load_java_part :SQLite3
|
2
2
|
|
3
|
-
require 'arjdbc/jdbc/missing_functionality_helper'
|
4
3
|
require 'arjdbc/sqlite3/explain_support'
|
4
|
+
require 'arjdbc/util/table_copier'
|
5
5
|
|
6
6
|
module ArJdbc
|
7
7
|
module SQLite3
|
8
|
-
|
9
|
-
def self.column_selector
|
10
|
-
[ /sqlite/i, lambda { |cfg,col| col.extend(::ArJdbc::SQLite3::Column) } ]
|
11
|
-
end
|
8
|
+
include Util::TableCopier
|
12
9
|
|
10
|
+
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
|
13
11
|
def self.jdbc_connection_class
|
14
12
|
::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
|
15
13
|
end
|
16
|
-
|
14
|
+
|
15
|
+
# @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
|
16
|
+
def self.column_selector
|
17
|
+
[ /sqlite/i, lambda { |config, column| column.extend(Column) } ]
|
18
|
+
end
|
19
|
+
|
20
|
+
# @see ActiveRecord::ConnectionAdapters::JdbcColumn
|
17
21
|
module Column
|
18
|
-
|
19
|
-
#
|
22
|
+
|
23
|
+
# @override {ActiveRecord::ConnectionAdapters::JdbcColumn#init_column}
|
20
24
|
def init_column(name, default, *args)
|
21
25
|
if default =~ /NULL/
|
22
26
|
@default = nil
|
@@ -25,12 +29,20 @@ module ArJdbc
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
#
|
32
|
+
# @override {ActiveRecord::ConnectionAdapters::JdbcColumn#default_value}
|
33
|
+
def default_value(value)
|
34
|
+
# JDBC returns column default strings with actual single quotes :
|
35
|
+
return $1 if value =~ /^'(.*)'$/
|
36
|
+
|
37
|
+
value
|
38
|
+
end
|
39
|
+
|
40
|
+
# @override {ActiveRecord::ConnectionAdapters::Column#type_cast}
|
29
41
|
def type_cast(value)
|
30
42
|
return nil if value.nil?
|
31
43
|
case type
|
32
44
|
when :string then value
|
33
|
-
when :primary_key
|
45
|
+
when :primary_key
|
34
46
|
value.respond_to?(:to_i) ? value.to_i : ( value ? 1 : 0 )
|
35
47
|
when :float then value.to_f
|
36
48
|
when :decimal then self.class.value_to_decimal(value)
|
@@ -38,9 +50,10 @@ module ArJdbc
|
|
38
50
|
else super
|
39
51
|
end
|
40
52
|
end
|
41
|
-
|
53
|
+
|
42
54
|
private
|
43
|
-
|
55
|
+
|
56
|
+
# @override {ActiveRecord::ConnectionAdapters::Column#simplified_type}
|
44
57
|
def simplified_type(field_type)
|
45
58
|
case field_type
|
46
59
|
when /boolean/i then :boolean
|
@@ -58,6 +71,7 @@ module ArJdbc
|
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
74
|
+
# @override {ActiveRecord::ConnectionAdapters::Column#extract_limit}
|
61
75
|
def extract_limit(sql_type)
|
62
76
|
return nil if sql_type =~ /^(real)\(\d+/i
|
63
77
|
super
|
@@ -78,33 +92,22 @@ module ArJdbc
|
|
78
92
|
end
|
79
93
|
end
|
80
94
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
95
|
+
end
|
96
|
+
|
97
|
+
# @see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
|
98
|
+
def self.arel_visitor_type(config = nil)
|
99
|
+
::Arel::Visitors::SQLite
|
100
|
+
end
|
101
|
+
|
102
|
+
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#bind_substitution
|
103
|
+
# @private
|
104
|
+
class BindSubstitution < ::Arel::Visitors::SQLite
|
105
|
+
include ::Arel::Visitors::BindVisitor
|
106
|
+
end if defined? ::Arel::Visitors::BindVisitor
|
85
107
|
|
86
|
-
value
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.arel2_visitors(config = nil)
|
92
|
-
{ 'sqlite3' => ::Arel::Visitors::SQLite, 'jdbcsqlite3' => ::Arel::Visitors::SQLite }
|
93
|
-
end
|
94
|
-
|
95
|
-
def new_visitor(config = nil)
|
96
|
-
visitor = ::Arel::Visitors::SQLite
|
97
|
-
( prepared_statements? ? visitor : bind_substitution(visitor) ).new(self)
|
98
|
-
end if defined? ::Arel::Visitors::SQLite
|
99
|
-
|
100
|
-
# @see #bind_substitution
|
101
|
-
class BindSubstitution < Arel::Visitors::SQLite # :nodoc:
|
102
|
-
include Arel::Visitors::BindVisitor
|
103
|
-
end if defined? Arel::Visitors::BindVisitor
|
104
|
-
|
105
108
|
ADAPTER_NAME = 'SQLite'.freeze
|
106
|
-
|
107
|
-
def adapter_name
|
109
|
+
|
110
|
+
def adapter_name
|
108
111
|
ADAPTER_NAME
|
109
112
|
end
|
110
113
|
|
@@ -114,6 +117,7 @@ module ArJdbc
|
|
114
117
|
:text => { :name => "text" },
|
115
118
|
:integer => { :name => "integer" },
|
116
119
|
:float => { :name => "float" },
|
120
|
+
# :real => { :name=>"real" },
|
117
121
|
:decimal => { :name => "decimal" },
|
118
122
|
:datetime => { :name => "datetime" },
|
119
123
|
:timestamp => { :name => "datetime" },
|
@@ -123,18 +127,13 @@ module ArJdbc
|
|
123
127
|
:boolean => { :name => "boolean" }
|
124
128
|
}
|
125
129
|
|
130
|
+
# @override
|
126
131
|
def native_database_types
|
127
|
-
types =
|
132
|
+
types = NATIVE_DATABASE_TYPES.dup
|
128
133
|
types[:primary_key] = default_primary_key_type
|
129
134
|
types
|
130
135
|
end
|
131
136
|
|
132
|
-
def modify_types(types)
|
133
|
-
super(types)
|
134
|
-
types.merge! NATIVE_DATABASE_TYPES
|
135
|
-
types
|
136
|
-
end
|
137
|
-
|
138
137
|
def default_primary_key_type
|
139
138
|
if supports_autoincrement?
|
140
139
|
'integer PRIMARY KEY AUTOINCREMENT NOT NULL'
|
@@ -142,60 +141,73 @@ module ArJdbc
|
|
142
141
|
'integer PRIMARY KEY NOT NULL'
|
143
142
|
end
|
144
143
|
end
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
|
145
|
+
# @override
|
146
|
+
def supports_ddl_transactions?
|
147
|
+
true
|
148
148
|
end
|
149
|
-
|
150
|
-
|
149
|
+
|
150
|
+
# @override
|
151
|
+
def supports_savepoints?
|
151
152
|
sqlite_version >= '3.6.8'
|
152
153
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
154
|
+
|
155
|
+
# @override
|
156
|
+
def supports_add_column?
|
157
|
+
true
|
156
158
|
end
|
157
159
|
|
158
|
-
|
159
|
-
|
160
|
+
# @override
|
161
|
+
def supports_count_distinct?
|
162
|
+
true
|
160
163
|
end
|
161
164
|
|
162
|
-
|
163
|
-
|
165
|
+
# @override
|
166
|
+
def supports_autoincrement?
|
167
|
+
true
|
164
168
|
end
|
165
169
|
|
166
|
-
|
167
|
-
|
170
|
+
# @override
|
171
|
+
def supports_index_sort_order?
|
172
|
+
true
|
168
173
|
end
|
169
174
|
|
170
|
-
|
175
|
+
# @override
|
176
|
+
def supports_migrations?
|
171
177
|
true
|
172
178
|
end
|
173
179
|
|
174
|
-
|
180
|
+
# @override
|
181
|
+
def supports_primary_key?
|
175
182
|
true
|
176
183
|
end
|
177
184
|
|
178
|
-
|
185
|
+
# @override
|
186
|
+
def supports_add_column?
|
179
187
|
true
|
180
188
|
end
|
181
189
|
|
182
|
-
|
190
|
+
# @override
|
191
|
+
def supports_count_distinct?
|
183
192
|
true
|
184
193
|
end
|
185
194
|
|
186
|
-
|
195
|
+
# @override
|
196
|
+
def supports_autoincrement?
|
187
197
|
true
|
188
198
|
end
|
189
199
|
|
190
|
-
|
200
|
+
# @override
|
201
|
+
def supports_index_sort_order?
|
191
202
|
true
|
192
203
|
end
|
193
|
-
|
204
|
+
|
194
205
|
def sqlite_version
|
195
|
-
@sqlite_version ||= select_value('SELECT sqlite_version(*)')
|
206
|
+
@sqlite_version ||= Version.new(select_value('SELECT sqlite_version(*)'))
|
196
207
|
end
|
197
208
|
private :sqlite_version
|
198
|
-
|
209
|
+
|
210
|
+
# @override
|
199
211
|
def quote(value, column = nil)
|
200
212
|
if value.kind_of?(String)
|
201
213
|
column_type = column && column.type
|
@@ -211,29 +223,26 @@ module ArJdbc
|
|
211
223
|
|
212
224
|
def quote_table_name_for_assignment(table, attr)
|
213
225
|
quote_column_name(attr)
|
214
|
-
end if ::ActiveRecord::VERSION::MAJOR
|
215
|
-
|
216
|
-
|
226
|
+
end if ::ActiveRecord::VERSION::MAJOR >= 4
|
227
|
+
|
228
|
+
# @override
|
229
|
+
def quote_column_name(name)
|
217
230
|
%Q("#{name.to_s.gsub('"', '""')}") # "' kludge for emacs font-lock
|
218
231
|
end
|
219
232
|
|
220
|
-
# Quote date/time values for use in SQL input.
|
221
|
-
# if the value is a Time responding to usec.
|
222
|
-
|
223
|
-
|
233
|
+
# Quote date/time values for use in SQL input.
|
234
|
+
# Includes microseconds if the value is a Time responding to usec.
|
235
|
+
# @override
|
236
|
+
def quoted_date(value)
|
237
|
+
if value.acts_like?(:time) && value.respond_to?(:usec)
|
224
238
|
"#{super}.#{sprintf("%06d", value.usec)}"
|
225
239
|
else
|
226
240
|
super
|
227
241
|
end
|
228
|
-
end
|
229
|
-
|
230
|
-
#
|
231
|
-
def
|
232
|
-
execute(sql, name, binds)
|
233
|
-
id_value || last_insert_id
|
234
|
-
end
|
235
|
-
|
236
|
-
def tables(name = nil, table_name = nil) # :nodoc:
|
242
|
+
end if ::ActiveRecord::VERSION::MAJOR >= 3
|
243
|
+
|
244
|
+
# @override
|
245
|
+
def tables(name = nil, table_name = nil)
|
237
246
|
sql = "SELECT name FROM sqlite_master WHERE type = 'table'"
|
238
247
|
if table_name
|
239
248
|
sql << " AND name = #{quote_table_name(table_name)}"
|
@@ -244,41 +253,48 @@ module ArJdbc
|
|
244
253
|
select_rows(sql, name).map { |row| row[0] }
|
245
254
|
end
|
246
255
|
|
256
|
+
# @override
|
247
257
|
def table_exists?(table_name)
|
248
258
|
table_name && tables(nil, table_name).any?
|
249
259
|
end
|
250
|
-
|
251
|
-
# Returns 62. SQLite supports index names up to 64
|
252
|
-
#
|
253
|
-
#
|
260
|
+
|
261
|
+
# Returns 62. SQLite supports index names up to 64 characters.
|
262
|
+
# The rest is used by Rails internally to perform temporary rename operations.
|
263
|
+
# @return [Fixnum]
|
254
264
|
def allowed_index_name_length
|
255
265
|
index_name_length - 2
|
256
266
|
end
|
257
267
|
|
258
|
-
|
259
|
-
|
268
|
+
# @override
|
269
|
+
def create_savepoint(name = current_savepoint_name(true))
|
270
|
+
log("SAVEPOINT #{name}", 'Savepoint') { super }
|
260
271
|
end
|
261
272
|
|
262
|
-
|
263
|
-
|
273
|
+
# @override
|
274
|
+
def rollback_to_savepoint(name = current_savepoint_name)
|
275
|
+
log("ROLLBACK TO SAVEPOINT #{name}", 'Savepoint') { super }
|
264
276
|
end
|
265
277
|
|
266
|
-
|
267
|
-
|
278
|
+
# @override
|
279
|
+
def release_savepoint(name = current_savepoint_name)
|
280
|
+
log("RELEASE SAVEPOINT #{name}", 'Savepoint') { super }
|
268
281
|
end
|
269
|
-
|
270
|
-
|
282
|
+
|
283
|
+
# @private
|
284
|
+
def recreate_database(name = nil, options = {})
|
271
285
|
drop_database(name)
|
272
286
|
create_database(name, options)
|
273
287
|
end
|
274
|
-
|
275
|
-
|
288
|
+
|
289
|
+
# @private
|
290
|
+
def create_database(name = nil, options = {})
|
276
291
|
end
|
277
292
|
|
278
|
-
|
293
|
+
# @private
|
294
|
+
def drop_database(name = nil)
|
279
295
|
tables.each { |table| drop_table(table) }
|
280
296
|
end
|
281
|
-
|
297
|
+
|
282
298
|
def select(sql, name = nil, binds = [])
|
283
299
|
result = super # AR::Result (4.0) or Array (<= 3.2)
|
284
300
|
if result.respond_to?(:columns) # 4.0
|
@@ -299,11 +315,21 @@ module ArJdbc
|
|
299
315
|
result
|
300
316
|
end
|
301
317
|
|
302
|
-
# @
|
303
|
-
|
318
|
+
# @note We have an extra binds argument at the end due AR-2.3 support.
|
319
|
+
# @override
|
320
|
+
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
|
321
|
+
result = execute(sql, name, binds)
|
322
|
+
id_value || last_inserted_id(result)
|
323
|
+
end
|
324
|
+
|
325
|
+
# @note Does not support prepared statements for INSERT statements.
|
326
|
+
# @override
|
327
|
+
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
|
328
|
+
# NOTE: since SQLite JDBC does not support executeUpdate but only
|
329
|
+
# statement.execute we can not support prepared statements here :
|
304
330
|
execute(sql, name, binds)
|
305
331
|
end
|
306
|
-
|
332
|
+
|
307
333
|
def table_structure(table_name)
|
308
334
|
sql = "PRAGMA table_info(#{quote_table_name(table_name)})"
|
309
335
|
log(sql, 'SCHEMA') { @connection.execute_query_raw(sql) }
|
@@ -313,34 +339,38 @@ module ArJdbc
|
|
313
339
|
raise e
|
314
340
|
end
|
315
341
|
|
316
|
-
|
342
|
+
# @override
|
343
|
+
def columns(table_name, name = nil)
|
317
344
|
klass = ::ActiveRecord::ConnectionAdapters::SQLite3Column
|
318
345
|
table_structure(table_name).map do |field|
|
319
346
|
klass.new(field['name'], field['dflt_value'], field['type'], field['notnull'] == 0)
|
320
347
|
end
|
321
348
|
end
|
322
349
|
|
323
|
-
|
350
|
+
# @override
|
351
|
+
def primary_key(table_name)
|
324
352
|
column = table_structure(table_name).find { |field| field['pk'].to_i == 1 }
|
325
353
|
column && column['name']
|
326
354
|
end
|
327
355
|
|
328
|
-
|
356
|
+
# @override
|
357
|
+
def remove_index!(table_name, index_name)
|
329
358
|
execute "DROP INDEX #{quote_column_name(index_name)}"
|
330
359
|
end
|
331
360
|
|
361
|
+
# @override
|
332
362
|
def rename_table(table_name, new_name)
|
333
363
|
execute "ALTER TABLE #{quote_table_name(table_name)} RENAME TO #{quote_table_name(new_name)}"
|
334
364
|
rename_table_indexes(table_name, new_name) if respond_to?(:rename_table_indexes) # AR-4.0 SchemaStatements
|
335
365
|
end
|
336
366
|
|
337
|
-
#
|
338
|
-
#
|
367
|
+
# SQLite has an additional restriction on the ALTER TABLE statement.
|
368
|
+
# @see http://www.sqlite.org/lang_altertable.html
|
339
369
|
def valid_alter_table_options( type, options)
|
340
370
|
type.to_sym != :primary_key
|
341
371
|
end
|
342
372
|
|
343
|
-
def add_column(table_name, column_name, type, options = {})
|
373
|
+
def add_column(table_name, column_name, type, options = {})
|
344
374
|
if supports_add_column? && valid_alter_table_options( type, options )
|
345
375
|
super(table_name, column_name, type, options)
|
346
376
|
else
|
@@ -351,19 +381,21 @@ module ArJdbc
|
|
351
381
|
end
|
352
382
|
|
353
383
|
if ActiveRecord::VERSION::MAJOR >= 4
|
354
|
-
|
355
|
-
|
384
|
+
|
385
|
+
# @private
|
386
|
+
def remove_column(table_name, column_name, type = nil, options = {})
|
356
387
|
alter_table(table_name) do |definition|
|
357
388
|
definition.remove_column column_name
|
358
389
|
end
|
359
390
|
end
|
360
|
-
|
391
|
+
|
361
392
|
else
|
362
|
-
|
363
|
-
|
393
|
+
|
394
|
+
# @private
|
395
|
+
def remove_column(table_name, *column_names)
|
364
396
|
if column_names.empty?
|
365
397
|
raise ArgumentError.new(
|
366
|
-
"You must specify at least one column name." +
|
398
|
+
"You must specify at least one column name." +
|
367
399
|
" Example: remove_column(:people, :first_name)"
|
368
400
|
)
|
369
401
|
end
|
@@ -374,9 +406,9 @@ module ArJdbc
|
|
374
406
|
end
|
375
407
|
end
|
376
408
|
alias :remove_columns :remove_column
|
377
|
-
|
409
|
+
|
378
410
|
end
|
379
|
-
|
411
|
+
|
380
412
|
def change_column_default(table_name, column_name, default) #:nodoc:
|
381
413
|
alter_table(table_name) do |definition|
|
382
414
|
definition[column_name].default = default
|
@@ -392,7 +424,7 @@ module ArJdbc
|
|
392
424
|
end
|
393
425
|
end
|
394
426
|
|
395
|
-
def change_column(table_name, column_name, type, options = {})
|
427
|
+
def change_column(table_name, column_name, type, options = {})
|
396
428
|
alter_table(table_name) do |definition|
|
397
429
|
include_default = options_include_default?(options)
|
398
430
|
definition[column_name].instance_eval do
|
@@ -406,7 +438,7 @@ module ArJdbc
|
|
406
438
|
end
|
407
439
|
end
|
408
440
|
|
409
|
-
def rename_column(table_name, column_name, new_column_name)
|
441
|
+
def rename_column(table_name, column_name, new_column_name)
|
410
442
|
unless columns(table_name).detect{|c| c.name == column_name.to_s }
|
411
443
|
raise ActiveRecord::ActiveRecordError, "Missing column #{table_name}.#{column_name}"
|
412
444
|
end
|
@@ -414,10 +446,10 @@ module ArJdbc
|
|
414
446
|
rename_column_indexes(table_name, column_name, new_column_name) if respond_to?(:rename_column_indexes) # AR-4.0 SchemaStatements
|
415
447
|
end
|
416
448
|
|
417
|
-
|
418
|
-
def add_lock!(sql, options)
|
419
|
-
sql
|
420
|
-
end
|
449
|
+
# @private
|
450
|
+
def add_lock!(sql, options)
|
451
|
+
sql # SELECT ... FOR UPDATE is redundant since the table is locked
|
452
|
+
end if ::ActiveRecord::VERSION::MAJOR < 3
|
421
453
|
|
422
454
|
def empty_insert_statement_value
|
423
455
|
# inherited (default) on 3.2 : "VALUES(DEFAULT)"
|
@@ -426,14 +458,20 @@ module ArJdbc
|
|
426
458
|
# on 4.0 no longer re-defined (thus inherits default)
|
427
459
|
"DEFAULT VALUES"
|
428
460
|
end
|
429
|
-
|
461
|
+
|
430
462
|
def encoding
|
431
463
|
select_value 'PRAGMA encoding'
|
432
464
|
end
|
433
|
-
|
465
|
+
|
466
|
+
def last_insert_id
|
467
|
+
@connection.last_insert_rowid
|
468
|
+
end
|
469
|
+
|
434
470
|
protected
|
435
|
-
|
436
|
-
|
471
|
+
|
472
|
+
def last_inserted_id(result)
|
473
|
+
super || last_insert_id # NOTE: #last_insert_id call should not be needed
|
474
|
+
end
|
437
475
|
|
438
476
|
def translate_exception(exception, message)
|
439
477
|
case exception.message
|
@@ -444,21 +482,24 @@ module ArJdbc
|
|
444
482
|
end
|
445
483
|
end
|
446
484
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
485
|
+
# @private available in native adapter way back to AR-2.3
|
486
|
+
class Version
|
487
|
+
include Comparable
|
488
|
+
|
489
|
+
def initialize(version_string)
|
490
|
+
@version = version_string.split('.').map! { |v| v.to_i }
|
491
|
+
end
|
492
|
+
|
493
|
+
def <=>(version_string)
|
494
|
+
@version <=> version_string.split('.').map! { |v| v.to_i }
|
495
|
+
end
|
496
|
+
|
497
|
+
def to_s
|
498
|
+
@version
|
499
|
+
end
|
500
|
+
|
460
501
|
end
|
461
|
-
|
502
|
+
|
462
503
|
end
|
463
504
|
end
|
464
505
|
|
@@ -466,7 +507,7 @@ module ActiveRecord::ConnectionAdapters
|
|
466
507
|
|
467
508
|
# NOTE: SQLite3Column exists in native adapter since AR 4.0
|
468
509
|
remove_const(:SQLite3Column) if const_defined?(:SQLite3Column)
|
469
|
-
|
510
|
+
|
470
511
|
class SQLite3Column < JdbcColumn
|
471
512
|
include ArJdbc::SQLite3::Column
|
472
513
|
|
@@ -489,9 +530,9 @@ module ActiveRecord::ConnectionAdapters
|
|
489
530
|
value
|
490
531
|
end
|
491
532
|
end
|
492
|
-
|
533
|
+
|
493
534
|
remove_const(:SQLite3Adapter) if const_defined?(:SQLite3Adapter)
|
494
|
-
|
535
|
+
|
495
536
|
class SQLite3Adapter < JdbcAdapter
|
496
537
|
include ArJdbc::SQLite3
|
497
538
|
include ArJdbc::SQLite3::ExplainSupport
|
@@ -503,13 +544,16 @@ module ActiveRecord::ConnectionAdapters
|
|
503
544
|
def jdbc_column_class
|
504
545
|
::ActiveRecord::ConnectionAdapters::SQLite3Column
|
505
546
|
end
|
506
|
-
|
547
|
+
|
548
|
+
# @private
|
549
|
+
Version = ArJdbc::SQLite3::Version
|
550
|
+
|
507
551
|
end
|
508
552
|
|
509
553
|
if ActiveRecord::VERSION::MAJOR <= 3
|
510
554
|
remove_const(:SQLiteColumn) if const_defined?(:SQLiteColumn)
|
511
555
|
SQLiteColumn = SQLite3Column
|
512
|
-
|
556
|
+
|
513
557
|
remove_const(:SQLiteAdapter) if const_defined?(:SQLiteAdapter)
|
514
558
|
|
515
559
|
SQLiteAdapter = SQLite3Adapter
|