activerecord-jdbc-adapter 1.2.5 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +5 -1
- data/Appraisals +5 -5
- data/Gemfile +9 -1
- data/Gemfile.lock +44 -10
- data/History.txt +126 -2
- data/README.md +246 -0
- data/Rakefile +34 -25
- data/activerecord-jdbc-adapter.gemspec +1 -1
- data/gemfiles/rails23.gemfile +5 -3
- data/gemfiles/rails23.gemfile.lock +26 -18
- data/gemfiles/rails30.gemfile +4 -2
- data/gemfiles/rails30.gemfile.lock +16 -8
- data/gemfiles/rails31.gemfile +4 -2
- data/gemfiles/rails31.gemfile.lock +16 -9
- data/gemfiles/rails32.gemfile +4 -2
- data/gemfiles/rails32.gemfile.lock +15 -8
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/arel/visitors/sql_server.rb +3 -0
- data/lib/arjdbc.rb +3 -5
- data/lib/arjdbc/db2.rb +1 -0
- data/lib/arjdbc/db2/adapter.rb +302 -196
- data/lib/arjdbc/db2/connection_methods.rb +18 -0
- data/lib/arjdbc/derby/active_record_patch.rb +12 -0
- data/lib/arjdbc/derby/adapter.rb +180 -158
- data/lib/arjdbc/derby/connection_methods.rb +5 -1
- data/lib/arjdbc/firebird/adapter.rb +27 -19
- data/lib/arjdbc/h2/adapter.rb +162 -7
- data/lib/arjdbc/h2/connection_methods.rb +5 -1
- data/lib/arjdbc/hsqldb.rb +1 -1
- data/lib/arjdbc/hsqldb/adapter.rb +96 -61
- data/lib/arjdbc/hsqldb/connection_methods.rb +5 -1
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/informix/adapter.rb +56 -55
- data/lib/arjdbc/jdbc/adapter.rb +173 -86
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/column.rb +28 -23
- data/lib/arjdbc/jdbc/connection.rb +10 -6
- data/lib/arjdbc/jdbc/driver.rb +13 -5
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +21 -0
- data/lib/arjdbc/mssql.rb +1 -1
- data/lib/arjdbc/mssql/adapter.rb +51 -53
- data/lib/arjdbc/mssql/connection_methods.rb +8 -1
- data/lib/arjdbc/mysql.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +186 -150
- data/lib/arjdbc/mysql/connection_methods.rb +9 -9
- data/lib/arjdbc/mysql/explain_support.rb +85 -0
- data/lib/arjdbc/oracle.rb +1 -1
- data/lib/arjdbc/oracle/adapter.rb +232 -125
- data/lib/arjdbc/oracle/connection_methods.rb +2 -2
- data/lib/arjdbc/postgresql.rb +1 -1
- data/lib/arjdbc/postgresql/adapter.rb +134 -86
- data/lib/arjdbc/postgresql/connection_methods.rb +6 -4
- data/lib/arjdbc/postgresql/explain_support.rb +55 -0
- data/lib/arjdbc/sqlite3.rb +1 -1
- data/lib/arjdbc/sqlite3/adapter.rb +176 -108
- data/lib/arjdbc/sqlite3/connection_methods.rb +5 -5
- data/lib/arjdbc/sqlite3/explain_support.rb +32 -0
- data/lib/arjdbc/sybase/adapter.rb +7 -6
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +1 -1
- data/rakelib/02-test.rake +9 -11
- data/rakelib/rails.rake +18 -10
- data/src/java/arjdbc/db2/DB2Module.java +70 -0
- data/src/java/arjdbc/derby/DerbyModule.java +24 -5
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +66 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +14 -7
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +111 -89
- data/src/java/arjdbc/mysql/MySQLModule.java +79 -70
- data/src/java/arjdbc/oracle/OracleModule.java +74 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +5 -10
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +77 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +25 -111
- data/src/java/arjdbc/util/QuotingUtils.java +104 -0
- data/test/abstract_db_create.rb +6 -6
- data/test/activerecord/connection_adapters/type_conversion_test.rb +2 -2
- data/test/assets/flowers.jpg +0 -0
- data/test/binary.rb +67 -0
- data/test/db/db2.rb +30 -7
- data/test/db/jdbc.rb +4 -2
- data/test/db/oracle.rb +18 -27
- data/test/db2_binary_test.rb +6 -0
- data/test/db2_serialize_test.rb +6 -0
- data/test/db2_simple_test.rb +20 -25
- data/test/db2_test.rb +71 -0
- data/test/derby_binary_test.rb +6 -0
- data/test/derby_migration_test.rb +42 -35
- data/test/derby_reset_column_information_test.rb +1 -0
- data/test/derby_row_locking_test.rb +17 -0
- data/test/derby_schema_dump_test.rb +9 -0
- data/test/derby_serialize_test.rb +6 -0
- data/test/derby_simple_test.rb +59 -17
- data/test/generic_jdbc_connection_test.rb +112 -5
- data/test/h2_binary_test.rb +6 -0
- data/test/h2_change_column_test.rb +1 -1
- data/test/h2_schema_dump_test.rb +25 -0
- data/test/h2_serialize_test.rb +6 -0
- data/test/h2_simple_test.rb +23 -9
- data/test/has_many_through.rb +18 -4
- data/test/hsqldb_binary_test.rb +6 -0
- data/test/hsqldb_schema_dump_test.rb +15 -0
- data/test/hsqldb_serialize_test.rb +6 -0
- data/test/hsqldb_simple_test.rb +1 -0
- data/test/informix_simple_test.rb +1 -1
- data/test/jdbc/db2.rb +23 -0
- data/test/jdbc/oracle.rb +23 -0
- data/test/jdbc_common.rb +3 -110
- data/test/jndi_callbacks_test.rb +0 -2
- data/test/jndi_test.rb +2 -0
- data/test/models/binary.rb +18 -0
- data/test/models/custom_pk_name.rb +1 -0
- data/test/models/data_types.rb +11 -2
- data/test/models/entry.rb +1 -1
- data/test/models/string_id.rb +2 -2
- data/test/models/thing.rb +1 -1
- data/test/models/topic.rb +32 -0
- data/test/mssql_legacy_types_test.rb +1 -1
- data/test/mssql_limit_offset_test.rb +13 -3
- data/test/mssql_serialize_test.rb +6 -0
- data/test/mysql_binary_test.rb +6 -0
- data/test/mysql_schema_dump_test.rb +220 -0
- data/test/mysql_serialize_test.rb +6 -0
- data/test/mysql_simple_test.rb +22 -2
- data/test/mysql_test.rb +93 -0
- data/test/oracle_binary_test.rb +6 -0
- data/test/oracle_limit_test.rb +2 -1
- data/test/oracle_serialize_test.rb +6 -0
- data/test/oracle_simple_test.rb +61 -0
- data/test/oracle_specific_test.rb +77 -26
- data/test/postgres_binary_test.rb +6 -0
- data/test/postgres_native_type_mapping_test.rb +12 -11
- data/test/postgres_nonseq_pkey_test.rb +1 -0
- data/test/postgres_reserved_test.rb +1 -0
- data/test/postgres_reset_column_information_test.rb +1 -0
- data/test/postgres_row_locking_test.rb +21 -0
- data/test/postgres_schema_dump_test.rb +88 -0
- data/test/postgres_schema_search_path_test.rb +1 -0
- data/test/postgres_simple_test.rb +62 -89
- data/test/postgres_table_alias_length_test.rb +1 -0
- data/test/postgres_test.rb +31 -0
- data/test/postgres_type_conversion_test.rb +16 -16
- data/test/row_locking.rb +69 -64
- data/test/schema_dump.rb +168 -0
- data/test/serialize.rb +277 -0
- data/test/simple.rb +326 -122
- data/test/sqlite3_serialize_test.rb +6 -0
- data/test/sqlite3_simple_test.rb +51 -84
- data/test/sqlite3_type_conversion_test.rb +101 -0
- data/test/test_helper.rb +224 -0
- metadata +325 -366
- data/README.rdoc +0 -214
- data/test/db/logger.rb +0 -3
- data/test/derby_multibyte_test.rb +0 -11
- data/test/mysql_info_test.rb +0 -123
data/test/oracle_limit_test.rb
CHANGED
data/test/oracle_simple_test.rb
CHANGED
@@ -15,4 +15,65 @@ class OracleSimpleTest < Test::Unit::TestCase
|
|
15
15
|
assert e1.id != e2.id
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def test_find_by_sql_WITH_statement
|
20
|
+
user = User.create! :login => 'ferko'
|
21
|
+
Entry.create! :title => 'aaa', :user_id => user.id
|
22
|
+
entries = Entry.find_by_sql '' +
|
23
|
+
' WITH EntryLogin (title, login) AS ' +
|
24
|
+
' ( ' +
|
25
|
+
' SELECT e.title, u.login ' +
|
26
|
+
' FROM entries e INNER JOIN users u ON e.user_id = u.id ' +
|
27
|
+
' ) ' +
|
28
|
+
' ' +
|
29
|
+
' SELECT * FROM EntryLogin ORDER BY title ASC '
|
30
|
+
assert entries.first
|
31
|
+
assert entries.first.title
|
32
|
+
assert entries.first.login
|
33
|
+
end
|
34
|
+
|
35
|
+
include ExplainSupportTestMethods if ar_version("3.1")
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def assert_empty_string value
|
40
|
+
# An empty string is treated as a null value in Oracle :
|
41
|
+
# http://www.techonthenet.com/oracle/questions/empty_null.php
|
42
|
+
assert_equal nil, value
|
43
|
+
end
|
44
|
+
|
45
|
+
def assert_null_text value
|
46
|
+
# Oracle adapter initializes all CLOB fields with empty_clob()
|
47
|
+
# fn, so they all have a initial value of an empty string ''
|
48
|
+
assert_equal '', value
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_date_equal expected, actual
|
52
|
+
# Oracle doesn't distinguish btw date/datetime
|
53
|
+
assert_equal expected, actual.to_date
|
54
|
+
end
|
55
|
+
|
56
|
+
def assert_date_type(value)
|
57
|
+
# NOTE: no support for bare Date type in Oracle :
|
58
|
+
assert_instance_of Date, value.to_date
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class OracleMultibyteTest < Test::Unit::TestCase
|
64
|
+
include MultibyteTestMethods
|
65
|
+
|
66
|
+
def self.startup
|
67
|
+
super
|
68
|
+
MigrationSetup.setup!
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.shutdown
|
72
|
+
MigrationSetup.teardown!
|
73
|
+
super
|
74
|
+
end
|
75
|
+
|
76
|
+
def setup!; end # MigrationSetup#setup!
|
77
|
+
def teardown!; end # MigrationSetup#teardown!
|
78
|
+
|
18
79
|
end
|
@@ -1,40 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
1
2
|
require 'jdbc_common'
|
2
3
|
require 'db/oracle'
|
3
4
|
|
4
|
-
class DefaultNumber < ActiveRecord::Base
|
5
|
-
end
|
6
|
-
|
7
5
|
class OracleSpecificTest < Test::Unit::TestCase
|
8
|
-
include
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
include MigrationSetup
|
7
|
+
|
8
|
+
@@java_connection = nil
|
9
|
+
|
10
|
+
def self.startup
|
11
|
+
config = ActiveRecord::Base.connection.config
|
12
|
+
jdbc_driver = ActiveRecord::ConnectionAdapters::JdbcDriver.new(config[:driver])
|
13
|
+
@@java_connection = jdbc_driver.connection(config[:url], config[:username], config[:password])
|
14
|
+
@@java_connection.setAutoCommit(true)
|
15
|
+
|
16
|
+
java_connection = @@java_connection
|
17
|
+
java_connection.createStatement.execute "
|
13
18
|
CREATE TABLE DEFAULT_NUMBERS (
|
14
|
-
|
19
|
+
ID INTEGER NOT NULL PRIMARY KEY, VALUE NUMBER, DATUM DATE, FPOINT NUMBER(10,2), VALUE2 NUMBER(15)
|
15
20
|
)"
|
16
|
-
|
21
|
+
java_connection.createStatement.execute "
|
17
22
|
INSERT INTO DEFAULT_NUMBERS (ID, VALUE, DATUM, FPOINT, VALUE2)
|
18
|
-
|
19
|
-
|
23
|
+
VALUES (1, 0.076, TIMESTAMP'2009-11-05 00:00:00', 1000.01, 1234)"
|
24
|
+
java_connection.createStatement.execute "CREATE SYNONYM POSTS FOR ENTRIES"
|
25
|
+
|
26
|
+
MigrationSetup.setup!
|
20
27
|
end
|
21
28
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
29
|
+
def self.shutdown
|
30
|
+
MigrationSetup.teardown!
|
31
|
+
|
32
|
+
java_connection = @@java_connection
|
33
|
+
java_connection.createStatement.execute "DROP TABLE DEFAULT_NUMBERS"
|
34
|
+
java_connection.createStatement.execute "DROP SYNONYM POSTS"
|
35
|
+
|
36
|
+
@@java_connection.close
|
25
37
|
super
|
26
38
|
end
|
27
39
|
|
40
|
+
def setup! # MigrationSetup#setup!
|
41
|
+
# speedup by creating tables once only on startup !
|
42
|
+
# before: Finished in 174.545 seconds.
|
43
|
+
# after: Finished in 22.504 seconds.
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown! # MigrationSetup#teardown!
|
47
|
+
# speedup by creating tables once only on startup !
|
48
|
+
end
|
49
|
+
|
50
|
+
class DefaultNumber < ActiveRecord::Base; end
|
51
|
+
|
28
52
|
def test_default_number_precision
|
29
|
-
assert_equal 0.076, DefaultNumber.
|
53
|
+
assert_equal 0.076, DefaultNumber.first.value
|
30
54
|
end
|
31
55
|
|
32
56
|
def test_number_with_precision_and_scale
|
33
|
-
assert_equal 1000.01, DefaultNumber.
|
57
|
+
assert_equal 1000.01, DefaultNumber.first.fpoint
|
34
58
|
end
|
35
59
|
|
36
60
|
def test_number_with_precision
|
37
|
-
assert_equal 1234, DefaultNumber.
|
61
|
+
assert_equal 1234, DefaultNumber.first.value2
|
38
62
|
end
|
39
63
|
|
40
64
|
def test_number_type_with_precision_and_scale_is_reported_correctly
|
@@ -45,39 +69,66 @@ class OracleSpecificTest < Test::Unit::TestCase
|
|
45
69
|
|
46
70
|
# JRUBY-3675, ACTIVERECORD_JDBC-22
|
47
71
|
def test_load_date
|
48
|
-
obj = DefaultNumber.
|
72
|
+
obj = DefaultNumber.first
|
49
73
|
assert_not_nil obj.datum, "no date"
|
50
74
|
end
|
51
75
|
|
52
76
|
# ACTIVERECORD_JDBC-127
|
53
77
|
def test_save_date
|
54
|
-
obj = DefaultNumber.
|
78
|
+
obj = DefaultNumber.first
|
55
79
|
obj.datum = '01Jan2010'
|
56
80
|
obj.save!
|
57
81
|
end
|
58
82
|
|
59
83
|
def test_save_timestamp
|
60
|
-
obj = DefaultNumber.
|
84
|
+
obj = DefaultNumber.first
|
61
85
|
obj.datum = Time.now
|
62
86
|
obj.save!
|
63
87
|
end
|
64
88
|
|
65
89
|
def test_load_null_date
|
66
|
-
|
67
|
-
obj = DefaultNumber.
|
90
|
+
java_connection.createStatement.execute "UPDATE DEFAULT_NUMBERS SET DATUM = NULL"
|
91
|
+
obj = DefaultNumber.first
|
68
92
|
assert obj.datum.nil?
|
69
93
|
end
|
70
94
|
|
71
95
|
def test_model_access_by_synonym
|
72
96
|
@klass = Class.new(ActiveRecord::Base)
|
73
|
-
@klass.table_name = "POSTS"
|
97
|
+
@klass.table_name = "POSTS" # alias
|
74
98
|
entry_columns = Entry.columns_hash
|
75
99
|
@klass.columns.each do |c|
|
76
|
-
ec = entry_columns[c.name]
|
77
|
-
assert ec
|
100
|
+
assert ec = entry_columns[c.name]
|
78
101
|
assert_equal ec.sql_type, c.sql_type
|
79
102
|
assert_equal ec.type, c.type
|
80
103
|
end
|
81
104
|
end
|
82
105
|
|
106
|
+
#
|
107
|
+
|
108
|
+
def test_oracle_identifier_lengths
|
109
|
+
assert_equal 30, connection.table_alias_length
|
110
|
+
assert_equal 30, connection.table_name_length
|
111
|
+
assert_equal 30, connection.index_name_length
|
112
|
+
assert_equal 30, connection.column_name_length
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_current_user
|
116
|
+
puts "ORA current_user: #{connection.current_user}"
|
117
|
+
assert_instance_of String, connection.current_user
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_current_database
|
121
|
+
puts "ORA current_database: #{connection.current_database}"
|
122
|
+
assert_instance_of String, connection.current_database
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_current_schema
|
126
|
+
puts "ORA current_schema: #{connection.current_schema}"
|
127
|
+
assert_instance_of String, connection.current_schema
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def java_connection; @@java_connection; end
|
133
|
+
|
83
134
|
end if defined?(JRUBY_VERSION)
|
@@ -1,21 +1,22 @@
|
|
1
1
|
require 'jdbc_common'
|
2
|
+
require 'db/postgres'
|
2
3
|
|
3
4
|
class CreateNativeTypeMappingTestSchema < ActiveRecord::Migration
|
4
5
|
def self.up
|
5
6
|
execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
|
6
7
|
execute "CREATE SEQUENCE seq_pk_customers"
|
7
8
|
columns = [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
"bigint_serial_should_be_integer bigint default nextval('seq_pk_customers')",
|
10
|
+
"integer_serial_should_be_integer integer default nextval('seq_pk_customers')",
|
11
|
+
"varchar_should_be_string varchar(2)",
|
12
|
+
"timestamp_should_be_datetime timestamp",
|
13
|
+
"bytea_should_be_binary bytea",
|
14
|
+
"double_precision_should_be_float double precision",
|
15
|
+
"real_should_be_float real",
|
16
|
+
"bool_should_be_boolean bool",
|
17
|
+
"interval_should_be_string interval",
|
18
|
+
"bigint_should_be_integer bigint"
|
19
|
+
]
|
19
20
|
columns << "uuid_should_be_string uuid" if PG_VERSION >= 80300
|
20
21
|
table_sql = %Q{
|
21
22
|
CREATE TABLE customers (
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres'
|
3
|
+
require 'row_locking'
|
4
|
+
|
5
|
+
class PostgresRowLockingTest < Test::Unit::TestCase
|
6
|
+
include MigrationSetup
|
7
|
+
include RowLockingTestMethods
|
8
|
+
|
9
|
+
def self.startup
|
10
|
+
MigrationSetup.setup!
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup!; nil; end
|
14
|
+
|
15
|
+
def self.shutdown
|
16
|
+
MigrationSetup.teardown!
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown!; nil; end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'db/postgres'
|
2
|
+
require 'schema_dump'
|
3
|
+
|
4
|
+
class PostgresSchemaDumpTest < Test::Unit::TestCase
|
5
|
+
include SchemaDumpTestMethods
|
6
|
+
|
7
|
+
def self.startup
|
8
|
+
super
|
9
|
+
MigrationSetup.setup!
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.shutdown
|
13
|
+
MigrationSetup.teardown!
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup!; end # MigrationSetup#setup!
|
18
|
+
def teardown!; end # MigrationSetup#teardown!
|
19
|
+
|
20
|
+
def test_schema_dump_includes_xml_shorthand_definition
|
21
|
+
output = standard_dump
|
22
|
+
if %r{create_table "postgresql_xml_data_type"} =~ output
|
23
|
+
assert_match %r{t.xml "data"}, output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_schema_dump_includes_tsvector_shorthand_definition
|
28
|
+
output = standard_dump
|
29
|
+
if %r{create_table "postgresql_tsvectors"} =~ output
|
30
|
+
assert_match %r{t.tsvector "text_vector"}, output
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
|
36
|
+
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
|
37
|
+
def test_schema_dump_should_not_have_limits_on_boolean
|
38
|
+
dump = dump_with_data_types
|
39
|
+
lines = dump.lines.grep(/boolean/)
|
40
|
+
assert ! lines.empty?, "no boolean type definition found in: #{dump}"
|
41
|
+
lines.each {|line| assert line !~ /limit/ }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_schema_dump_should_not_have_limits_on_binaries
|
45
|
+
dump = dump_with_data_types
|
46
|
+
lines = dump.lines.grep(/binary/)
|
47
|
+
assert ! lines.empty?, "no binary type definitions found in: #{dump}"
|
48
|
+
lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
|
49
|
+
end
|
50
|
+
|
51
|
+
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
|
52
|
+
def test_schema_dump_should_not_have_limits_on_text_or_date
|
53
|
+
dump = dump_with_data_types
|
54
|
+
lines = dump.lines.grep(/date|text/)
|
55
|
+
assert ! lines.empty?
|
56
|
+
lines.each {|line| assert line !~ /limit/ }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_schema_dump_integer_with_no_limit_should_have_no_limit
|
60
|
+
dump = dump_with_data_types
|
61
|
+
lines = dump.lines.grep(/sample_integer_no_limit/)
|
62
|
+
assert ! lines.empty?
|
63
|
+
lines.each {|line| assert line !~ /:limit/ }
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_schema_dump_integer_with_limit_2_should_have_limit_2
|
67
|
+
dump = dump_with_data_types
|
68
|
+
lines = dump.lines.grep(/sample_integer_with_limit_2/)
|
69
|
+
assert ! lines.empty?
|
70
|
+
lines.each {|line| assert line =~ /limit => 2/ }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_schema_dump_integer_with_limit_8_should_have_limit_8
|
74
|
+
dump = dump_with_data_types
|
75
|
+
lines = dump.lines.grep(/sample_integer_with_limit_8/)
|
76
|
+
assert ! lines.empty?
|
77
|
+
lines.each {|line| assert line =~ /limit => 8/ }
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def dump_with_data_types(io = StringIO.new)
|
83
|
+
ActiveRecord::SchemaDumper.ignore_tables = [/^[^d]/] # keep data_types
|
84
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io)
|
85
|
+
io.string
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -5,69 +5,77 @@
|
|
5
5
|
#
|
6
6
|
|
7
7
|
require 'jdbc_common'
|
8
|
+
require 'db/postgres'
|
8
9
|
|
9
10
|
class PostgresSimpleTest < Test::Unit::TestCase
|
10
11
|
include SimpleTestMethods
|
11
12
|
include ActiveRecord3TestMethods
|
12
13
|
include ColumnNameQuotingTests
|
14
|
+
include XmlColumnTests
|
13
15
|
|
14
16
|
def test_adapter_class_name_equals_native_adapter_class_name
|
15
|
-
classname =
|
17
|
+
classname = connection.class.name[/[^:]*$/]
|
16
18
|
assert_equal 'PostgreSQLAdapter', classname
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_schema_search_path
|
20
|
-
assert_equal
|
22
|
+
assert_equal connection.schema_search_path, "\"$user\",public"
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_current_schema
|
24
|
-
assert_equal
|
26
|
+
assert_equal connection.current_schema, "public"
|
25
27
|
end
|
26
28
|
|
27
29
|
def test_encoding
|
28
|
-
assert_not_nil
|
30
|
+
assert_not_nil connection.encoding
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_multi_statement_support
|
32
|
-
results =
|
34
|
+
results = connection.execute "SELECT title from entries; SELECT login from users"
|
33
35
|
assert_equal 2, results.length
|
34
36
|
assert_equal ["title"], results[0].first.keys
|
35
37
|
assert_equal ["login"], results[1].first.keys
|
36
38
|
end
|
37
39
|
|
40
|
+
def test_find_by_sql_WITH_statement
|
41
|
+
user = User.create! :login => 'ferko'
|
42
|
+
Entry.create! :title => 'aaa', :user_id => user.id
|
43
|
+
entries = Entry.find_by_sql '' +
|
44
|
+
'( ' +
|
45
|
+
'WITH EntryAndUser (title, login, updated_on) AS ' +
|
46
|
+
' ( ' +
|
47
|
+
' SELECT e.title, u.login, e.updated_on ' +
|
48
|
+
' FROM entries e INNER JOIN users u ON e.user_id = u.id ' +
|
49
|
+
' ) ' +
|
50
|
+
'SELECT * FROM EntryAndUser ORDER BY title ASC ' +
|
51
|
+
') '
|
52
|
+
assert entries.first
|
53
|
+
assert entries.first.title
|
54
|
+
assert entries.first.login
|
55
|
+
end
|
56
|
+
|
38
57
|
def test_create_xml_column
|
39
58
|
return unless PG_VERSION >= 80300
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
xml_test = @connection.columns(:xml_testings).detect do
|
47
|
-
|c| c.name == "xml_test"
|
48
|
-
end
|
49
|
-
|
50
|
-
assert_equal "xml", xml_test.sql_type
|
51
|
-
ensure
|
52
|
-
@connection.drop_table :xml_testings rescue nil
|
53
|
-
end
|
54
|
-
|
59
|
+
super
|
60
|
+
end if ar_version('3.1')
|
61
|
+
def xml_sql_type; 'xml'; end
|
62
|
+
|
55
63
|
def test_create_table_with_limits
|
56
64
|
assert_nothing_raised do
|
57
|
-
|
65
|
+
connection.create_table :testings do |t|
|
58
66
|
t.column :eleven_int, :integer, :limit => 11
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
62
|
-
columns =
|
70
|
+
columns = connection.columns(:testings)
|
63
71
|
eleven = columns.detect { |c| c.name == "eleven_int" }
|
64
72
|
assert_equal "integer", eleven.sql_type
|
65
73
|
ensure
|
66
|
-
|
74
|
+
connection.drop_table :testings rescue nil
|
67
75
|
end
|
68
76
|
|
69
77
|
def test_supports_standard_conforming_string
|
70
|
-
assert([true, false].include?(
|
78
|
+
assert([true, false].include?(connection.supports_standard_conforming_strings?))
|
71
79
|
end
|
72
80
|
|
73
81
|
def test_standard_conforming_string_default_set_on_new_connections
|
@@ -76,34 +84,38 @@ class PostgresSimpleTest < Test::Unit::TestCase
|
|
76
84
|
end
|
77
85
|
|
78
86
|
def test_default_standard_conforming_string
|
79
|
-
if
|
80
|
-
assert_equal true,
|
87
|
+
if connection.supports_standard_conforming_strings?
|
88
|
+
assert_equal true, connection.standard_conforming_strings?
|
81
89
|
else
|
82
|
-
assert_equal false,
|
90
|
+
assert_equal false, connection.standard_conforming_strings?
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
94
|
def test_string_quoting_with_standard_conforming_strings
|
87
|
-
if
|
95
|
+
if connection.supports_standard_conforming_strings?
|
88
96
|
s = "\\m it's \\M"
|
89
|
-
assert_equal "'\\m it''s \\M'",
|
97
|
+
assert_equal "'\\m it''s \\M'", connection.quote(s)
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
93
101
|
def test_string_quoting_without_standard_conforming_strings
|
94
|
-
|
102
|
+
connection.standard_conforming_strings = false
|
95
103
|
s = "\\m it's \\M"
|
96
|
-
assert_equal "'\\\\m it''s \\\\M'",
|
97
|
-
|
104
|
+
assert_equal "'\\\\m it''s \\\\M'", connection.quote(s)
|
105
|
+
connection.standard_conforming_strings = true
|
98
106
|
end
|
107
|
+
|
108
|
+
include ExplainSupportTestMethods if ar_version("3.1")
|
109
|
+
|
99
110
|
end
|
100
111
|
|
101
112
|
class PostgresTimestampTest < Test::Unit::TestCase
|
102
|
-
|
113
|
+
|
114
|
+
def self.startup
|
103
115
|
DbTypeMigration.up
|
104
116
|
end
|
105
117
|
|
106
|
-
def
|
118
|
+
def self.shutdown
|
107
119
|
DbTypeMigration.down
|
108
120
|
end
|
109
121
|
|
@@ -128,19 +140,29 @@ class PostgresTimestampTest < Test::Unit::TestCase
|
|
128
140
|
|
129
141
|
def test_save_infinity_and_beyond
|
130
142
|
d = DbType.create!(:sample_timestamp => 1.0 / 0.0)
|
131
|
-
|
143
|
+
if ar_version('3.0')
|
144
|
+
assert_equal(1.0 / 0.0, d.sample_timestamp)
|
145
|
+
else # 2.3
|
146
|
+
assert_equal(nil, d.sample_timestamp)
|
147
|
+
end
|
132
148
|
|
133
149
|
e = DbType.create!(:sample_timestamp => -1.0 / 0.0)
|
134
|
-
|
150
|
+
if ar_version('3.0')
|
151
|
+
assert_equal(-1.0 / 0.0, e.sample_timestamp)
|
152
|
+
else # 2.3
|
153
|
+
assert_equal(nil, e.sample_timestamp)
|
154
|
+
end
|
135
155
|
end
|
156
|
+
|
136
157
|
end
|
137
158
|
|
138
159
|
class PostgresDeserializationTest < Test::Unit::TestCase
|
139
|
-
|
160
|
+
|
161
|
+
def self.startup
|
140
162
|
DbTypeMigration.up
|
141
163
|
end
|
142
164
|
|
143
|
-
def
|
165
|
+
def self.shutdown
|
144
166
|
DbTypeMigration.down
|
145
167
|
end
|
146
168
|
|
@@ -152,55 +174,6 @@ class PostgresDeserializationTest < Test::Unit::TestCase
|
|
152
174
|
end
|
153
175
|
end
|
154
176
|
|
155
|
-
class
|
156
|
-
|
157
|
-
DbTypeMigration.up
|
158
|
-
@connection = ActiveRecord::Base.connection
|
159
|
-
strio = StringIO.new
|
160
|
-
ActiveRecord::SchemaDumper::dump(ActiveRecord::Base.connection, strio)
|
161
|
-
@dump = strio.string
|
162
|
-
end
|
163
|
-
|
164
|
-
def teardown
|
165
|
-
DbTypeMigration.down
|
166
|
-
end
|
167
|
-
|
168
|
-
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
|
169
|
-
def test_schema_dump_should_not_have_limits_on_boolean
|
170
|
-
lines = @dump.lines.grep(/boolean/)
|
171
|
-
assert !lines.empty?
|
172
|
-
lines.each {|line| assert line !~ /limit/ }
|
173
|
-
end
|
174
|
-
|
175
|
-
|
176
|
-
def test_schema_dump_should_not_have_limits_on_binaries
|
177
|
-
lines = @dump.lines.grep(/binary/)
|
178
|
-
assert !lines.empty?, 'no binary type definitions found'
|
179
|
-
lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
|
180
|
-
end
|
181
|
-
|
182
|
-
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
|
183
|
-
def test_schema_dump_should_not_have_limits_on_text_or_date
|
184
|
-
lines = @dump.lines.grep(/date|text/)
|
185
|
-
assert !lines.empty?
|
186
|
-
lines.each {|line| assert line !~ /limit/ }
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_schema_dump_integer_with_no_limit_should_have_no_limit
|
190
|
-
lines = @dump.lines.grep(/sample_integer_no_limit/)
|
191
|
-
assert !lines.empty?
|
192
|
-
lines.each {|line| assert line !~ /:limit/ }
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_schema_dump_integer_with_limit_2_should_have_limit_2
|
196
|
-
lines = @dump.lines.grep(/sample_integer_with_limit_2/)
|
197
|
-
assert !lines.empty?
|
198
|
-
lines.each {|line| assert line =~ /limit => 2/ }
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_schema_dump_integer_with_limit_8_should_have_limit_8
|
202
|
-
lines = @dump.lines.grep(/sample_integer_with_limit_8/)
|
203
|
-
assert !lines.empty?
|
204
|
-
lines.each {|line| assert line =~ /limit => 8/ }
|
205
|
-
end
|
177
|
+
class PostgresHasManyThroughTest < Test::Unit::TestCase
|
178
|
+
include HasManyThroughMethods
|
206
179
|
end
|