activerecord-jdbc-adapter 0.9.3-java → 0.9.4-java
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/History.txt +11 -0
- data/Manifest.txt +8 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +18 -14
- data/lib/activerecord-jdbc-adapter.rb +6 -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 +6 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_db2.rb +19 -0
- data/lib/jdbc_adapter/jdbc_derby.rb +0 -4
- data/lib/jdbc_adapter/jdbc_hsqldb.rb +5 -2
- data/lib/jdbc_adapter/jdbc_mysql.rb +9 -1
- data/lib/jdbc_adapter/jdbc_oracle.rb +1 -1
- data/lib/jdbc_adapter/jdbc_postgre.rb +22 -1
- data/lib/jdbc_adapter/jdbc_sqlite3.rb +4 -2
- data/lib/jdbc_adapter/railtie.rb +9 -0
- data/lib/jdbc_adapter/version.rb +1 -1
- data/rakelib/package.rake +1 -0
- data/rakelib/test.rake +1 -6
- data/test/mysql_info_test.rb +62 -0
- metadata +11 -3
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 0.9.4
|
2
|
+
|
3
|
+
- ACTIVERECORD_JDBC-96: DB2 JdbcSpec cannot dump schema correctly
|
4
|
+
(Youhei Kondou)
|
5
|
+
- ACTIVERECORD_JDBC-97: Dont use Rails 3 deprecated constants (David
|
6
|
+
Calavera)
|
7
|
+
- Updates for rake db:schema:dump compatibility with Rails 2.3+ and
|
8
|
+
MySQL (Joakim Kolsj�)
|
9
|
+
- Rails 3.0.0.beta2 compatibility
|
10
|
+
- Return of Derby, H2, Hsqldb support (requires AR >= 3.0.0.beta2)
|
11
|
+
|
1
12
|
== 0.9.3
|
2
13
|
|
3
14
|
- Rails 3 compatibility
|
data/Manifest.txt
CHANGED
@@ -3,6 +3,7 @@ Manifest.txt
|
|
3
3
|
README.txt
|
4
4
|
Rakefile
|
5
5
|
LICENSE.txt
|
6
|
+
lib/activerecord-jdbc-adapter.rb
|
6
7
|
lib/jdbc_adapter.rb
|
7
8
|
lib/pg.rb
|
8
9
|
lib/active_record/connection_adapters/cachedb_adapter.rb
|
@@ -17,6 +18,11 @@ lib/active_record/connection_adapters/mysql_adapter.rb
|
|
17
18
|
lib/active_record/connection_adapters/oracle_adapter.rb
|
18
19
|
lib/active_record/connection_adapters/postgresql_adapter.rb
|
19
20
|
lib/active_record/connection_adapters/sqlite3_adapter.rb
|
21
|
+
lib/arel/engines/sql/compilers/db2_compiler.rb
|
22
|
+
lib/arel/engines/sql/compilers/derby_compiler.rb
|
23
|
+
lib/arel/engines/sql/compilers/h2_compiler.rb
|
24
|
+
lib/arel/engines/sql/compilers/hsqldb_compiler.rb
|
25
|
+
lib/arel/engines/sql/compilers/jdbc_compiler.rb
|
20
26
|
lib/generators/jdbc/jdbc_generator.rb
|
21
27
|
lib/jdbc_adapter/jdbc_cachedb.rb
|
22
28
|
lib/jdbc_adapter/jdbc_db2.rb
|
@@ -32,6 +38,7 @@ lib/jdbc_adapter/jdbc_postgre.rb
|
|
32
38
|
lib/jdbc_adapter/jdbc_sqlite3.rb
|
33
39
|
lib/jdbc_adapter/jdbc_sybase.rb
|
34
40
|
lib/jdbc_adapter/missing_functionality_helper.rb
|
41
|
+
lib/jdbc_adapter/railtie.rb
|
35
42
|
lib/jdbc_adapter/rake_tasks.rb
|
36
43
|
lib/jdbc_adapter/tsql_helper.rb
|
37
44
|
lib/jdbc_adapter/version.rb
|
@@ -55,6 +62,7 @@ test/manualTestDatabase.rb
|
|
55
62
|
test/minirunit.rb
|
56
63
|
test/mssql_simple_test.rb
|
57
64
|
test/mysql_db_create_test.rb
|
65
|
+
test/mysql_info_test.rb
|
58
66
|
test/mysql_multibyte_test.rb
|
59
67
|
test/mysql_nonstandard_primary_key_test.rb
|
60
68
|
test/mysql_simple_test.rb
|
@@ -61,14 +61,15 @@ end
|
|
61
61
|
module ActiveRecord
|
62
62
|
class Base
|
63
63
|
extend JdbcSpec::ActiveRecordExtensions
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
if respond_to?(:attributes_with_quotes)
|
65
|
+
alias :attributes_with_quotes_pre_oracle :attributes_with_quotes
|
66
|
+
def attributes_with_quotes(include_primary_key = true, *args) #:nodoc:
|
67
|
+
aq = attributes_with_quotes_pre_oracle(include_primary_key, *args)
|
68
|
+
if connection.class == ConnectionAdapters::JdbcAdapter && (connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer))
|
69
|
+
aq[self.class.primary_key] = "?" if include_primary_key && aq[self.class.primary_key].nil?
|
70
|
+
end
|
71
|
+
aq
|
70
72
|
end
|
71
|
-
aq
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
@@ -620,13 +621,16 @@ module ActiveRecord
|
|
620
621
|
end
|
621
622
|
|
622
623
|
def pk_and_sequence_for(table)
|
623
|
-
|
624
|
-
if
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
624
|
+
key = primary_key(table)
|
625
|
+
[key, nil] if key
|
626
|
+
end
|
627
|
+
|
628
|
+
def primary_key(table)
|
629
|
+
primary_keys(table).first
|
630
|
+
end
|
631
|
+
|
632
|
+
def primary_keys(table)
|
633
|
+
@connection.primary_keys(table)
|
630
634
|
end
|
631
635
|
|
632
636
|
private
|
Binary file
|
@@ -16,6 +16,11 @@ module JdbcSpec
|
|
16
16
|
end }]
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.extended(obj)
|
20
|
+
# Ignore these 4 system tables
|
21
|
+
ActiveRecord::SchemaDumper.ignore_tables |= %w{hmon_atm_info hmon_collection policy stmg_dbsize_info}
|
22
|
+
end
|
23
|
+
|
19
24
|
module Column
|
20
25
|
def type_cast(value)
|
21
26
|
return nil if value.nil? || value =~ /^\s*null\s*$/i
|
@@ -69,6 +74,10 @@ module JdbcSpec
|
|
69
74
|
tp
|
70
75
|
end
|
71
76
|
|
77
|
+
def adapter_name
|
78
|
+
'DB2'
|
79
|
+
end
|
80
|
+
|
72
81
|
def add_limit_offset!(sql, options)
|
73
82
|
if limit = options[:limit]
|
74
83
|
offset = options[:offset] || 0
|
@@ -77,6 +86,16 @@ module JdbcSpec
|
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
89
|
+
def pk_and_sequence_for(table)
|
90
|
+
# In JDBC/DB2 side, only upcase names of table and column are handled.
|
91
|
+
keys = super(table.upcase)
|
92
|
+
if keys[0]
|
93
|
+
# In ActiveRecord side, only downcase names of table and column are handled.
|
94
|
+
keys[0] = keys[0].downcase
|
95
|
+
end
|
96
|
+
keys
|
97
|
+
end
|
98
|
+
|
80
99
|
def quote_column_name(column_name)
|
81
100
|
column_name
|
82
101
|
end
|
@@ -38,6 +38,8 @@ module ::JdbcSpec
|
|
38
38
|
:text
|
39
39
|
when /tinyint/i
|
40
40
|
:boolean
|
41
|
+
when /real/i
|
42
|
+
:float
|
41
43
|
else
|
42
44
|
super(field_type)
|
43
45
|
end
|
@@ -61,7 +63,7 @@ module ::JdbcSpec
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def adapter_name #:nodoc:
|
64
|
-
defined?(::Jdbc::H2) ? '
|
66
|
+
defined?(::Jdbc::H2) ? 'H2' : 'Hsqldb'
|
65
67
|
end
|
66
68
|
|
67
69
|
def modify_types(tp)
|
@@ -90,7 +92,8 @@ module ::JdbcSpec
|
|
90
92
|
"''"
|
91
93
|
elsif column && column.type == :binary
|
92
94
|
"'#{value.unpack("H*")}'"
|
93
|
-
elsif column
|
95
|
+
elsif column && (column.type == :integer ||
|
96
|
+
column.respond_to?(:primary) && column.primary && column.klass != String)
|
94
97
|
value.to_i.to_s
|
95
98
|
else
|
96
99
|
"'#{quote_string(value)}'"
|
@@ -71,6 +71,10 @@ module ::JdbcSpec
|
|
71
71
|
tp
|
72
72
|
end
|
73
73
|
|
74
|
+
def adapter_name #:nodoc:
|
75
|
+
'mysql'
|
76
|
+
end
|
77
|
+
|
74
78
|
# QUOTING ==================================================
|
75
79
|
|
76
80
|
def quote(value, column = nil)
|
@@ -136,7 +140,7 @@ module ::JdbcSpec
|
|
136
140
|
select_all(sql).inject("") do |structure, table|
|
137
141
|
table.delete('Table_type')
|
138
142
|
|
139
|
-
hash =
|
143
|
+
hash = show_create_table(table.to_a.first.last)
|
140
144
|
|
141
145
|
if(table = hash["Create Table"])
|
142
146
|
structure += table + ";\n\n"
|
@@ -229,6 +233,10 @@ module ::JdbcSpec
|
|
229
233
|
end
|
230
234
|
|
231
235
|
private
|
236
|
+
def show_create_table(table)
|
237
|
+
select_one("SHOW CREATE TABLE #{quote_table_name(table)}")
|
238
|
+
end
|
239
|
+
|
232
240
|
def supports_views?
|
233
241
|
false
|
234
242
|
end
|
@@ -95,6 +95,10 @@ module ::JdbcSpec
|
|
95
95
|
tp
|
96
96
|
end
|
97
97
|
|
98
|
+
def adapter_name #:nodoc:
|
99
|
+
'PostgreSQL'
|
100
|
+
end
|
101
|
+
|
98
102
|
def postgresql_version
|
99
103
|
@postgresql_version ||=
|
100
104
|
begin
|
@@ -202,7 +206,7 @@ module ::JdbcSpec
|
|
202
206
|
# If that fails, try parsing the primary key's default value.
|
203
207
|
# Support the 7.x and 8.0 nextval('foo'::text) as well as
|
204
208
|
# the 8.1+ nextval('foo'::regclass).
|
205
|
-
result =
|
209
|
+
result = select(<<-end_sql, 'PK and custom sequence')[0]
|
206
210
|
SELECT attr.attname,
|
207
211
|
CASE
|
208
212
|
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
|
@@ -320,6 +324,23 @@ module ::JdbcSpec
|
|
320
324
|
execute "DROP DATABASE \"#{name}\""
|
321
325
|
end
|
322
326
|
|
327
|
+
def create_schema(schema_name, pg_username)
|
328
|
+
execute("CREATE SCHEMA \"#{schema_name}\" AUTHORIZATION \"#{pg_username}\"")
|
329
|
+
end
|
330
|
+
|
331
|
+
def drop_schema(schema_name)
|
332
|
+
execute("DROP SCHEMA \"#{schema_name}\"")
|
333
|
+
end
|
334
|
+
|
335
|
+
def all_schemas
|
336
|
+
select('select nspname from pg_namespace').map {|r| r["nspname"] }
|
337
|
+
end
|
338
|
+
|
339
|
+
def primary_key(table)
|
340
|
+
pk_and_sequence = pk_and_sequence_for(table)
|
341
|
+
pk_and_sequence && pk_and_sequence.first
|
342
|
+
end
|
343
|
+
|
323
344
|
def structure_dump
|
324
345
|
database = @config[:database]
|
325
346
|
if database.nil?
|
@@ -21,8 +21,10 @@ module ::JdbcSpec
|
|
21
21
|
# Allow database path relative to RAILS_ROOT, but only if
|
22
22
|
# the database path is not the special path that tells
|
23
23
|
# Sqlite to build a database only in memory.
|
24
|
-
|
25
|
-
|
24
|
+
rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
|
25
|
+
if rails_root_defined && ':memory:' != config[:database]
|
26
|
+
rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
|
27
|
+
config[:database] = File.expand_path(config[:database], rails_root)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
data/lib/jdbc_adapter/version.rb
CHANGED
data/rakelib/package.rake
CHANGED
@@ -43,6 +43,7 @@ end
|
|
43
43
|
%w(test package install_gem release clean).each do |task|
|
44
44
|
desc "Run rake #{task} on all available adapters and drivers"
|
45
45
|
task "all:#{task}" => task
|
46
|
+
task "adapters:#{task}" => task
|
46
47
|
end
|
47
48
|
|
48
49
|
(Dir["drivers/*/Rakefile"] + Dir["adapters/*/Rakefile"]).each do |rakefile|
|
data/rakelib/test.rake
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
require File.expand_path('../../test/helper', __FILE__)
|
2
2
|
if defined?(JRUBY_VERSION)
|
3
|
-
databases = [:test_mysql, :test_jdbc, :test_sqlite3]
|
3
|
+
databases = [:test_mysql, :test_jdbc, :test_sqlite3, :test_derby, :test_hsqldb, :test_h2]
|
4
4
|
if find_executable?("psql") && `psql -c '\\l'` && $?.exitstatus == 0
|
5
5
|
databases << :test_postgres
|
6
6
|
end
|
7
|
-
require File.expand_path('../../test/pick_rails_version', __FILE__)
|
8
|
-
if ActiveRecord::VERSION::MAJOR < 3
|
9
|
-
# These databases not working with Rails3/Arel yet
|
10
|
-
databases += [:test_derby, :test_hsqldb, :test_h2]
|
11
|
-
end
|
12
7
|
task :test => databases
|
13
8
|
else
|
14
9
|
task :test => [:test_mysql]
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/mysql'
|
3
|
+
|
4
|
+
class DBSetup < ActiveRecord::Migration
|
5
|
+
|
6
|
+
def self.up
|
7
|
+
create_table :books do |t|
|
8
|
+
t.string :title
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table :cars, :primary_key => 'legacy_id' do |t|
|
12
|
+
t.string :name
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :cats, :id => false do |t|
|
16
|
+
t.string :name
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.down
|
22
|
+
drop_table :books
|
23
|
+
drop_table :cars
|
24
|
+
drop_table :cats
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class MysqlInfoTest < Test::Unit::TestCase
|
30
|
+
|
31
|
+
def setup
|
32
|
+
DBSetup.up
|
33
|
+
@connection = ActiveRecord::Base.connection
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
DBSetup.down
|
38
|
+
end
|
39
|
+
|
40
|
+
## primary_key
|
41
|
+
def test_should_return_the_primary_key_of_a_table
|
42
|
+
assert_equal 'id', @connection.primary_key('books')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_be_able_to_return_a_custom_primary_key
|
46
|
+
assert_equal 'legacy_id', @connection.primary_key('cars')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_return_nil_for_a_table_without_a_primary_key
|
50
|
+
assert_nil @connection.primary_key('cats')
|
51
|
+
end
|
52
|
+
|
53
|
+
## structure_dump
|
54
|
+
def test_should_include_the_tables_in_a_structure_dump
|
55
|
+
# TODO: Improve these tests, I added this one because no other tests exists for this method.
|
56
|
+
dump = @connection.structure_dump
|
57
|
+
assert dump.include?('CREATE TABLE `books`')
|
58
|
+
assert dump.include?('CREATE TABLE `cars`')
|
59
|
+
assert dump.include?('CREATE TABLE `cats`')
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 4
|
9
|
+
version: 0.9.4
|
10
10
|
platform: java
|
11
11
|
authors:
|
12
12
|
- Nick Sieger, Ola Bini and JRuby contributors
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-05 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- README.txt
|
39
39
|
- Rakefile
|
40
40
|
- LICENSE.txt
|
41
|
+
- lib/activerecord-jdbc-adapter.rb
|
41
42
|
- lib/jdbc_adapter.rb
|
42
43
|
- lib/pg.rb
|
43
44
|
- lib/active_record/connection_adapters/cachedb_adapter.rb
|
@@ -52,6 +53,11 @@ files:
|
|
52
53
|
- lib/active_record/connection_adapters/oracle_adapter.rb
|
53
54
|
- lib/active_record/connection_adapters/postgresql_adapter.rb
|
54
55
|
- lib/active_record/connection_adapters/sqlite3_adapter.rb
|
56
|
+
- lib/arel/engines/sql/compilers/db2_compiler.rb
|
57
|
+
- lib/arel/engines/sql/compilers/derby_compiler.rb
|
58
|
+
- lib/arel/engines/sql/compilers/h2_compiler.rb
|
59
|
+
- lib/arel/engines/sql/compilers/hsqldb_compiler.rb
|
60
|
+
- lib/arel/engines/sql/compilers/jdbc_compiler.rb
|
55
61
|
- lib/generators/jdbc/jdbc_generator.rb
|
56
62
|
- lib/jdbc_adapter/jdbc_cachedb.rb
|
57
63
|
- lib/jdbc_adapter/jdbc_db2.rb
|
@@ -67,6 +73,7 @@ files:
|
|
67
73
|
- lib/jdbc_adapter/jdbc_sqlite3.rb
|
68
74
|
- lib/jdbc_adapter/jdbc_sybase.rb
|
69
75
|
- lib/jdbc_adapter/missing_functionality_helper.rb
|
76
|
+
- lib/jdbc_adapter/railtie.rb
|
70
77
|
- lib/jdbc_adapter/rake_tasks.rb
|
71
78
|
- lib/jdbc_adapter/tsql_helper.rb
|
72
79
|
- lib/jdbc_adapter/version.rb
|
@@ -90,6 +97,7 @@ files:
|
|
90
97
|
- test/minirunit.rb
|
91
98
|
- test/mssql_simple_test.rb
|
92
99
|
- test/mysql_db_create_test.rb
|
100
|
+
- test/mysql_info_test.rb
|
93
101
|
- test/mysql_multibyte_test.rb
|
94
102
|
- test/mysql_nonstandard_primary_key_test.rb
|
95
103
|
- test/mysql_simple_test.rb
|