activerecord-jdbc-adapter-onsite 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +22 -0
- data/.travis.yml +14 -0
- data/Appraisals +16 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/History.txt +488 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +214 -0
- data/Rakefile +62 -0
- data/activerecord-jdbc-adapter.gemspec +23 -0
- data/bench/bench_attributes.rb +13 -0
- data/bench/bench_attributes_new.rb +14 -0
- data/bench/bench_create.rb +12 -0
- data/bench/bench_find_all.rb +12 -0
- data/bench/bench_find_all_mt.rb +25 -0
- data/bench/bench_model.rb +85 -0
- data/bench/bench_new.rb +12 -0
- data/bench/bench_new_valid.rb +12 -0
- data/bench/bench_valid.rb +13 -0
- data/gemfiles/rails23.gemfile +10 -0
- data/gemfiles/rails23.gemfile.lock +38 -0
- data/gemfiles/rails30.gemfile +9 -0
- data/gemfiles/rails30.gemfile.lock +33 -0
- data/gemfiles/rails31.gemfile +9 -0
- data/gemfiles/rails31.gemfile.lock +35 -0
- data/gemfiles/rails32.gemfile +9 -0
- data/gemfiles/rails32.gemfile.lock +35 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +32 -0
- data/lib/arel/visitors/firebird.rb +24 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +46 -0
- data/lib/arjdbc.rb +24 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +541 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/derby/adapter.rb +358 -0
- data/lib/arjdbc/derby/connection_methods.rb +19 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/firebird/adapter.rb +140 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +54 -0
- data/lib/arjdbc/h2/connection_methods.rb +13 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/arjdbc/hsqldb/adapter.rb +184 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +15 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +142 -0
- data/lib/arjdbc/informix/connection_methods.rb +11 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +356 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +47 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +134 -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 +35 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/arjdbc/jdbc/jdbc.rake +131 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +88 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +477 -0
- data/lib/arjdbc/mssql/connection_methods.rb +31 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +101 -0
- data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
- data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +505 -0
- data/lib/arjdbc/mysql/connection_methods.rb +28 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/arjdbc/oracle/adapter.rb +432 -0
- data/lib/arjdbc/oracle/connection_methods.rb +12 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +861 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +23 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +389 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +35 -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/generators/jdbc/USAGE +10 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/pom.xml +57 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/db.rake +39 -0
- data/rakelib/rails.rake +41 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +69 -0
- data/src/java/arjdbc/derby/DerbyModule.java +324 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +68 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1346 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +161 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +82 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +126 -0
- data/test/abstract_db_create.rb +135 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/activerecord/jall.sh +7 -0
- data/test/activerecord/jtest.sh +3 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +12 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +18 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_reset_column_information_test.rb +8 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_reset_column_information_test.rb +8 -0
- data/test/derby_row_locking_test.rb +9 -0
- data/test/derby_simple_test.rb +139 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_change_column_test.rb +68 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +108 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +28 -0
- data/test/jndi_callbacks_test.rb +36 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +9 -0
- data/test/models/auto_id.rb +15 -0
- data/test/models/custom_pk_name.rb +14 -0
- data/test/models/data_types.rb +30 -0
- data/test/models/entry.rb +40 -0
- data/test/models/mixed_case.rb +22 -0
- data/test/models/reserved_word.rb +15 -0
- data/test/models/string_id.rb +17 -0
- data/test/models/thing.rb +16 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_ignore_system_views_test.rb +27 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_null_test.rb +14 -0
- data/test/mssql_reset_column_information_test.rb +8 -0
- data/test/mssql_row_locking_sql_test.rb +159 -0
- data/test/mssql_row_locking_test.rb +9 -0
- data/test/mssql_simple_test.rb +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_index_length_test.rb +58 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_reset_column_information_test.rb +8 -0
- data/test/mysql_simple_test.rb +125 -0
- data/test/oracle_reset_column_information_test.rb +8 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_information_schema_leak_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_native_type_mapping_test.rb +93 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_reset_column_information_test.rb +8 -0
- data/test/postgres_schema_search_path_test.rb +48 -0
- data/test/postgres_simple_test.rb +168 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/postgres_type_conversion_test.rb +34 -0
- data/test/row_locking.rb +90 -0
- data/test/simple.rb +731 -0
- data/test/sqlite3_reset_column_information_test.rb +8 -0
- data/test/sqlite3_simple_test.rb +316 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- data/test/sybase_reset_column_information_test.rb +8 -0
- metadata +288 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/oracle'
|
|
3
|
+
|
|
4
|
+
class OracleSimpleTest < Test::Unit::TestCase
|
|
5
|
+
include SimpleTestMethods
|
|
6
|
+
|
|
7
|
+
def test_default_id_type_is_integer
|
|
8
|
+
assert Integer === Entry.first.id
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_sequences_are_not_cached
|
|
12
|
+
ActiveRecord::Base.transaction do
|
|
13
|
+
e1 = Entry.create :title => "hello1"
|
|
14
|
+
e2 = Entry.create :title => "hello2"
|
|
15
|
+
assert e1.id != e2.id
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/oracle'
|
|
3
|
+
|
|
4
|
+
class DefaultNumber < ActiveRecord::Base
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class OracleSpecificTest < Test::Unit::TestCase
|
|
8
|
+
include MultibyteTestMethods # so we can get @java_con
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
super
|
|
12
|
+
@java_con.createStatement.execute "
|
|
13
|
+
CREATE TABLE DEFAULT_NUMBERS (
|
|
14
|
+
ID INTEGER NOT NULL PRIMARY KEY, VALUE NUMBER, DATUM DATE, FPOINT NUMBER(10,2), VALUE2 NUMBER(15)
|
|
15
|
+
)"
|
|
16
|
+
@java_con.createStatement.execute "
|
|
17
|
+
INSERT INTO DEFAULT_NUMBERS (ID, VALUE, DATUM, FPOINT, VALUE2)
|
|
18
|
+
VALUES (1, 0.076, TIMESTAMP'2009-11-05 00:00:00', 1000.01, 1234)"
|
|
19
|
+
@java_con.createStatement.execute "CREATE SYNONYM POSTS FOR ENTRIES"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def teardown
|
|
23
|
+
@java_con.createStatement.execute "DROP TABLE DEFAULT_NUMBERS"
|
|
24
|
+
@java_con.createStatement.execute "DROP SYNONYM POSTS"
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_default_number_precision
|
|
29
|
+
assert_equal 0.076, DefaultNumber.find(:first).value
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_number_with_precision_and_scale
|
|
33
|
+
assert_equal 1000.01, DefaultNumber.find(:first).fpoint
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_number_with_precision
|
|
37
|
+
assert_equal 1234, DefaultNumber.find(:first).value2
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_number_type_with_precision_and_scale_is_reported_correctly
|
|
41
|
+
assert_equal 'NUMBER', DefaultNumber.columns_hash['value'].sql_type
|
|
42
|
+
assert_equal 'NUMBER(10,2)', DefaultNumber.columns_hash['fpoint'].sql_type
|
|
43
|
+
assert_equal 'NUMBER(15)', DefaultNumber.columns_hash['value2'].sql_type
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# JRUBY-3675, ACTIVERECORD_JDBC-22
|
|
47
|
+
def test_load_date
|
|
48
|
+
obj = DefaultNumber.find(:first)
|
|
49
|
+
assert_not_nil obj.datum, "no date"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# ACTIVERECORD_JDBC-127
|
|
53
|
+
def test_save_date
|
|
54
|
+
obj = DefaultNumber.find(:first)
|
|
55
|
+
obj.datum = '01Jan2010'
|
|
56
|
+
obj.save!
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_save_timestamp
|
|
60
|
+
obj = DefaultNumber.find(:first)
|
|
61
|
+
obj.datum = Time.now
|
|
62
|
+
obj.save!
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_load_null_date
|
|
66
|
+
@java_con.createStatement.execute "UPDATE DEFAULT_NUMBERS SET DATUM = NULL"
|
|
67
|
+
obj = DefaultNumber.find(:first)
|
|
68
|
+
assert obj.datum.nil?
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_model_access_by_synonym
|
|
72
|
+
@klass = Class.new(ActiveRecord::Base)
|
|
73
|
+
@klass.table_name = "POSTS"
|
|
74
|
+
entry_columns = Entry.columns_hash
|
|
75
|
+
@klass.columns.each do |c|
|
|
76
|
+
ec = entry_columns[c.name]
|
|
77
|
+
assert ec
|
|
78
|
+
assert_equal ec.sql_type, c.sql_type
|
|
79
|
+
assert_equal ec.type, c.type
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end if defined?(JRUBY_VERSION)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'abstract_db_create'
|
|
2
|
+
require 'db/postgres'
|
|
3
|
+
|
|
4
|
+
class PostgresDbCreateTest < Test::Unit::TestCase
|
|
5
|
+
include AbstractDbCreate
|
|
6
|
+
|
|
7
|
+
def db_config
|
|
8
|
+
POSTGRES_CONFIG
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
if find_executable?("psql")
|
|
12
|
+
def test_rake_db_create
|
|
13
|
+
Rake::Task["db:create"].invoke
|
|
14
|
+
output = `psql -d template1 -c '\\l'`
|
|
15
|
+
assert output =~ /#{@db_name}/m
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_rake_db_test_purge
|
|
19
|
+
Rake::Task["db:create"].invoke
|
|
20
|
+
Rake::Task["db:test:purge"].invoke
|
|
21
|
+
end
|
|
22
|
+
else
|
|
23
|
+
def test_skipped
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_rake_db_create_does_not_load_full_environment
|
|
28
|
+
Rake::Task["db:create"].invoke
|
|
29
|
+
assert @rails_env_set
|
|
30
|
+
assert !defined?(@full_environment_loaded) || !@full_environment_loaded
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'abstract_db_create'
|
|
2
|
+
require 'db/postgres'
|
|
3
|
+
|
|
4
|
+
class PostgresDbDropTest < Test::Unit::TestCase
|
|
5
|
+
include AbstractDbCreate
|
|
6
|
+
|
|
7
|
+
def db_config
|
|
8
|
+
POSTGRES_CONFIG
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_dropping_nonexistent_database_does_not_raise_exception
|
|
12
|
+
assert_nothing_raised do
|
|
13
|
+
Rake::Task["db:drop"].invoke
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/postgres'
|
|
3
|
+
|
|
4
|
+
class CreateISLSchema < ActiveRecord::Migration
|
|
5
|
+
def self.up
|
|
6
|
+
execute "CREATE TABLE domains (id int, name varchar(16))"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.down
|
|
10
|
+
execute "DROP TABLE domains"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Domain < ActiveRecord::Base
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class PostgresInformationSchemaLeakTest < Test::Unit::TestCase
|
|
18
|
+
def setup
|
|
19
|
+
CreateISLSchema.up
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def teardown
|
|
23
|
+
CreateISLSchema.down
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_columns
|
|
27
|
+
assert_equal(%w{id name}, Domain.column_names)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'models/entry'
|
|
3
|
+
require 'models/mixed_case'
|
|
4
|
+
|
|
5
|
+
class MixedCaseTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
Migration::MixedCase.up
|
|
8
|
+
@table_name = User.table_name
|
|
9
|
+
User.table_name = 'tblUsers'
|
|
10
|
+
User.reset_column_information
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
User.table_name = @table_name
|
|
15
|
+
User.reset_column_information
|
|
16
|
+
Migration::MixedCase.down
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_create
|
|
20
|
+
mixed_case = MixedCase.create :SOME_value => 'some value'
|
|
21
|
+
assert_equal 'some value', mixed_case.SOME_value
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_find_mixed_table_name
|
|
25
|
+
User.create :firstName => "Nick", :lastName => "Sieger"
|
|
26
|
+
u = User.find :first
|
|
27
|
+
assert_equal "Nick Sieger", "#{u.firstName} #{u.lastName}"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/postgres'
|
|
3
|
+
|
|
4
|
+
class CreateNativeTypeMappingTestSchema < ActiveRecord::Migration
|
|
5
|
+
def self.up
|
|
6
|
+
execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
|
|
7
|
+
execute "CREATE SEQUENCE seq_pk_customers"
|
|
8
|
+
columns = [
|
|
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
|
+
]
|
|
20
|
+
columns << "uuid_should_be_string uuid" if PG_VERSION >= 80300
|
|
21
|
+
table_sql = %Q{
|
|
22
|
+
CREATE TABLE customers (
|
|
23
|
+
#{columns.join(",\n")}
|
|
24
|
+
)}
|
|
25
|
+
execute table_sql
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.down
|
|
29
|
+
execute "DROP TABLE customers"
|
|
30
|
+
execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class Customer < ActiveRecord::Base
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class PostgresNativeTypeMappingTest < Test::Unit::TestCase
|
|
38
|
+
def setup
|
|
39
|
+
CreateNativeTypeMappingTestSchema.up
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def teardown
|
|
43
|
+
CreateNativeTypeMappingTestSchema.down
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def column_type(column_name)
|
|
47
|
+
Customer.columns.detect { |c| c.name == column_name }.type
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_uuid_column_should_map_to_string
|
|
51
|
+
assert_equal :string, column_type("uuid_should_be_string") if PG_VERSION >= 80300
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_bigint_serial_should_be_mapped_to_integer
|
|
55
|
+
assert_equal :integer, column_type("bigint_serial_should_be_integer")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_integer_serial_should_be_mapped_to_integer
|
|
59
|
+
assert_equal :integer, column_type("integer_serial_should_be_integer")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_varchar_should_be_mapped_to_string
|
|
63
|
+
assert_equal :string, column_type("varchar_should_be_string")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_timestamp_should_be_mapped_to_datetime
|
|
67
|
+
assert_equal :datetime, column_type("timestamp_should_be_datetime")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_bytea_should_be_mapped_to_binary
|
|
71
|
+
assert_equal :binary, column_type("bytea_should_be_binary")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_double_precision_should_be_mapped_to_float
|
|
75
|
+
assert_equal :float, column_type("double_precision_should_be_float")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_real_should_be_mapped_to_float
|
|
79
|
+
assert_equal :float, column_type("real_should_be_float")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_bool_should_be_mapped_to_boolean
|
|
83
|
+
assert_equal :boolean, column_type("bool_should_be_boolean")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_interval_should_be_mapped_to_string
|
|
87
|
+
assert_equal :string, column_type("interval_should_be_string")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_bigint_should_be_mapped_to_integer
|
|
91
|
+
assert_equal :integer, column_type("bigint_should_be_integer")
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/postgres'
|
|
3
|
+
|
|
4
|
+
class CreateUrls < ActiveRecord::Migration
|
|
5
|
+
def self.up
|
|
6
|
+
create_table 'urls', :id => false do |t|
|
|
7
|
+
t.text :uhash, :null => false
|
|
8
|
+
t.text :url, :null => false
|
|
9
|
+
end
|
|
10
|
+
execute "ALTER TABLE urls ADD PRIMARY KEY (uhash)"
|
|
11
|
+
end
|
|
12
|
+
def self.down
|
|
13
|
+
drop_table 'urls'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Url < ActiveRecord::Base
|
|
18
|
+
self.primary_key = :uhash
|
|
19
|
+
#Shouldn't be needed: set_sequence_name nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class PostgresNonSeqPKey < Test::Unit::TestCase
|
|
23
|
+
def setup
|
|
24
|
+
CreateUrls.up
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def teardown
|
|
28
|
+
CreateUrls.down
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_create
|
|
32
|
+
url = Url.create! do |u|
|
|
33
|
+
u.uhash = 'uhash'
|
|
34
|
+
u.url = 'http://url'
|
|
35
|
+
end
|
|
36
|
+
assert_equal( 'uhash', url.uhash )
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/postgres'
|
|
3
|
+
require 'models/reserved_word'
|
|
4
|
+
|
|
5
|
+
class PostgresReservedWordsTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
CreateReservedWords.up
|
|
8
|
+
end
|
|
9
|
+
def teardown
|
|
10
|
+
CreateReservedWords.down
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_quote_reserved_word_column
|
|
14
|
+
columns = ReservedWord.column_names - ["id"]
|
|
15
|
+
ReservedWord.connection.add_index :reserved_words, columns
|
|
16
|
+
indexes = ReservedWord.connection.indexes("reserved_words")
|
|
17
|
+
assert_equal 1, indexes.size
|
|
18
|
+
columns.each do |c|
|
|
19
|
+
assert indexes[0].columns.include?(c), "#{indexes[0].columns.inspect} does not include #{c.inspect}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/postgres'
|
|
3
|
+
|
|
4
|
+
class CreateSchema < ActiveRecord::Migration
|
|
5
|
+
def self.up
|
|
6
|
+
execute "CREATE SCHEMA test"
|
|
7
|
+
execute "CREATE TABLE test.people (id serial, name text)"
|
|
8
|
+
execute "INSERT INTO test.people (name) VALUES ('Alex')"
|
|
9
|
+
execute "CREATE TABLE public.people (id serial, wrongname text)"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.down
|
|
13
|
+
execute "DROP SCHEMA test CASCADE"
|
|
14
|
+
execute "DROP TABLE people"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class Person < ActiveRecord::Base
|
|
19
|
+
establish_connection POSTGRES_CONFIG.merge(:schema_search_path => 'test,public')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class PostgresSchemaSearchPathTest < Test::Unit::TestCase
|
|
23
|
+
def setup
|
|
24
|
+
CreateSchema.up
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def teardown
|
|
28
|
+
CreateSchema.down
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_columns
|
|
32
|
+
assert_equal(%w{id name}, Person.column_names)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_find_right
|
|
36
|
+
assert_not_nil Person.find_by_name("Alex")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_find_wrong
|
|
40
|
+
assert_raise NoMethodError do
|
|
41
|
+
Person.find_by_wrongname("Alex")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
def test_column_information
|
|
45
|
+
assert Person.columns.map{|col| col.name}.include?("name")
|
|
46
|
+
assert !Person.columns.map{|col| col.name}.include?("wrongname")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# To run this script, set up the following postgres user and database:
|
|
2
|
+
#
|
|
3
|
+
# sudo -u postgres createuser -D -A -P blog
|
|
4
|
+
# sudo -u postgres createdb -O blog weblog_development
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
require 'jdbc_common'
|
|
8
|
+
require 'db/postgres'
|
|
9
|
+
|
|
10
|
+
class PostgresSimpleTest < Test::Unit::TestCase
|
|
11
|
+
include SimpleTestMethods
|
|
12
|
+
include ActiveRecord3TestMethods
|
|
13
|
+
include ColumnNameQuotingTests
|
|
14
|
+
|
|
15
|
+
def test_adapter_class_name_equals_native_adapter_class_name
|
|
16
|
+
classname = @connection.class.name[/[^:]*$/]
|
|
17
|
+
assert_equal 'PostgreSQLAdapter', classname
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_encoding
|
|
21
|
+
assert_not_nil @connection.encoding
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_multi_statement_support
|
|
25
|
+
results = @connection.execute "SELECT title from entries; SELECT login from users"
|
|
26
|
+
assert_equal 2, results.length
|
|
27
|
+
assert_equal ["title"], results[0].first.keys
|
|
28
|
+
assert_equal ["login"], results[1].first.keys
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_create_xml_column
|
|
32
|
+
return unless PG_VERSION >= 80300
|
|
33
|
+
assert_nothing_raised do
|
|
34
|
+
@connection.create_table :xml_testings do |t|
|
|
35
|
+
t.column :xml_test, :xml
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
xml_test = @connection.columns(:xml_testings).detect do
|
|
40
|
+
|c| c.name == "xml_test"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
assert_equal "xml", xml_test.sql_type
|
|
44
|
+
ensure
|
|
45
|
+
@connection.drop_table :xml_testings rescue nil
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_create_table_with_limits
|
|
49
|
+
assert_nothing_raised do
|
|
50
|
+
@connection.create_table :testings do |t|
|
|
51
|
+
t.column :eleven_int, :integer, :limit => 11
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
columns = @connection.columns(:testings)
|
|
56
|
+
eleven = columns.detect { |c| c.name == "eleven_int" }
|
|
57
|
+
assert_equal "integer", eleven.sql_type
|
|
58
|
+
ensure
|
|
59
|
+
@connection.drop_table :testings rescue nil
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class PostgresTimestampTest < Test::Unit::TestCase
|
|
64
|
+
def setup
|
|
65
|
+
DbTypeMigration.up
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def teardown
|
|
69
|
+
DbTypeMigration.down
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_string_is_character_varying
|
|
73
|
+
sample_string = DbType.connection.columns(:db_types).detect do |c|
|
|
74
|
+
c.name == "sample_string"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
assert_match(/^character varying/, sample_string.sql_type)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# infinite timestamp tests based on rails tests for postgresql_adapter.rb
|
|
81
|
+
def test_load_infinity_and_beyond
|
|
82
|
+
d = DbType.find_by_sql("select 'infinity'::timestamp as sample_timestamp")
|
|
83
|
+
assert d.first.sample_timestamp.infinite?, 'timestamp should be infinite'
|
|
84
|
+
|
|
85
|
+
d = DbType.find_by_sql "select '-infinity'::timestamp as sample_timestamp"
|
|
86
|
+
time = d.first.sample_timestamp
|
|
87
|
+
assert time.infinite?, "timestamp should be infinte"
|
|
88
|
+
assert_operator time, :<, 0
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_save_infinity_and_beyond
|
|
92
|
+
d = DbType.create!(:sample_timestamp => 1.0 / 0.0)
|
|
93
|
+
assert_equal(1.0 / 0.0, d.sample_timestamp)
|
|
94
|
+
|
|
95
|
+
e = DbType.create!(:sample_timestamp => -1.0 / 0.0)
|
|
96
|
+
assert_equal(-1.0 / 0.0, e.sample_timestamp)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
class PostgresDeserializationTest < Test::Unit::TestCase
|
|
101
|
+
def setup
|
|
102
|
+
DbTypeMigration.up
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def teardown
|
|
106
|
+
DbTypeMigration.down
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_should_keep_float_precision
|
|
110
|
+
expected = DbType.create(:sample_float => 7.3)
|
|
111
|
+
actual = DbType.find(expected.id)
|
|
112
|
+
|
|
113
|
+
assert_equal expected.sample_float, actual.sample_float
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
class PostgresSchemaDumperTest < Test::Unit::TestCase
|
|
118
|
+
def setup
|
|
119
|
+
DbTypeMigration.up
|
|
120
|
+
@connection = ActiveRecord::Base.connection
|
|
121
|
+
strio = StringIO.new
|
|
122
|
+
ActiveRecord::SchemaDumper::dump(ActiveRecord::Base.connection, strio)
|
|
123
|
+
@dump = strio.string
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def teardown
|
|
127
|
+
DbTypeMigration.down
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
|
|
131
|
+
def test_schema_dump_should_not_have_limits_on_boolean
|
|
132
|
+
lines = @dump.lines.grep(/boolean/)
|
|
133
|
+
assert !lines.empty?
|
|
134
|
+
lines.each {|line| assert line !~ /limit/ }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_schema_dump_should_not_have_limits_on_binaries
|
|
139
|
+
lines = @dump.lines.grep(/binary/)
|
|
140
|
+
assert !lines.empty?, 'no binary type definitions found'
|
|
141
|
+
lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
|
|
145
|
+
def test_schema_dump_should_not_have_limits_on_text_or_date
|
|
146
|
+
lines = @dump.lines.grep(/date|text/)
|
|
147
|
+
assert !lines.empty?
|
|
148
|
+
lines.each {|line| assert line !~ /limit/ }
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_schema_dump_integer_with_no_limit_should_have_no_limit
|
|
152
|
+
lines = @dump.lines.grep(/sample_integer_no_limit/)
|
|
153
|
+
assert !lines.empty?
|
|
154
|
+
lines.each {|line| assert line !~ /:limit/ }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_schema_dump_integer_with_limit_2_should_have_limit_2
|
|
158
|
+
lines = @dump.lines.grep(/sample_integer_with_limit_2/)
|
|
159
|
+
assert !lines.empty?
|
|
160
|
+
lines.each {|line| assert line =~ /limit => 2/ }
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_schema_dump_integer_with_limit_8_should_have_limit_8
|
|
164
|
+
lines = @dump.lines.grep(/sample_integer_with_limit_8/)
|
|
165
|
+
assert !lines.empty?
|
|
166
|
+
lines.each {|line| assert line =~ /limit => 8/ }
|
|
167
|
+
end
|
|
168
|
+
end
|