activerecord-jdbc-adapter 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +20 -0
- data/README.md +30 -40
- data/gemfiles/rails23.gemfile +0 -1
- data/gemfiles/rails23.gemfile.lock +0 -4
- data/gemfiles/rails30.gemfile +0 -1
- data/gemfiles/rails30.gemfile.lock +0 -4
- data/gemfiles/rails31.gemfile +0 -1
- data/gemfiles/rails31.gemfile.lock +0 -4
- data/gemfiles/rails32.gemfile +0 -1
- data/gemfiles/rails32.gemfile.lock +0 -4
- data/gemfiles/rails40.gemfile +0 -1
- data/gemfiles/rails40.gemfile.lock +0 -4
- data/gemfiles/rails41.gemfile +0 -1
- data/gemfiles/rails41.gemfile.lock +1 -5
- data/lib/arjdbc/jdbc/adapter.rb +9 -2
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/mssql/utils.rb +16 -5
- data/lib/arjdbc/mysql/adapter.rb +8 -11
- data/lib/arjdbc/mysql/bulk_change_table.rb +107 -0
- data/lib/arjdbc/mysql/column.rb +2 -0
- data/lib/arjdbc/mysql/connection_methods.rb +16 -7
- data/lib/arjdbc/mysql/explain_support.rb +1 -1
- data/lib/arjdbc/postgresql/adapter.rb +5 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +25 -5
- data/lib/arjdbc/sqlite3/adapter.rb +2 -2
- data/lib/arjdbc/sqlite3/connection_methods.rb +14 -10
- data/lib/arjdbc/tasks.rb +3 -3
- data/lib/arjdbc/tasks/databases.rake +1 -1
- data/lib/arjdbc/tasks/databases3.rake +22 -22
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/02-test.rake +9 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +6 -2
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +13 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0441e4d8245ad0891db71d08c1d484304c319ab
|
4
|
+
data.tar.gz: a60418477bfbd7ad65c2a1517a6c53dec0158cf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e278d10109cfb86a7eb626dda7ab13f2bd789eb64b9cf71b9f9a8b7d41411a0ec67a9811aa12b0a0fb78490e910292b10c542785045d6346b70ac5f3f2bece
|
7
|
+
data.tar.gz: 8418e4e1f59bc327a899acd31639bb4f4f607f87fc693add1e056cc230f6a44bce189fc657d01be6d3e4f953f5e8826ac40c1f5d69721e32c7ad488bab9a7456
|
data/History.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 1.3.2 (10/11/13)
|
2
|
+
|
3
|
+
- when "pop-ing" current savepoint name - consider open transaction count (#477)
|
4
|
+
- [postgres] we should return "raw" hstore values on AR < 4.0 by default
|
5
|
+
(regression caused by fixing #454 for AR >= 4.0)
|
6
|
+
- [postgres] needs ColumnDefinition.array? method used by SchemaCreation (#474)
|
7
|
+
- [mysql] backported bulk change table support from Rails (fixes #469)
|
8
|
+
- support MySQL's failover host configurations (multiple hosts specified)
|
9
|
+
- set JDBC specific config values as properties instead of URL options
|
10
|
+
- SQLite3's version object should return a string on `to_s`
|
11
|
+
- [sqlite3] support :timeout option as busy_timeout (similar to Rails)
|
12
|
+
- [sqlite3] mkdir for sqlite database (path) - just like AR 4.0 now does
|
13
|
+
- [postgres] handle :connect_timeout, :sslmode, :keepalives & :krbsrvname
|
14
|
+
- [postgres] support :hostaddr, :user and :dbname options just like Rails does
|
15
|
+
- fix rake task name **db:structure:load** - missing db: prefix (#465)
|
16
|
+
- Prevent rake from throwing an exception when task w/o comment is redefined
|
17
|
+
|
18
|
+
Code Contributors (in no particular order): Prathamesh Sonpatki, Stefan Wrobel,
|
19
|
+
Micah Jaffe, Rajan Agaskar
|
20
|
+
|
1
21
|
## 1.3.1 (09/17/13)
|
2
22
|
|
3
23
|
- helper gems should contain all files from lib/* (#463)
|
data/README.md
CHANGED
@@ -13,9 +13,9 @@ JRubies) thus Java >= **1.6** is mandatory.
|
|
13
13
|
#### AR-JDBC **1.3.x** is a recommended update for all **1.2.x** users.
|
14
14
|
|
15
15
|
Our latest major version **1.3.x** represents a few months of refactoring and
|
16
|
-
updates covering (not just) new *ActiveRecord* features. It tries to stay
|
17
|
-
with 1.2.9 as much as possible but please be aware that it's not always
|
18
|
-
(mostly for the best), please read our [migration guide][8] for details.
|
16
|
+
updates covering (not just) new/old *ActiveRecord* features. It tries to stay
|
17
|
+
compatible with 1.2.9 as much as possible but please be aware that it's not always
|
18
|
+
possible(mostly for the best), please read our [migration guide][8] for details.
|
19
19
|
|
20
20
|
## Databases
|
21
21
|
|
@@ -46,30 +46,26 @@ adapters are available:
|
|
46
46
|
- HSQLDB (`activerecord-jdbchsqldb-adapter`)
|
47
47
|
- H2 (`activerecord-jdbch2-adapter`)
|
48
48
|
- MSSQL (`activerecord-jdbcmssql-adapter`) - uses the OSS jTDS driver by default
|
49
|
-
which might have issues with the latest SQLServer (
|
49
|
+
which might have issues with the latest SQLServer (but should work using the
|
50
|
+
Microsoft JDBC Driver for SQL Server - we recommend using 4.0)
|
50
51
|
|
51
|
-
2a.
|
52
|
-
following command to generate your application:
|
52
|
+
2a. If you're generating a new Rails application, use the following command:
|
53
53
|
|
54
54
|
jruby -S rails new sweetapp
|
55
55
|
|
56
56
|
2b. Otherwise, you might need to perform some extra configuration steps
|
57
57
|
to prepare your Rails application for JDBC.
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
like the following
|
59
|
+
You'll need to modify your *Gemfile* to use the *activerecord-jdbc-adapter* gem
|
60
|
+
(or one of the helper gems) under JRuby. Change your *Gemfile* to look something
|
61
|
+
like the following:
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
gem '
|
65
|
-
|
66
|
-
platforms :jruby do
|
67
|
-
gem 'jruby-openssl'
|
68
|
-
gem 'activerecord-jdbcmysql-adapter'
|
69
|
-
end
|
64
|
+
gem 'mysql2', platform: :ruby
|
65
|
+
gem 'activerecord-jdbcmysql-adapter', platform: :jruby
|
70
66
|
```
|
71
67
|
|
72
|
-
If you're using Rails 2.3:
|
68
|
+
If you're (stuck) using Rails 2.3, you might need to:
|
73
69
|
|
74
70
|
jruby script/generate jdbc
|
75
71
|
|
@@ -77,11 +73,10 @@ If you're using Rails 2.3:
|
|
77
73
|
|
78
74
|
```yml
|
79
75
|
development:
|
80
|
-
adapter: mysql
|
76
|
+
adapter: mysql2 # or mysql
|
77
|
+
database: blog_development
|
81
78
|
username: blog
|
82
79
|
password: 1234
|
83
|
-
host: localhost
|
84
|
-
database: blog_development
|
85
80
|
```
|
86
81
|
|
87
82
|
**Legacy Configuration:** If you use one of the *activerecord-jdbcxxx-adapter*
|
@@ -95,22 +90,22 @@ class and URL (do not forget to put the driver .jar(s) on the class-path) e.g.:
|
|
95
90
|
development:
|
96
91
|
adapter: jdbc
|
97
92
|
username: blog
|
98
|
-
password:
|
93
|
+
password: 1234
|
99
94
|
driver: com.mysql.jdbc.Driver
|
100
95
|
url: jdbc:mysql://localhost:3306/blog_development
|
101
96
|
```
|
102
97
|
|
103
98
|
For JNDI data sources, you may simply specify the JNDI location as follows (the
|
104
|
-
correct
|
99
|
+
correct database type will be automatically detected):
|
105
100
|
|
106
101
|
```yml
|
107
102
|
production:
|
108
|
-
adapter: jdbc
|
109
|
-
jndi: jdbc/
|
103
|
+
adapter: jndi # jdbc
|
104
|
+
jndi: jdbc/PostgreDS
|
110
105
|
```
|
111
106
|
|
112
107
|
JDBC driver specific properties might be set if you use an URL to specify the DB
|
113
|
-
or using the *properties:* syntax
|
108
|
+
or preferably using the *properties:* syntax:
|
114
109
|
|
115
110
|
```yml
|
116
111
|
production:
|
@@ -128,7 +123,6 @@ If you're really old school you might want to use AR-JDBC with a DB2 on z/OS:
|
|
128
123
|
```yml
|
129
124
|
development:
|
130
125
|
adapter: jdbc
|
131
|
-
encoding: unicode
|
132
126
|
url: jdbc:db2j:net://mightyzoshost:446/RAILS_DBT1
|
133
127
|
driver: com.ibm.db2.jcc.DB2Driver
|
134
128
|
schema: DB2XB12
|
@@ -136,23 +130,19 @@ development:
|
|
136
130
|
tablespace: TSDE911
|
137
131
|
lob_tablespaces:
|
138
132
|
first_table: TSDE912
|
139
|
-
username:
|
140
|
-
password:
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
```yml
|
146
|
-
development:
|
147
|
-
[...]
|
148
|
-
dialect: as400 # For example
|
133
|
+
username: business
|
134
|
+
password: machines
|
135
|
+
encoding: unicode
|
136
|
+
# you can force a (DB2) dialect using:
|
137
|
+
#dialect: as400
|
149
138
|
```
|
150
139
|
|
151
140
|
More information on (configuring) AR-JDBC might be found on our [wiki][5].
|
152
141
|
|
153
142
|
### Standalone with ActiveRecord
|
154
143
|
|
155
|
-
Once the setup is made (see below) you can establish a JDBC connection like this
|
144
|
+
Once the setup is made (see below) you can establish a JDBC connection like this
|
145
|
+
(e.g. for `activerecord-jdbcderby-adapter`):
|
156
146
|
|
157
147
|
```ruby
|
158
148
|
ActiveRecord::Base.establish_connection(
|
@@ -161,7 +151,7 @@ ActiveRecord::Base.establish_connection(
|
|
161
151
|
)
|
162
152
|
```
|
163
153
|
|
164
|
-
or using (requires that you manually put the driver jar on the
|
154
|
+
or using (requires that you manually put the driver jar on the class-path):
|
165
155
|
|
166
156
|
```ruby
|
167
157
|
ActiveRecord::Base.establish_connection(
|
@@ -173,11 +163,11 @@ ActiveRecord::Base.establish_connection(
|
|
173
163
|
|
174
164
|
#### Using Bundler
|
175
165
|
|
176
|
-
Proceed as with Rails; specify
|
177
|
-
|
166
|
+
Proceed as with Rails; specify `ActiveRecord` in your Bundle along with the
|
167
|
+
chosen JDBC adapter(s), this time sample *Gemfile* for MySQL:
|
178
168
|
|
179
169
|
```ruby
|
180
|
-
gem 'activerecord', '~> 3.2.
|
170
|
+
gem 'activerecord', '~> 3.2.14'
|
181
171
|
gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
|
182
172
|
```
|
183
173
|
|
data/gemfiles/rails23.gemfile
CHANGED
@@ -18,9 +18,6 @@ GEM
|
|
18
18
|
atomic (1.1.10-java)
|
19
19
|
bcrypt-ruby (3.0.1)
|
20
20
|
bcrypt-ruby (3.0.1-java)
|
21
|
-
bouncy-castle-java (1.5.0147)
|
22
|
-
jruby-openssl (0.8.8)
|
23
|
-
bouncy-castle-java (>= 1.5.0147)
|
24
21
|
metaclass (0.0.1)
|
25
22
|
mocha (0.13.3)
|
26
23
|
metaclass (~> 0.0.1)
|
@@ -54,7 +51,6 @@ DEPENDENCIES
|
|
54
51
|
activerecord (~> 2.3.18)
|
55
52
|
appraisal
|
56
53
|
bcrypt-ruby (~> 3.0.0)
|
57
|
-
jruby-openssl
|
58
54
|
mocha (~> 0.13.1)
|
59
55
|
mysql2
|
60
56
|
pg
|
data/gemfiles/rails30.gemfile
CHANGED
@@ -19,11 +19,8 @@ GEM
|
|
19
19
|
atomic (1.1.10-java)
|
20
20
|
bcrypt-ruby (3.0.1)
|
21
21
|
bcrypt-ruby (3.0.1-java)
|
22
|
-
bouncy-castle-java (1.5.0147)
|
23
22
|
builder (2.1.2)
|
24
23
|
i18n (0.5.0)
|
25
|
-
jruby-openssl (0.8.8)
|
26
|
-
bouncy-castle-java (>= 1.5.0147)
|
27
24
|
metaclass (0.0.1)
|
28
25
|
mocha (0.13.3)
|
29
26
|
metaclass (~> 0.0.1)
|
@@ -53,7 +50,6 @@ DEPENDENCIES
|
|
53
50
|
activerecord (~> 3.0.20)
|
54
51
|
appraisal
|
55
52
|
bcrypt-ruby (~> 3.0.0)
|
56
|
-
jruby-openssl
|
57
53
|
mocha (~> 0.13.1)
|
58
54
|
mysql2
|
59
55
|
pg
|
data/gemfiles/rails31.gemfile
CHANGED
@@ -20,11 +20,8 @@ GEM
|
|
20
20
|
atomic (1.1.10-java)
|
21
21
|
bcrypt-ruby (3.0.1)
|
22
22
|
bcrypt-ruby (3.0.1-java)
|
23
|
-
bouncy-castle-java (1.5.0147)
|
24
23
|
builder (3.0.4)
|
25
24
|
i18n (0.6.4)
|
26
|
-
jruby-openssl (0.8.8)
|
27
|
-
bouncy-castle-java (>= 1.5.0147)
|
28
25
|
metaclass (0.0.1)
|
29
26
|
mocha (0.13.3)
|
30
27
|
metaclass (~> 0.0.1)
|
@@ -51,7 +48,6 @@ DEPENDENCIES
|
|
51
48
|
activerecord (~> 3.1.12)
|
52
49
|
appraisal
|
53
50
|
bcrypt-ruby (~> 3.0.0)
|
54
|
-
jruby-openssl
|
55
51
|
mocha (~> 0.13.1)
|
56
52
|
mysql2
|
57
53
|
pg
|
data/gemfiles/rails32.gemfile
CHANGED
@@ -20,11 +20,8 @@ GEM
|
|
20
20
|
atomic (1.1.10-java)
|
21
21
|
bcrypt-ruby (3.0.1)
|
22
22
|
bcrypt-ruby (3.0.1-java)
|
23
|
-
bouncy-castle-java (1.5.0147)
|
24
23
|
builder (3.0.4)
|
25
24
|
i18n (0.6.4)
|
26
|
-
jruby-openssl (0.8.8)
|
27
|
-
bouncy-castle-java (>= 1.5.0147)
|
28
25
|
metaclass (0.0.1)
|
29
26
|
mocha (0.13.3)
|
30
27
|
metaclass (~> 0.0.1)
|
@@ -54,7 +51,6 @@ DEPENDENCIES
|
|
54
51
|
activerecord (~> 3.2.13)
|
55
52
|
appraisal
|
56
53
|
bcrypt-ruby (~> 3.0.0)
|
57
|
-
jruby-openssl
|
58
54
|
mocha (~> 0.13.1)
|
59
55
|
mysql2
|
60
56
|
pg
|
data/gemfiles/rails40.gemfile
CHANGED
@@ -24,11 +24,8 @@ GEM
|
|
24
24
|
atomic (1.1.10-java)
|
25
25
|
bcrypt-ruby (3.0.1)
|
26
26
|
bcrypt-ruby (3.0.1-java)
|
27
|
-
bouncy-castle-java (1.5.0147)
|
28
27
|
builder (3.1.4)
|
29
28
|
i18n (0.6.4)
|
30
|
-
jruby-openssl (0.8.8)
|
31
|
-
bouncy-castle-java (>= 1.5.0147)
|
32
29
|
metaclass (0.0.1)
|
33
30
|
minitest (4.7.5)
|
34
31
|
mocha (0.13.3)
|
@@ -54,7 +51,6 @@ DEPENDENCIES
|
|
54
51
|
activerecord (~> 4.0.0)
|
55
52
|
appraisal
|
56
53
|
bcrypt-ruby (~> 3.0.0)
|
57
|
-
jruby-openssl
|
58
54
|
mocha (~> 0.13.1)
|
59
55
|
mysql2
|
60
56
|
pg
|
data/gemfiles/rails41.gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
GIT
|
2
2
|
remote: git://github.com/rails/rails.git
|
3
|
-
revision:
|
3
|
+
revision: 0941a109fda0a96403fc9b51249ced7b7ca63447
|
4
4
|
branch: master
|
5
5
|
specs:
|
6
6
|
actionmailer (4.1.0.beta)
|
@@ -55,13 +55,10 @@ GEM
|
|
55
55
|
atomic (1.1.13-java)
|
56
56
|
bcrypt-ruby (3.0.1)
|
57
57
|
bcrypt-ruby (3.0.1-java)
|
58
|
-
bouncy-castle-java (1.5.0147)
|
59
58
|
builder (3.1.4)
|
60
59
|
erubis (2.7.0)
|
61
60
|
hike (1.2.3)
|
62
61
|
i18n (0.6.5)
|
63
|
-
jruby-openssl (0.8.8)
|
64
|
-
bouncy-castle-java (>= 1.5.0147)
|
65
62
|
json (1.8.0)
|
66
63
|
json (1.8.0-java)
|
67
64
|
mail (2.5.4)
|
@@ -116,7 +113,6 @@ DEPENDENCIES
|
|
116
113
|
activerecord
|
117
114
|
appraisal
|
118
115
|
bcrypt-ruby (~> 3.0.0)
|
119
|
-
jruby-openssl
|
120
116
|
mocha (~> 0.13.1)
|
121
117
|
mysql2
|
122
118
|
pg
|
data/lib/arjdbc/jdbc/adapter.rb
CHANGED
@@ -402,8 +402,15 @@ module ActiveRecord
|
|
402
402
|
# @since 1.3.0
|
403
403
|
# @override
|
404
404
|
def current_savepoint_name(create = nil)
|
405
|
-
|
406
|
-
|
405
|
+
open_tx = open_transactions
|
406
|
+
return "active_record_#{open_tx}" if create
|
407
|
+
|
408
|
+
sp_names = @connection.marked_savepoint_names
|
409
|
+
unless sp_names.empty?
|
410
|
+
sp_names[ -(sp_names.size - open_tx + 1) ]
|
411
|
+
else
|
412
|
+
"active_record_#{open_tx}"
|
413
|
+
end
|
407
414
|
end
|
408
415
|
|
409
416
|
# Executes a SQL query in the context of this connection using the bind
|
Binary file
|
data/lib/arjdbc/mssql/utils.rb
CHANGED
@@ -23,12 +23,23 @@ module ArJdbc
|
|
23
23
|
|
24
24
|
# protected
|
25
25
|
|
26
|
+
# See "Delimited Identifiers": http://msdn.microsoft.com/en-us/library/ms176027.aspx
|
27
|
+
def remove_identifier_delimiters(keyword)
|
28
|
+
if /\A(\[|")(.*)/m.match(keyword)
|
29
|
+
delim, rest = $1, $2
|
30
|
+
if delim == '[' && rest =~ /]\z/ || delim == '"' && rest =~ /"\z/
|
31
|
+
return rest.chop
|
32
|
+
end
|
33
|
+
end
|
34
|
+
keyword
|
35
|
+
end
|
36
|
+
|
26
37
|
def unquote_table_name(table_name)
|
27
|
-
|
38
|
+
remove_identifier_delimiters(table_name)
|
28
39
|
end
|
29
40
|
|
30
41
|
def unquote_column_name(column_name)
|
31
|
-
column_name
|
42
|
+
remove_identifier_delimiters(column_name)
|
32
43
|
end
|
33
44
|
|
34
45
|
def unquote_string(string)
|
@@ -36,16 +47,16 @@ module ArJdbc
|
|
36
47
|
end
|
37
48
|
|
38
49
|
def unqualify_table_name(table_name)
|
39
|
-
table_name.to_s.split('.').last
|
50
|
+
remove_identifier_delimiters(table_name.to_s.split('.').last)
|
40
51
|
end
|
41
52
|
|
42
53
|
def unqualify_table_schema(table_name)
|
43
|
-
table_name.to_s.split('.')[-2]
|
54
|
+
remove_identifier_delimiters(table_name.to_s.split('.')[-2]) rescue nil
|
44
55
|
end
|
45
56
|
|
46
57
|
def unqualify_db_name(table_name)
|
47
58
|
table_names = table_name.to_s.split('.')
|
48
|
-
table_names.length == 3 ? table_names.first
|
59
|
+
table_names.length == 3 ? remove_identifier_delimiters(table_names.first) : nil
|
49
60
|
end
|
50
61
|
|
51
62
|
end
|
data/lib/arjdbc/mysql/adapter.rb
CHANGED
@@ -3,11 +3,13 @@ ArJdbc.load_java_part :MySQL
|
|
3
3
|
require 'bigdecimal'
|
4
4
|
require 'active_record/connection_adapters/abstract/schema_definitions'
|
5
5
|
require 'arjdbc/mysql/column'
|
6
|
+
require 'arjdbc/mysql/bulk_change_table'
|
6
7
|
require 'arjdbc/mysql/explain_support'
|
7
8
|
require 'arjdbc/mysql/schema_creation' # AR 4.x
|
8
9
|
|
9
10
|
module ArJdbc
|
10
11
|
module MySQL
|
12
|
+
include BulkChangeTable if const_defined? :BulkChangeTable
|
11
13
|
|
12
14
|
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
|
13
15
|
def self.jdbc_connection_class
|
@@ -35,8 +37,8 @@ module ArJdbc
|
|
35
37
|
|
36
38
|
# Increase timeout so the server doesn't disconnect us.
|
37
39
|
wait_timeout = config[:wait_timeout]
|
38
|
-
wait_timeout =
|
39
|
-
variables[:wait_timeout] = wait_timeout
|
40
|
+
wait_timeout = self.class.type_cast_config_to_integer(wait_timeout)
|
41
|
+
variables[:wait_timeout] = wait_timeout.is_a?(Fixnum) ? wait_timeout : 2147483
|
40
42
|
|
41
43
|
# Make MySQL reject illegal values rather than truncating or blanking them, see
|
42
44
|
# http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
|
@@ -65,7 +67,9 @@ module ArJdbc
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def strict_mode? # strict_mode is default since AR 4.0
|
68
|
-
config.key?(:strict) ?
|
70
|
+
config.key?(:strict) ?
|
71
|
+
self.class.type_cast_config_to_boolean(config[:strict]) :
|
72
|
+
::ActiveRecord::VERSION::MAJOR > 3
|
69
73
|
end
|
70
74
|
|
71
75
|
# @private
|
@@ -177,11 +181,6 @@ module ArJdbc
|
|
177
181
|
true
|
178
182
|
end
|
179
183
|
|
180
|
-
# @override
|
181
|
-
def supports_bulk_alter?
|
182
|
-
true
|
183
|
-
end
|
184
|
-
|
185
184
|
# @override
|
186
185
|
def supports_index_sort_order?
|
187
186
|
# Technically MySQL allows to create indexes with the sort order syntax
|
@@ -418,7 +417,7 @@ module ArJdbc
|
|
418
417
|
add_column_options!(change_column_sql, options)
|
419
418
|
add_column_position!(change_column_sql, options)
|
420
419
|
execute(change_column_sql)
|
421
|
-
end
|
420
|
+
end
|
422
421
|
|
423
422
|
# @override
|
424
423
|
def rename_column(table_name, column_name, new_column_name)
|
@@ -605,8 +604,6 @@ module ActiveRecord
|
|
605
604
|
class Column < JdbcColumn
|
606
605
|
include ::ArJdbc::MySQL::Column
|
607
606
|
|
608
|
-
attr_reader :collation, :strict, :extra
|
609
|
-
|
610
607
|
def initialize(name, default, sql_type = nil, null = true, collation = nil, strict = false, extra = "")
|
611
608
|
if Hash === name
|
612
609
|
super # first arg: config
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module MySQL
|
3
|
+
module BulkChangeTable
|
4
|
+
|
5
|
+
# @override
|
6
|
+
def supports_bulk_alter?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def bulk_change_table(table_name, operations)
|
11
|
+
sqls = operations.map do |command, args|
|
12
|
+
table, arguments = args.shift, args
|
13
|
+
method = :"#{command}_sql"
|
14
|
+
|
15
|
+
if respond_to?(method, true)
|
16
|
+
send(method, table, *arguments)
|
17
|
+
else
|
18
|
+
raise "Unknown method called : #{method}(#{arguments.inspect})"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
sqls.flatten!
|
22
|
+
|
23
|
+
execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls.join(", ")}")
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def add_column_sql(table_name, column_name, type, options = {})
|
29
|
+
add_column_sql = "ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
|
30
|
+
add_column_options!(add_column_sql, options)
|
31
|
+
add_column_position!(add_column_sql, options)
|
32
|
+
add_column_sql
|
33
|
+
end
|
34
|
+
|
35
|
+
def change_column_sql(table_name, column_name, type, options = {})
|
36
|
+
column = column_for(table_name, column_name)
|
37
|
+
|
38
|
+
unless options_include_default?(options)
|
39
|
+
options[:default] = column.default
|
40
|
+
end
|
41
|
+
|
42
|
+
unless options.has_key?(:null)
|
43
|
+
options[:null] = column.null
|
44
|
+
end
|
45
|
+
|
46
|
+
change_column_sql = "CHANGE #{quote_column_name(column_name)} #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
|
47
|
+
add_column_options!(change_column_sql, options)
|
48
|
+
add_column_position!(change_column_sql, options)
|
49
|
+
change_column_sql
|
50
|
+
end
|
51
|
+
|
52
|
+
def rename_column_sql(table_name, column_name, new_column_name)
|
53
|
+
options = {}
|
54
|
+
|
55
|
+
if column = columns(table_name).find { |c| c.name == column_name.to_s }
|
56
|
+
options[:default] = column.default
|
57
|
+
options[:null] = column.null
|
58
|
+
options[:auto_increment] = (column.extra == "auto_increment")
|
59
|
+
else
|
60
|
+
raise ActiveRecordError, "No such column: #{table_name}.#{column_name}"
|
61
|
+
end
|
62
|
+
|
63
|
+
current_type = select_one("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE '#{column_name}'", 'SCHEMA')["Type"]
|
64
|
+
rename_column_sql = "CHANGE #{quote_column_name(column_name)} #{quote_column_name(new_column_name)} #{current_type}"
|
65
|
+
add_column_options!(rename_column_sql, options)
|
66
|
+
rename_column_sql
|
67
|
+
end
|
68
|
+
|
69
|
+
def remove_column_sql(table_name, column_name, type = nil, options = {})
|
70
|
+
"DROP #{quote_column_name(column_name)}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def remove_columns_sql(table_name, *column_names)
|
74
|
+
column_names.map {|column_name| remove_column_sql(table_name, column_name) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_index_sql(table_name, column_name, options = {})
|
78
|
+
index_name, index_type, index_columns = add_index_options(table_name, column_name, options)
|
79
|
+
"ADD #{index_type} INDEX #{index_name} (#{index_columns})"
|
80
|
+
end
|
81
|
+
|
82
|
+
def remove_index_sql(table_name, options = {})
|
83
|
+
index_name = index_name_for_remove(table_name, options)
|
84
|
+
"DROP INDEX #{index_name}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_timestamps_sql(table_name)
|
88
|
+
[add_column_sql(table_name, :created_at, :datetime), add_column_sql(table_name, :updated_at, :datetime)]
|
89
|
+
end
|
90
|
+
|
91
|
+
def remove_timestamps_sql(table_name)
|
92
|
+
[remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)]
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def add_column_position!(sql, options)
|
98
|
+
if options[:first]
|
99
|
+
sql << " FIRST"
|
100
|
+
elsif options[:after]
|
101
|
+
sql << " AFTER #{quote_column_name(options[:after])}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/arjdbc/mysql/column.rb
CHANGED
@@ -7,17 +7,26 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
config[:username] = 'root' unless config.key?(:username)
|
10
|
-
|
11
|
-
|
10
|
+
# jdbc:mysql://[host][,failoverhost...][:port]/[database]
|
11
|
+
# - if the host name is not specified, it defaults to 127.0.0.1
|
12
|
+
# - if the port is not specified, it defaults to 3306
|
13
|
+
# - alternate fail-over syntax: [host:port],[host:port]/[database]
|
14
|
+
unless config[:url]
|
15
|
+
host = config[:host]; host = host.join(',') if host.respond_to?(:join)
|
16
|
+
url = "jdbc:mysql://#{host}"
|
17
|
+
url << ":#{config[:port]}" if config[:port]
|
18
|
+
url << "/#{config[:database]}"
|
19
|
+
config[:url] = url
|
20
|
+
end
|
12
21
|
config[:driver] ||= defined?(::Jdbc::MySQL.driver_name) ? ::Jdbc::MySQL.driver_name : 'com.mysql.jdbc.Driver'
|
13
22
|
config[:adapter_spec] ||= ::ArJdbc::MySQL
|
14
23
|
config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter unless config.key?(:adapter_class)
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
properties = ( config[:properties] ||= {} )
|
26
|
+
properties['zeroDateTimeBehavior'] ||= 'convertToNull'
|
27
|
+
properties['jdbcCompliantTruncation'] ||= 'false'
|
28
|
+
properties['useUnicode'] ||= 'true'
|
29
|
+
properties['characterEncoding'] = config[:encoding] || 'utf8'
|
21
30
|
|
22
31
|
jdbc_connection(config)
|
23
32
|
end
|
@@ -1257,6 +1257,7 @@ module ActiveRecord::ConnectionAdapters
|
|
1257
1257
|
|
1258
1258
|
class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
|
1259
1259
|
attr_accessor :array
|
1260
|
+
def array?; !!@array; end
|
1260
1261
|
end
|
1261
1262
|
|
1262
1263
|
module ColumnMethods
|
@@ -1385,5 +1386,9 @@ module ActiveRecord::ConnectionAdapters
|
|
1385
1386
|
::ActiveRecord::ConnectionAdapters::PostgreSQLColumn
|
1386
1387
|
end
|
1387
1388
|
|
1389
|
+
if ActiveRecord::VERSION::MAJOR < 4 # Rails 3.x compatibility
|
1390
|
+
PostgreSQLJdbcConnection.raw_hstore_type = true if PostgreSQLJdbcConnection.raw_hstore_type? == nil
|
1391
|
+
end
|
1392
|
+
|
1388
1393
|
end
|
1389
1394
|
end
|
@@ -6,11 +6,31 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
6
6
|
rescue LoadError # assuming driver.jar is on the class-path
|
7
7
|
end
|
8
8
|
|
9
|
-
config[:host] ||=
|
10
|
-
config[:port] ||= 5432
|
11
|
-
config[:
|
12
|
-
|
13
|
-
config[:url]
|
9
|
+
host = config[:host] ||= ( config[:hostaddr] || 'localhost' )
|
10
|
+
port = config[:port] ||= 5432
|
11
|
+
database = config[:database] || config[:dbname]
|
12
|
+
|
13
|
+
config[:url] ||= "jdbc:postgresql://#{host}:#{port}/#{database}"
|
14
|
+
config[:url] << config[:pg_params] if config[:pg_params] # should go away
|
15
|
+
|
16
|
+
config[:username] ||= config[:user] || ENV_JAVA['user.name']
|
17
|
+
properties = ( config[:properties] ||= {} )
|
18
|
+
# PG :connect_timeout - maximum time to wait for connection to succeed
|
19
|
+
if connect_timeout = config[:connect_timeout]
|
20
|
+
properties['socketTimeout'] ||= connect_timeout
|
21
|
+
# NOTE: maybe set options['loginTimeout'] as well?
|
22
|
+
end
|
23
|
+
sslmode = config.key?(:sslmode) ? config[:sslmode] : config[:requiressl]
|
24
|
+
unless sslmode.nil? # PG :sslmode - disable|allow|prefer|require
|
25
|
+
# JRuby/JVM needs to be started with :
|
26
|
+
# -Djavax.net.ssl.trustStore=mystore -Djavax.net.ssl.trustStorePassword=...
|
27
|
+
# or a non-validating connection might be used (for testing) :
|
28
|
+
# :sslfactory = 'org.postgresql.ssl.NonValidatingFactory'
|
29
|
+
properties['ssl'] ||= 'true' if sslmode == true || sslmode.to_s == 'require'
|
30
|
+
end
|
31
|
+
properties['tcpKeepAlive'] ||= config[:keepalives] if config.key?(:keepalives)
|
32
|
+
properties['kerberosServerName'] ||= config[:krbsrvname] if config[:krbsrvname]
|
33
|
+
|
14
34
|
config[:driver] ||= defined?(::Jdbc::Postgres.driver_name) ? ::Jdbc::Postgres.driver_name : 'org.postgresql.Driver'
|
15
35
|
config[:adapter_spec] ||= ::ArJdbc::PostgreSQL
|
16
36
|
config[:adapter_class] = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter unless config.key?(:adapter_class)
|
@@ -210,7 +210,7 @@ module ArJdbc
|
|
210
210
|
# @override
|
211
211
|
def quote(value, column = nil)
|
212
212
|
return value if sql_literal?(value)
|
213
|
-
|
213
|
+
|
214
214
|
if value.kind_of?(String)
|
215
215
|
column_type = column && column.type
|
216
216
|
if column_type == :binary && column.class.respond_to?(:string_to_binary)
|
@@ -497,7 +497,7 @@ module ArJdbc
|
|
497
497
|
end
|
498
498
|
|
499
499
|
def to_s
|
500
|
-
@version
|
500
|
+
@version.join('.')
|
501
501
|
end
|
502
502
|
|
503
503
|
end
|
@@ -7,27 +7,31 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
parse_sqlite3_config!(config)
|
10
|
-
database = config[:database]
|
11
|
-
|
12
|
-
config[:url] ||= "jdbc:sqlite:#{database}"
|
10
|
+
database = config[:database] # NOTE: "jdbc:sqlite::memory:" syntax is supported
|
11
|
+
config[:url] ||= "jdbc:sqlite:#{database == ':memory:' ? '' : database}"
|
13
12
|
config[:driver] ||= defined?(::Jdbc::SQLite3.driver_name) ? ::Jdbc::SQLite3.driver_name : 'org.sqlite.JDBC'
|
14
13
|
config[:adapter_spec] ||= ::ArJdbc::SQLite3
|
15
14
|
config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter unless config.key?(:adapter_class)
|
16
15
|
config[:connection_alive_sql] ||= 'SELECT 1'
|
17
|
-
|
16
|
+
|
17
|
+
options = ( config[:properties] ||= {} )
|
18
|
+
# NOTE: configuring from JDBC properties not supported on 3.7.2 :
|
19
|
+
options['busy_timeout'] ||= config[:timeout] if config.key?(:timeout)
|
20
|
+
|
18
21
|
jdbc_connection(config)
|
19
22
|
end
|
20
23
|
alias_method :jdbcsqlite3_connection, :sqlite3_connection
|
21
24
|
|
22
25
|
private
|
23
|
-
|
26
|
+
|
24
27
|
def parse_sqlite3_config!(config)
|
25
|
-
config[:database] ||= config[:dbfile]
|
26
|
-
|
27
|
-
if config[:database] != ':memory:' && defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
|
28
|
+
database = ( config[:database] ||= config[:dbfile] ) # allow Rails relative path :
|
29
|
+
if database != ':memory:' && defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
|
28
30
|
rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
|
29
|
-
config[:database] = File.expand_path(
|
31
|
+
config[:database] = File.expand_path(database, rails_root.to_s)
|
32
|
+
dirname = File.dirname(config[:database])
|
33
|
+
Dir.mkdir(dirname) unless File.directory?(dirname)
|
30
34
|
end
|
31
35
|
end
|
32
|
-
|
36
|
+
|
33
37
|
end
|
data/lib/arjdbc/tasks.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
if defined?(Rake.application) && Rake.application
|
2
|
-
skip = ENV["SKIP_AR_JDBC_RAKE_REDEFINES"] # jruby -J-
|
3
|
-
if !
|
2
|
+
skip = ENV["SKIP_AR_JDBC_RAKE_REDEFINES"] # jruby -J-Darjdbc.tasks.skip=true -S rake ...
|
3
|
+
if !(Java::JavaLang::Boolean.getBoolean('arjdbc.tasks.skip') || ( skip && skip != 'false' ))
|
4
4
|
databases_rake = File.expand_path('tasks/databases.rake', File.dirname(__FILE__))
|
5
5
|
if Rake.application.lookup("db:create")
|
6
6
|
load databases_rake # load the override tasks now
|
@@ -10,4 +10,4 @@ if defined?(Rake.application) && Rake.application
|
|
10
10
|
end
|
11
11
|
else
|
12
12
|
warn "ArJdbc: could not load rake tasks - rake not loaded ..."
|
13
|
-
end
|
13
|
+
end
|
@@ -27,7 +27,7 @@ Rake::DSL.module_eval do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
new_task = task(*args, &block)
|
30
|
-
new_task.comment = old_comment
|
30
|
+
new_task.comment = old_comment if old_comment
|
31
31
|
new_task.actions.concat(old_actions) if old_actions
|
32
32
|
new_task.prerequisites.concat(old_prereqs) if old_prereqs
|
33
33
|
new_task
|
@@ -9,9 +9,9 @@ end
|
|
9
9
|
module ArJdbc
|
10
10
|
module Tasks
|
11
11
|
class << self
|
12
|
-
|
12
|
+
|
13
13
|
# API similar to ActiveRecord::Tasks::DatabaseTasks on AR 4.0
|
14
|
-
|
14
|
+
|
15
15
|
def create(config)
|
16
16
|
tasks_instance(config).create
|
17
17
|
end
|
@@ -23,7 +23,7 @@ module ArJdbc
|
|
23
23
|
def purge(config)
|
24
24
|
tasks_instance(config).purge
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def charset(config)
|
28
28
|
tasks_instance(config).charset
|
29
29
|
end
|
@@ -39,18 +39,18 @@ module ArJdbc
|
|
39
39
|
def structure_load(config, filename)
|
40
40
|
tasks_instance(config).structure_load(filename)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
namespace :db do
|
48
|
-
|
48
|
+
|
49
49
|
class << self
|
50
50
|
alias_method :_rails_create_database, :create_database
|
51
51
|
alias_method :_rails_drop_database, :drop_database
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def create_database(config)
|
55
55
|
case config['adapter']
|
56
56
|
when /mysql|postgresql|sqlite/
|
@@ -68,7 +68,7 @@ namespace :db do
|
|
68
68
|
ArJdbc::Tasks.drop(config)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
redefine_task :charset do # available on 2.3
|
73
73
|
ArJdbc::Tasks.charset ActiveRecord::Base.configurations[rails_env]
|
74
74
|
end
|
@@ -76,25 +76,25 @@ namespace :db do
|
|
76
76
|
redefine_task :collation do # available on 2.3
|
77
77
|
ArJdbc::Tasks.collation ActiveRecord::Base.configurations[rails_env]
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
namespace :structure do
|
81
|
-
|
81
|
+
|
82
82
|
redefine_task :dump do
|
83
83
|
config = ActiveRecord::Base.configurations[rails_env] # current_config
|
84
84
|
filename = structure_sql
|
85
|
-
|
85
|
+
|
86
86
|
case config['adapter']
|
87
87
|
when /mysql/
|
88
88
|
ActiveRecord::Base.establish_connection(config)
|
89
89
|
File.open(filename, 'w:utf-8') { |f| f << ActiveRecord::Base.connection.structure_dump }
|
90
90
|
when /postgresql/
|
91
91
|
ActiveRecord::Base.establish_connection(config)
|
92
|
-
|
92
|
+
|
93
93
|
ENV['PGHOST'] = config['host'] if config['host']
|
94
94
|
ENV['PGPORT'] = config['port'].to_s if config['port']
|
95
95
|
ENV['PGPASSWORD'] = config['password'].to_s if config['password']
|
96
96
|
ENV['PGUSER'] = config['username'].to_s if config['username']
|
97
|
-
|
97
|
+
|
98
98
|
require 'shellwords'
|
99
99
|
search_path = config['schema_search_path']
|
100
100
|
unless search_path.blank?
|
@@ -102,7 +102,7 @@ namespace :db do
|
|
102
102
|
end
|
103
103
|
`pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(config['database'])}`
|
104
104
|
raise 'Error dumping database' if $?.exitstatus == 1
|
105
|
-
|
105
|
+
|
106
106
|
File.open(filename, 'a') { |f| f << "SET search_path TO #{ActiveRecord::Base.connection.schema_search_path};\n\n" }
|
107
107
|
when /sqlite/
|
108
108
|
dbfile = config['database']
|
@@ -120,7 +120,7 @@ namespace :db do
|
|
120
120
|
redefine_task :load do
|
121
121
|
config = ActiveRecord::Base.configurations[rails_env] # current_config
|
122
122
|
filename = structure_sql
|
123
|
-
|
123
|
+
|
124
124
|
case config['adapter']
|
125
125
|
when /mysql/
|
126
126
|
ActiveRecord::Base.establish_connection(config)
|
@@ -142,7 +142,7 @@ namespace :db do
|
|
142
142
|
ArJdbc::Tasks.structure_load(config, filename)
|
143
143
|
end
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
def structure_sql
|
147
147
|
ENV['DB_STRUCTURE'] ||= begin
|
148
148
|
root = defined?(Rails.root) ? Rails.root : ( RAILS_ROOT rescue nil )
|
@@ -153,21 +153,21 @@ namespace :db do
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
namespace :test do
|
160
|
-
|
160
|
+
|
161
161
|
# desc "Recreate the test database from an existent structure.sql file"
|
162
162
|
redefine_task :load_structure => 'db:test:purge' do # not on 2.3
|
163
163
|
begin
|
164
164
|
current_config(:config => ActiveRecord::Base.configurations['test'])
|
165
|
-
Rake::Task["structure:load"].invoke
|
165
|
+
Rake::Task["db:structure:load"].invoke
|
166
166
|
ensure
|
167
167
|
current_config(:config => nil)
|
168
168
|
end
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
# desc "Recreate the test database from a fresh structure.sql file"
|
172
172
|
redefine_task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ]
|
173
173
|
# same as on 3.2 - but this task gets changed on 2.3 by depending on :load_structure
|
@@ -197,7 +197,7 @@ namespace :db do
|
|
197
197
|
end
|
198
198
|
# only does (:purge => :environment) on AR < 3.2
|
199
199
|
task :purge => :load_config if Rake::Task.task_defined?(:load_config)
|
200
|
-
|
200
|
+
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
end
|
data/lib/arjdbc/version.rb
CHANGED
data/rakelib/02-test.rake
CHANGED
@@ -105,6 +105,15 @@ test_task_for 'JNDI', :desc => 'Run tests against a JNDI connection (uses Derby)
|
|
105
105
|
test_task.libs << 'jdbc-derby/lib'
|
106
106
|
end
|
107
107
|
|
108
|
+
test_task_for :MySQL, :name => 'test_jdbc_mysql',
|
109
|
+
:prereqs => 'db:mysql', :database_name => 'MySQL (using adapter: jdbc)' do |test_task|
|
110
|
+
test_task.ruby_opts << '-rdb/jdbc_mysql' # replaces require 'db/mysql'
|
111
|
+
end
|
112
|
+
test_task_for :PostgreSQL, :name => 'test_jdbc_postgresql', :driver => 'postgres',
|
113
|
+
:prereqs => 'db:postgresql', :database_name => 'PostgreSQL (using adapter: jdbc)' do |test_task|
|
114
|
+
test_task.ruby_opts << '-rdb/jdbc_postgres' # replaces require 'db/postgres'
|
115
|
+
end
|
116
|
+
|
108
117
|
# TODO Sybase testing is currently broken, please fix it if you're on Sybase :
|
109
118
|
#test_task_for :Sybase, :desc => "Run tests against Sybase (using jTDS driver)"
|
110
119
|
#task :test_sybase_jtds => :test_sybase # alias
|
@@ -29,6 +29,7 @@ import arjdbc.jdbc.RubyJdbcConnection;
|
|
29
29
|
import arjdbc.jdbc.Callable;
|
30
30
|
|
31
31
|
import java.lang.reflect.Field;
|
32
|
+
import java.lang.reflect.Proxy;
|
32
33
|
import java.sql.Connection;
|
33
34
|
import java.sql.PreparedStatement;
|
34
35
|
import java.sql.SQLException;
|
@@ -249,10 +250,13 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
249
250
|
if ( field != null ) {
|
250
251
|
java.util.Timer timer = null;
|
251
252
|
try {
|
253
|
+
Connection unwrap = connection.unwrap(Connection.class);
|
254
|
+
// when failover is used (LoadBalancedMySQLConnection)
|
255
|
+
// we'll end up with a proxy returned not the real thing :
|
256
|
+
if ( Proxy.isProxyClass(unwrap.getClass()) ) return;
|
252
257
|
// connection likely: com.mysql.jdbc.JDBC4Connection
|
253
258
|
// or (for 3.0) super class: com.mysql.jdbc.ConnectionImpl
|
254
|
-
timer = (java.util.Timer)
|
255
|
-
field.get( connection.unwrap(Connection.class) );
|
259
|
+
timer = (java.util.Timer) field.get( unwrap );
|
256
260
|
}
|
257
261
|
catch (SQLException e) {
|
258
262
|
debugMessage( e.toString() );
|
@@ -499,7 +499,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
499
499
|
}
|
500
500
|
|
501
501
|
if ( object instanceof Map ) { // hstore
|
502
|
-
if ( rawHstoreType ) {
|
502
|
+
if ( rawHstoreType == Boolean.TRUE ) {
|
503
503
|
return runtime.newString( resultSet.getString(column) );
|
504
504
|
}
|
505
505
|
// by default we avoid double parsing by driver and than column :
|
@@ -552,20 +552,25 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
552
552
|
return str.toString();
|
553
553
|
}
|
554
554
|
|
555
|
-
protected static
|
555
|
+
protected static Boolean rawHstoreType;
|
556
|
+
static {
|
557
|
+
final String hstoreRaw = System.getProperty("arjdbc.postgresql.hstore.raw");
|
558
|
+
if ( hstoreRaw != null ) rawHstoreType = Boolean.parseBoolean(hstoreRaw);
|
559
|
+
}
|
556
560
|
|
557
|
-
@JRubyMethod(name = "raw_hstore_type?")
|
561
|
+
@JRubyMethod(name = "raw_hstore_type?", meta = true)
|
558
562
|
public static IRubyObject useRawHstoreType(final ThreadContext context, final IRubyObject self) {
|
563
|
+
if ( rawHstoreType == null ) return context.getRuntime().getNil();
|
559
564
|
return context.getRuntime().newBoolean(rawHstoreType);
|
560
565
|
}
|
561
566
|
|
562
|
-
@JRubyMethod(name = "raw_hstore_type=")
|
567
|
+
@JRubyMethod(name = "raw_hstore_type=", meta = true)
|
563
568
|
public static IRubyObject setRawHstoreType(final IRubyObject self, final IRubyObject value) {
|
564
569
|
if ( value instanceof RubyBoolean ) {
|
565
|
-
rawHstoreType = ((RubyBoolean) value).isTrue();
|
570
|
+
rawHstoreType = ((RubyBoolean) value).isTrue() ? Boolean.TRUE : Boolean.FALSE;
|
566
571
|
}
|
567
572
|
else {
|
568
|
-
rawHstoreType =
|
573
|
+
rawHstoreType = value.isNil() ? null : Boolean.TRUE;
|
569
574
|
}
|
570
575
|
return value;
|
571
576
|
}
|
@@ -579,12 +584,12 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
579
584
|
// - -1 years -2 days
|
580
585
|
protected static boolean rawIntervalType = Boolean.getBoolean("arjdbc.postgresql.iterval.raw");
|
581
586
|
|
582
|
-
@JRubyMethod(name = "raw_interval_type?")
|
587
|
+
@JRubyMethod(name = "raw_interval_type?", meta = true)
|
583
588
|
public static IRubyObject useRawIntervalType(final ThreadContext context, final IRubyObject self) {
|
584
589
|
return context.getRuntime().newBoolean(rawIntervalType);
|
585
590
|
}
|
586
591
|
|
587
|
-
@JRubyMethod(name = "raw_interval_type=")
|
592
|
+
@JRubyMethod(name = "raw_interval_type=", meta = true)
|
588
593
|
public static IRubyObject setRawIntervalType(final IRubyObject self, final IRubyObject value) {
|
589
594
|
if ( value instanceof RubyBoolean ) {
|
590
595
|
rawIntervalType = ((RubyBoolean) value).isTrue();
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbc-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sieger, Ola Bini and JRuby contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/arjdbc/mssql/utils.rb
|
143
143
|
- lib/arjdbc/mysql.rb
|
144
144
|
- lib/arjdbc/mysql/adapter.rb
|
145
|
+
- lib/arjdbc/mysql/bulk_change_table.rb
|
145
146
|
- lib/arjdbc/mysql/column.rb
|
146
147
|
- lib/arjdbc/mysql/connection_methods.rb
|
147
148
|
- lib/arjdbc/mysql/explain_support.rb
|