activerecord-jdbc-adapter 1.0.0.beta2-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -8
- data/Manifest.txt +0 -6
- data/README.txt +9 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +17 -5
- data/lib/arjdbc/db2/adapter.rb +19 -9
- data/lib/arjdbc/discover.rb +0 -7
- data/lib/arjdbc/jdbc/adapter.rb +14 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/mysql/adapter.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +108 -142
- data/lib/arjdbc/sqlite3/connection_methods.rb +3 -2
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/compile.rake +2 -1
- data/test/db/db2.rb +4 -2
- data/test/db/jndi_config.rb +1 -1
- data/test/models/mixed_case.rb +7 -2
- data/test/postgres_mixed_case_test.rb +11 -1
- data/test/simple.rb +10 -1
- metadata +6 -15
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +0 -1
- data/lib/arjdbc/cachedb.rb +0 -3
- data/lib/arjdbc/cachedb/adapter.rb +0 -20
- data/lib/arjdbc/cachedb/connection_methods.rb +0 -10
- data/test/cachedb_simple_test.rb +0 -6
- data/test/db/cachedb.rb +0 -9
data/History.txt
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
- Thanks to David Kellum, Dmitry Denisov, Dwayne Litzenberger, Gregor
|
4
4
|
Schmidt, James Walker, John Duff, Joshua Suggs, Nicholas J Kreucher,
|
5
|
-
Peter Donald, Geoff Longman,
|
6
|
-
to this
|
5
|
+
Peter Donald, Geoff Longman, Uwe Kubosch, Youhei Kondou, Michael
|
6
|
+
Pitman, Alex B, and Ryan Bell for their contributions to this
|
7
|
+
release.
|
7
8
|
- BIG set of DB2 updates (Thanks Nick Kreucher)
|
8
9
|
- Deprecate jdbc_adapter/rake_tasks
|
9
10
|
- (1.0.0.beta1)
|
@@ -21,19 +22,19 @@
|
|
21
22
|
- JRUBY-1642: Don't use H2 INFORMATION_SCHEMA in table or column
|
22
23
|
searches
|
23
24
|
- JRUBY-4972: Attempt to deal with type(0)/:limit => 0 by not setting
|
24
|
-
it808e213
|
25
|
-
- JRUBY-
|
26
|
-
|
25
|
+
it808e213
|
26
|
+
- JRUBY-5040: Fix issue with limits on timestamps in MySQL
|
27
|
+
- JRUBY-3555: Allow setting Derby schema with 'schema:' option
|
28
|
+
- ACTIVERECORD_JDBC-98: Make sure we actuall raise an error when
|
27
29
|
inappropriately configured
|
28
30
|
- ACTIVERECORD_JDBC-112: Add schema dumper tests for already-fixed
|
29
31
|
MySQL type limits
|
30
|
-
- ACTIVERECORD_JDBC-113: Fix PG float precision
|
31
|
-
need M[ys]SQL escape hatch on case-sensitive test
|
32
|
+
- ACTIVERECORD_JDBC-113: Fix PG float precision issue
|
32
33
|
- ACTIVERECORD_JDBC-103: Fix decimal options for PG add/change column
|
33
34
|
(Michael Pitman)
|
34
35
|
- ACTIVERECORD_JDBC-127: Fix quoting of Date vs. Time(stamp) for
|
35
36
|
Oracle (Lenny Marks)
|
36
|
-
- Oracle: Sort out
|
37
|
+
- Oracle: Sort out the NUMBER vs NUMBER(x) vs NUMBER(x,y) situation.
|
37
38
|
- JRUBY-3051: Think we finally got the PG mixed-case patches applied.
|
38
39
|
- JRUBY-5081: Consolidate code for dropping DB via postgres
|
39
40
|
- ACTIVERECORD_JDBC-101: Add override of LONGVARCHAR => CLOB for
|
@@ -45,6 +46,10 @@
|
|
45
46
|
queries (alex b)
|
46
47
|
- ACTIVERECORD_JDBC-129: Don't have limits for text, binary or bit
|
47
48
|
fields
|
49
|
+
- (1.0.0 final)
|
50
|
+
- Fix a few more SQLite3 AR tests
|
51
|
+
- SQLite3: handle ":memory:" database
|
52
|
+
- Release new SQLite3 driver 3.6.14.2 and new Derby driver 10.6.2.1
|
48
53
|
|
49
54
|
== 0.9.7
|
50
55
|
|
data/Manifest.txt
CHANGED
@@ -7,7 +7,6 @@ lib/activerecord-jdbc-adapter.rb
|
|
7
7
|
lib/arjdbc.rb
|
8
8
|
lib/jdbc_adapter.rb
|
9
9
|
lib/pg.rb
|
10
|
-
lib/active_record/connection_adapters/cachedb_adapter.rb
|
11
10
|
lib/active_record/connection_adapters/derby_adapter.rb
|
12
11
|
lib/active_record/connection_adapters/h2_adapter.rb
|
13
12
|
lib/active_record/connection_adapters/hsqldb_adapter.rb
|
@@ -26,7 +25,6 @@ lib/arel/engines/sql/compilers/h2_compiler.rb
|
|
26
25
|
lib/arel/engines/sql/compilers/hsqldb_compiler.rb
|
27
26
|
lib/arel/engines/sql/compilers/jdbc_compiler.rb
|
28
27
|
lib/arel/engines/sql/compilers/mssql_compiler.rb
|
29
|
-
lib/arjdbc/cachedb.rb
|
30
28
|
lib/arjdbc/db2.rb
|
31
29
|
lib/arjdbc/derby.rb
|
32
30
|
lib/arjdbc/discover.rb
|
@@ -43,8 +41,6 @@ lib/arjdbc/postgresql.rb
|
|
43
41
|
lib/arjdbc/sqlite3.rb
|
44
42
|
lib/arjdbc/sybase.rb
|
45
43
|
lib/arjdbc/version.rb
|
46
|
-
lib/arjdbc/cachedb/adapter.rb
|
47
|
-
lib/arjdbc/cachedb/connection_methods.rb
|
48
44
|
lib/arjdbc/db2/adapter.rb
|
49
45
|
lib/arjdbc/derby/adapter.rb
|
50
46
|
lib/arjdbc/derby/connection_methods.rb
|
@@ -90,7 +86,6 @@ lib/jdbc_adapter/rake_tasks.rb
|
|
90
86
|
lib/jdbc_adapter/version.rb
|
91
87
|
lib/arjdbc/jdbc/adapter_java.jar
|
92
88
|
test/abstract_db_create.rb
|
93
|
-
test/cachedb_simple_test.rb
|
94
89
|
test/db2_simple_test.rb
|
95
90
|
test/derby_migration_test.rb
|
96
91
|
test/derby_multibyte_test.rb
|
@@ -132,7 +127,6 @@ test/sqlite3_simple_test.rb
|
|
132
127
|
test/sybase_jtds_simple_test.rb
|
133
128
|
test/activerecord/connection_adapters/type_conversion_test.rb
|
134
129
|
test/activerecord/connections/native_jdbc_mysql/connection.rb
|
135
|
-
test/db/cachedb.rb
|
136
130
|
test/db/db2.rb
|
137
131
|
test/db/derby.rb
|
138
132
|
test/db/h2.rb
|
data/README.txt
CHANGED
@@ -110,6 +110,15 @@ or like this (but requires that you manually put the driver jar on the classpath
|
|
110
110
|
:url => 'jdbc:derby:test_ar;create=true'
|
111
111
|
)
|
112
112
|
|
113
|
+
== Extending AR-JDBC
|
114
|
+
|
115
|
+
You can create your own extension to AR-JDBC for a JDBC-based database
|
116
|
+
that core AR-JDBC does not support. We've created an example project
|
117
|
+
for the Intersystems Cache database that you can examine as a
|
118
|
+
template. See the project for more information at the following URL:
|
119
|
+
|
120
|
+
http://github.com/nicksieger/activerecord-cachedb-adapter
|
121
|
+
|
113
122
|
== Getting the source
|
114
123
|
|
115
124
|
The source for activerecord-jdbc-adapter is available using git.
|
@@ -2,15 +2,27 @@ module Arel
|
|
2
2
|
module SqlCompiler
|
3
3
|
class MsSQLCompiler < GenericCompiler
|
4
4
|
def select_sql
|
5
|
-
|
6
|
-
|
5
|
+
projections = @relation.projections
|
7
6
|
offset = relation.skipped
|
8
7
|
limit = relation.taken
|
9
|
-
|
10
|
-
|
8
|
+
if Count === projections.first && projections.size == 1 &&
|
9
|
+
(relation.taken.present? || relation.wheres.present?) && relation.joins(self).blank?
|
10
|
+
subquery = [
|
11
|
+
"SELECT * FROM #{relation.from_clauses}", build_clauses
|
12
|
+
].join ' '
|
13
|
+
@engine.connection.add_limit_offset!(subquery, :limit => limit, :offset => offset) if offset || limit
|
14
|
+
query = "SELECT COUNT(*) AS count_id FROM (#{subquery}) AS subquery"
|
15
|
+
else
|
16
|
+
query = [
|
17
|
+
"SELECT #{relation.select_clauses.join(', ')}",
|
18
|
+
"FROM #{relation.from_clauses}",
|
19
|
+
build_clauses
|
20
|
+
].compact.join ' '
|
21
|
+
@engine.connection.add_limit_offset!(query, :limit => limit, :offset => offset) if offset || limit
|
22
|
+
end
|
11
23
|
query
|
12
24
|
end
|
13
|
-
|
25
|
+
|
14
26
|
def build_clauses
|
15
27
|
joins = relation.joins(self)
|
16
28
|
wheres = relation.where_clauses
|
data/lib/arjdbc/db2/adapter.rb
CHANGED
@@ -98,14 +98,24 @@ module ArJdbc
|
|
98
98
|
|
99
99
|
# holy moly batman! all this to tell AS400 "yes i am sure"
|
100
100
|
def execute_and_auto_confirm(sql)
|
101
|
-
@connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*SYSRPYL)',0000000031.00000)"
|
102
101
|
begin
|
102
|
+
@connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*SYSRPYL)',0000000031.00000)"
|
103
103
|
@connection.execute_update "call qsys.qcmdexc('ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY(''I'')',0000000045.00000)"
|
104
|
-
|
105
|
-
|
104
|
+
rescue Exception => e
|
105
|
+
raise "Could not call CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I').\n" +
|
106
|
+
"Do you have authority to do this?\n\n" + e.to_s
|
107
|
+
end
|
108
|
+
|
109
|
+
r = execute sql
|
110
|
+
|
111
|
+
begin
|
106
112
|
@connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*DFT)',0000000027.00000)"
|
107
|
-
@connection.execute_update "call qsys.qcmdexc('RMVRPYLE SEQNBR(9876)',0000000021.00000)
|
113
|
+
@connection.execute_update "call qsys.qcmdexc('RMVRPYLE SEQNBR(9876)',0000000021.00000)"
|
114
|
+
rescue Exception => e
|
115
|
+
raise "Could not call CHGJOB INQMSGRPY(*DFT) and RMVRPYLE SEQNBR(9876).\n" +
|
116
|
+
"Do you have authority to do this?\n\n" + e.to_s
|
108
117
|
end
|
118
|
+
r
|
109
119
|
end
|
110
120
|
|
111
121
|
def last_insert_id(sql)
|
@@ -214,18 +224,18 @@ um <= #{sanitize_limit(limit) + offset}"
|
|
214
224
|
|
215
225
|
def change_column_null(table_name, column_name, null)
|
216
226
|
if null
|
217
|
-
|
227
|
+
execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP NOT NULL"
|
218
228
|
else
|
219
|
-
|
229
|
+
execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET NOT NULL"
|
220
230
|
end
|
221
231
|
reorg_table(table_name)
|
222
232
|
end
|
223
233
|
|
224
234
|
def change_column_default(table_name, column_name, default)
|
225
235
|
if default.nil?
|
226
|
-
|
236
|
+
execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP DEFAULT"
|
227
237
|
else
|
228
|
-
|
238
|
+
execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET WITH DEFAULT #{quote(default)}"
|
229
239
|
end
|
230
240
|
reorg_table(table_name)
|
231
241
|
end
|
@@ -263,7 +273,7 @@ um <= #{sanitize_limit(limit) + offset}"
|
|
263
273
|
# http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0000980.html
|
264
274
|
def rename_table(name, new_name) #:nodoc:
|
265
275
|
execute "RENAME TABLE #{name} TO #{new_name}"
|
266
|
-
reorg_table(
|
276
|
+
reorg_table(new_name)
|
267
277
|
end
|
268
278
|
|
269
279
|
def tables
|
data/lib/arjdbc/discover.rb
CHANGED
@@ -20,13 +20,6 @@ module ::ArJdbc
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# Other adapters are lazy-loaded
|
23
|
-
extension :CacheDB do |name|
|
24
|
-
if name =~ /cache/i
|
25
|
-
require 'arjdbc/cachedb'
|
26
|
-
true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
23
|
extension :DB2 do |name, config|
|
31
24
|
if name =~ /(db2|as400)/i && config[:url] !~ /^jdbc:derby:net:/
|
32
25
|
require 'arjdbc/db2'
|
data/lib/arjdbc/jdbc/adapter.rb
CHANGED
@@ -32,6 +32,7 @@ module ActiveRecord
|
|
32
32
|
end
|
33
33
|
super(connection, logger)
|
34
34
|
extend spec if spec
|
35
|
+
configure_arel2_visitors
|
35
36
|
connection.adapter = self
|
36
37
|
JndiConnectionPoolCallbacks.prepare(self, connection)
|
37
38
|
end
|
@@ -88,6 +89,19 @@ module ActiveRecord
|
|
88
89
|
'JDBC'
|
89
90
|
end
|
90
91
|
|
92
|
+
def arel2_visitors
|
93
|
+
{}
|
94
|
+
end
|
95
|
+
|
96
|
+
def configure_arel2_visitors
|
97
|
+
if defined?(::Arel::Visitors::VISITORS)
|
98
|
+
visitors = ::Arel::Visitors::VISITORS
|
99
|
+
arel2_visitors.each do |k,v|
|
100
|
+
visitors[k] = v unless visitors.has_key?(k)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
91
105
|
def is_a?(klass) # :nodoc:
|
92
106
|
# This is to fake out current_adapter? conditional logic in AR tests
|
93
107
|
if Class === klass && klass.name =~ /#{adapter_name}Adapter$/i
|
Binary file
|
data/lib/arjdbc/mysql/adapter.rb
CHANGED
@@ -23,26 +23,11 @@ module ::ArJdbc
|
|
23
23
|
return nil if value.nil?
|
24
24
|
case type
|
25
25
|
when :string then value
|
26
|
-
when :integer then ArJdbc::SQLite3::Column.cast_to_integer(value)
|
27
26
|
when :primary_key then defined?(value.to_i) ? value.to_i : (value ? 1 : 0)
|
28
27
|
when :float then value.to_f
|
29
|
-
when :datetime then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
|
30
|
-
when :date then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
|
31
|
-
when :time then ArJdbc::SQLite3::Column.cast_to_time(value)
|
32
28
|
when :decimal then self.class.value_to_decimal(value)
|
33
29
|
when :boolean then self.class.value_to_boolean(value)
|
34
|
-
else
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def type_cast_code(var_name)
|
39
|
-
case type
|
40
|
-
when :integer then "ArJdbc::SQLite3::Column.cast_to_integer(#{var_name})"
|
41
|
-
when :datetime then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
|
42
|
-
when :date then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
|
43
|
-
when :time then "ArJdbc::SQLite3::Column.cast_to_time(#{var_name})"
|
44
|
-
else
|
45
|
-
super
|
30
|
+
else super
|
46
31
|
end
|
47
32
|
end
|
48
33
|
|
@@ -84,35 +69,16 @@ module ::ArJdbc
|
|
84
69
|
|
85
70
|
value
|
86
71
|
end
|
87
|
-
|
88
|
-
def self.cast_to_integer(value)
|
89
|
-
return nil if value =~ /NULL/ or value.to_s.empty? or value.nil?
|
90
|
-
return (value.to_i) ? value.to_i : (value ? 1 : 0)
|
91
|
-
end
|
92
|
-
|
93
|
-
def self.cast_to_date_or_time(value)
|
94
|
-
return value if value.is_a? Date
|
95
|
-
return nil if value.blank?
|
96
|
-
guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value))
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.cast_to_time(value)
|
100
|
-
return value if value.is_a? Time
|
101
|
-
time_array = ParseDate.parsedate value
|
102
|
-
time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
|
103
|
-
Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.guess_date_or_time(value)
|
107
|
-
(value.hour == 0 and value.min == 0 and value.sec == 0) ?
|
108
|
-
Date.new(value.year, value.month, value.day) : value
|
109
|
-
end
|
110
72
|
end
|
111
73
|
|
112
74
|
def adapter_name #:nodoc:
|
113
75
|
'SQLite'
|
114
76
|
end
|
115
77
|
|
78
|
+
def supports_add_column?
|
79
|
+
sqlite_version >= '3.1.6'
|
80
|
+
end
|
81
|
+
|
116
82
|
def supports_count_distinct? #:nodoc:
|
117
83
|
sqlite_version >= '3.2.6'
|
118
84
|
end
|
@@ -135,26 +101,10 @@ module ::ArJdbc
|
|
135
101
|
tp[:time] = { :name => "TIME" }
|
136
102
|
tp[:date] = { :name => "DATE" }
|
137
103
|
tp[:boolean] = { :name => "BOOLEAN" }
|
104
|
+
tp[:binary] = { :name => "BLOB" }
|
138
105
|
tp
|
139
106
|
end
|
140
107
|
|
141
|
-
def quote(value, column = nil) # :nodoc:
|
142
|
-
return value.quoted_id if value.respond_to?(:quoted_id)
|
143
|
-
case value
|
144
|
-
when String
|
145
|
-
if column && column.type == :binary
|
146
|
-
"'#{quote_string(column.class.string_to_binary(value))}'"
|
147
|
-
elsif column && [:integer, :float].include?(column.type)
|
148
|
-
(column.type == :integer ? value.to_i : value.to_f).to_s
|
149
|
-
elsif column && column.respond_to?(:primary) && column.primary && column.klass != String
|
150
|
-
value.to_i.to_s
|
151
|
-
else
|
152
|
-
"'#{quote_string(value)}'"
|
153
|
-
end
|
154
|
-
else super
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
108
|
def quote_column_name(name) #:nodoc:
|
159
109
|
%Q("#{name}")
|
160
110
|
end
|
@@ -171,56 +121,6 @@ module ::ArJdbc
|
|
171
121
|
%Q{'f'}
|
172
122
|
end
|
173
123
|
|
174
|
-
def add_column(table_name, column_name, type, options = {})
|
175
|
-
if option_not_null = options[:null] == false
|
176
|
-
option_not_null = options.delete(:null)
|
177
|
-
end
|
178
|
-
add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
|
179
|
-
add_column_options!(add_column_sql, options)
|
180
|
-
execute(add_column_sql)
|
181
|
-
if option_not_null
|
182
|
-
alter_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ALTER #{quote_column_name(column_name)} NOT NULL"
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def remove_column(table_name, *column_names) #:nodoc:
|
187
|
-
column_names.flatten.each do |column_name|
|
188
|
-
alter_table(table_name) do |definition|
|
189
|
-
definition.columns.delete(definition[column_name])
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
alias :remove_columns :remove_column
|
194
|
-
|
195
|
-
def change_column(table_name, column_name, type, options = {}) #:nodoc:
|
196
|
-
alter_table(table_name) do |definition|
|
197
|
-
include_default = options_include_default?(options)
|
198
|
-
definition[column_name].instance_eval do
|
199
|
-
self.type = type
|
200
|
-
self.limit = options[:limit] if options.include?(:limit)
|
201
|
-
self.default = options[:default] if include_default
|
202
|
-
self.null = options[:null] if options.include?(:null)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
def change_column_default(table_name, column_name, default) #:nodoc:
|
208
|
-
alter_table(table_name) do |definition|
|
209
|
-
definition[column_name].default = default
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def rename_column(table_name, column_name, new_column_name) #:nodoc:
|
214
|
-
unless columns(table_name).detect{|c| c.name == column_name.to_s }
|
215
|
-
raise ActiveRecord::ActiveRecordError, "Missing column #{table_name}.#{column_name}"
|
216
|
-
end
|
217
|
-
alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s})
|
218
|
-
end
|
219
|
-
|
220
|
-
def rename_table(name, new_name)
|
221
|
-
execute "ALTER TABLE #{name} RENAME TO #{new_name}"
|
222
|
-
end
|
223
|
-
|
224
124
|
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
|
225
125
|
@connection.execute_update(sql)
|
226
126
|
id_value || last_insert_id
|
@@ -294,15 +194,94 @@ module ::ArJdbc
|
|
294
194
|
|
295
195
|
def columns(table_name, name = nil) #:nodoc:
|
296
196
|
table_structure(table_name).map do |field|
|
297
|
-
::ActiveRecord::ConnectionAdapters::
|
197
|
+
::ActiveRecord::ConnectionAdapters::SQLite3Column.new(@config, field['name'], field['dflt_value'], field['type'], field['notnull'] == 0)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def primary_key(table_name) #:nodoc:
|
202
|
+
column = table_structure(table_name).find { |field|
|
203
|
+
field['pk'].to_i == 1
|
204
|
+
}
|
205
|
+
column && column['name']
|
206
|
+
end
|
207
|
+
|
208
|
+
def remove_index!(table_name, index_name) #:nodoc:
|
209
|
+
execute "DROP INDEX #{quote_column_name(index_name)}"
|
210
|
+
end
|
211
|
+
|
212
|
+
def rename_table(name, new_name)
|
213
|
+
execute "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}"
|
214
|
+
end
|
215
|
+
|
216
|
+
# See: http://www.sqlite.org/lang_altertable.html
|
217
|
+
# SQLite has an additional restriction on the ALTER TABLE statement
|
218
|
+
def valid_alter_table_options( type, options)
|
219
|
+
type.to_sym != :primary_key
|
220
|
+
end
|
221
|
+
|
222
|
+
def add_column(table_name, column_name, type, options = {}) #:nodoc:
|
223
|
+
if supports_add_column? && valid_alter_table_options( type, options )
|
224
|
+
super(table_name, column_name, type, options)
|
225
|
+
else
|
226
|
+
alter_table(table_name) do |definition|
|
227
|
+
definition.column(column_name, type, options)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def remove_column(table_name, *column_names) #:nodoc:
|
233
|
+
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
|
234
|
+
column_names.flatten.each do |column_name|
|
235
|
+
alter_table(table_name) do |definition|
|
236
|
+
definition.columns.delete(definition[column_name])
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
alias :remove_columns :remove_column
|
241
|
+
|
242
|
+
def change_column_default(table_name, column_name, default) #:nodoc:
|
243
|
+
alter_table(table_name) do |definition|
|
244
|
+
definition[column_name].default = default
|
298
245
|
end
|
299
246
|
end
|
300
247
|
|
248
|
+
def change_column_null(table_name, column_name, null, default = nil)
|
249
|
+
unless null || default.nil?
|
250
|
+
execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
|
251
|
+
end
|
252
|
+
alter_table(table_name) do |definition|
|
253
|
+
definition[column_name].null = null
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def change_column(table_name, column_name, type, options = {}) #:nodoc:
|
258
|
+
alter_table(table_name) do |definition|
|
259
|
+
include_default = options_include_default?(options)
|
260
|
+
definition[column_name].instance_eval do
|
261
|
+
self.type = type
|
262
|
+
self.limit = options[:limit] if options.include?(:limit)
|
263
|
+
self.default = options[:default] if include_default
|
264
|
+
self.null = options[:null] if options.include?(:null)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def rename_column(table_name, column_name, new_column_name) #:nodoc:
|
270
|
+
unless columns(table_name).detect{|c| c.name == column_name.to_s }
|
271
|
+
raise ActiveRecord::ActiveRecordError, "Missing column #{table_name}.#{column_name}"
|
272
|
+
end
|
273
|
+
alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s})
|
274
|
+
end
|
275
|
+
|
301
276
|
# SELECT ... FOR UPDATE is redundant since the table is locked.
|
302
277
|
def add_lock!(sql, options) #:nodoc:
|
303
278
|
sql
|
304
279
|
end
|
305
280
|
|
281
|
+
def empty_insert_statement_value
|
282
|
+
"VALUES(NULL)"
|
283
|
+
end
|
284
|
+
|
306
285
|
protected
|
307
286
|
include ArJdbc::MissingFunctionalityHelper
|
308
287
|
|
@@ -318,7 +297,7 @@ module ::ArJdbc
|
|
318
297
|
end
|
319
298
|
|
320
299
|
module ActiveRecord::ConnectionAdapters
|
321
|
-
class
|
300
|
+
class SQLite3Column < JdbcColumn
|
322
301
|
include ArJdbc::SQLite3::Column
|
323
302
|
|
324
303
|
def initialize(name, *args)
|
@@ -333,44 +312,19 @@ module ActiveRecord::ConnectionAdapters
|
|
333
312
|
end
|
334
313
|
|
335
314
|
def self.string_to_binary(value)
|
336
|
-
value.
|
337
|
-
case b
|
338
|
-
when "\0" then "%00"
|
339
|
-
when "\%" then "%25"
|
340
|
-
end
|
341
|
-
end
|
315
|
+
"\000b64" + [value].pack('m*').split("\n").join('')
|
342
316
|
end
|
343
317
|
|
344
318
|
def self.binary_to_string(value)
|
345
|
-
value.
|
346
|
-
|
347
|
-
when "%00" then "\0"
|
348
|
-
when "%25" then "%"
|
349
|
-
end
|
319
|
+
if value.respond_to?(:force_encoding) && value.encoding != Encoding::ASCII_8BIT
|
320
|
+
value = value.force_encoding(Encoding::ASCII_8BIT)
|
350
321
|
end
|
351
|
-
end
|
352
|
-
|
353
|
-
def self.cast_to_integer(value)
|
354
|
-
return nil if value =~ /NULL/ or value.to_s.empty? or value.nil?
|
355
|
-
return (value.to_i) ? value.to_i : (value ? 1 : 0)
|
356
|
-
end
|
357
|
-
|
358
|
-
def self.cast_to_date_or_time(value)
|
359
|
-
return value if value.is_a? Date
|
360
|
-
return nil if value.blank?
|
361
|
-
guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value))
|
362
|
-
end
|
363
|
-
|
364
|
-
def self.cast_to_time(value)
|
365
|
-
return value if value.is_a? Time
|
366
|
-
time_array = ParseDate.parsedate value
|
367
|
-
time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
|
368
|
-
Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
|
369
|
-
end
|
370
322
|
|
371
|
-
|
372
|
-
|
373
|
-
|
323
|
+
if value[0..3] == "\000b64"
|
324
|
+
value[4..-1].unpack('m*').first
|
325
|
+
else
|
326
|
+
value
|
327
|
+
end
|
374
328
|
end
|
375
329
|
end
|
376
330
|
|
@@ -381,8 +335,20 @@ module ActiveRecord::ConnectionAdapters
|
|
381
335
|
# return nil to avoid extending ArJdbc::SQLite3, which we've already done
|
382
336
|
end
|
383
337
|
|
338
|
+
def jdbc_connection_class(spec)
|
339
|
+
ArJdbc::SQLite3.jdbc_connection_class
|
340
|
+
end
|
341
|
+
|
384
342
|
def jdbc_column_class
|
385
|
-
ActiveRecord::ConnectionAdapters::
|
343
|
+
ActiveRecord::ConnectionAdapters::SQLite3Column
|
386
344
|
end
|
387
345
|
end
|
388
346
|
end
|
347
|
+
|
348
|
+
# Fake out sqlite3/version driver for AR tests
|
349
|
+
$LOADED_FEATURES << 'sqlite3/version.rb'
|
350
|
+
module SQLite3
|
351
|
+
module Version
|
352
|
+
VERSION = '1.2.6' # query_cache_test.rb requires SQLite3::Version::VERSION > '1.2.5'
|
353
|
+
end
|
354
|
+
end
|
@@ -8,8 +8,9 @@ class ActiveRecord::Base
|
|
8
8
|
require "arjdbc/sqlite3"
|
9
9
|
|
10
10
|
parse_sqlite3_config!(config)
|
11
|
-
|
12
|
-
|
11
|
+
database = config[:database]
|
12
|
+
database = '' if database == ':memory:'
|
13
|
+
config[:url] ||= "jdbc:sqlite:#{database}"
|
13
14
|
config[:driver] ||= "org.sqlite.JDBC"
|
14
15
|
config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
15
16
|
jdbc_connection(config)
|
data/lib/arjdbc/version.rb
CHANGED
data/rakelib/compile.rake
CHANGED
@@ -16,9 +16,10 @@ jar_name = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
|
|
16
16
|
|
17
17
|
desc "Compile the native Java code."
|
18
18
|
task :java_compile do
|
19
|
+
debug = ENV['DEBUG'] ? '-g' : ''
|
19
20
|
pkg_classes = File.join(*%w(pkg classes))
|
20
21
|
mkdir_p pkg_classes
|
21
|
-
sh "javac -target 1.5 -source 1.5 -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
22
|
+
sh "javac -target 1.5 -source 1.5 #{debug} -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
22
23
|
sh "jar cf #{jar_name} -C #{pkg_classes} ."
|
23
24
|
end
|
24
25
|
file jar_name => :java_compile
|
data/test/db/db2.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
config = {
|
2
|
-
|
3
|
-
|
2
|
+
# DB2 uses $USER if running locally, just add
|
3
|
+
# yourself to your db2 groups in /etc/group
|
4
|
+
# :username => "blog",
|
5
|
+
# :password => "",
|
4
6
|
:adapter => "jdbc",
|
5
7
|
:driver => "com.ibm.db2.jcc.DB2Driver",
|
6
8
|
:url => "jdbc:db2:weblog_development"
|
data/test/db/jndi_config.rb
CHANGED
@@ -31,7 +31,7 @@ System.set_property(Context::PROVIDER_URL, "file://#{jndi_dir}")
|
|
31
31
|
ic = InitialContext.new
|
32
32
|
ic.rebind(JNDI_CONFIG[:jndi],
|
33
33
|
org.apache.derby.jdbc.EmbeddedDataSource.new.tap {|ds|
|
34
|
-
ds.database_name = "derby-testdb"
|
34
|
+
ds.database_name = "derby-testdb-jndi"
|
35
35
|
ds.create_database = "create"
|
36
36
|
ds.user = "sa"
|
37
37
|
ds.password = ""})
|
data/test/models/mixed_case.rb
CHANGED
@@ -3,15 +3,20 @@ require 'active_record'
|
|
3
3
|
|
4
4
|
module Migration
|
5
5
|
class MixedCase < ActiveRecord::Migration
|
6
|
-
|
6
|
+
|
7
7
|
def self.up
|
8
8
|
create_table "mixed_cases" do |t|
|
9
9
|
t.column :SOME_value, :string
|
10
10
|
end
|
11
|
+
create_table "tblUsers" do |t|
|
12
|
+
t.column :firstName, :string
|
13
|
+
t.column :lastName, :string
|
14
|
+
end
|
11
15
|
end
|
12
|
-
|
16
|
+
|
13
17
|
def self.down
|
14
18
|
drop_table "mixed_cases"
|
19
|
+
drop_table "tblUsers"
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
require 'jdbc_common'
|
2
|
+
require 'models/entry'
|
2
3
|
require 'models/mixed_case'
|
3
4
|
|
4
5
|
class MixedCaseTest < Test::Unit::TestCase
|
5
|
-
|
6
6
|
def setup
|
7
7
|
Migration::MixedCase.up
|
8
|
+
@table_name = User.table_name
|
9
|
+
User.table_name = 'tblUsers'
|
10
|
+
User.reset_column_information
|
8
11
|
end
|
9
12
|
|
10
13
|
def teardown
|
14
|
+
User.table_name = @table_name
|
15
|
+
User.reset_column_information
|
11
16
|
Migration::MixedCase.down
|
12
17
|
end
|
13
18
|
|
@@ -16,4 +21,9 @@ class MixedCaseTest < Test::Unit::TestCase
|
|
16
21
|
assert_equal 'some value', mixed_case.SOME_value
|
17
22
|
end
|
18
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
|
19
29
|
end
|
data/test/simple.rb
CHANGED
@@ -111,6 +111,16 @@ module SimpleTestMethods
|
|
111
111
|
assert_equal prev_count - 1, Entry.count
|
112
112
|
end
|
113
113
|
|
114
|
+
if Entry.respond_to?(:limit)
|
115
|
+
def test_limit
|
116
|
+
Entry.limit(10).to_a
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_count_with_limit
|
120
|
+
assert_equal Entry.count, Entry.limit(10).count
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
114
124
|
if Time.respond_to?(:zone)
|
115
125
|
def test_save_time_with_utc
|
116
126
|
current_zone = Time.zone
|
@@ -241,7 +251,6 @@ module SimpleTestMethods
|
|
241
251
|
binary_string = "\000ABCDEFGHIJKLMNOPQRSTUVWXYZ'\001\003"*1#2_000
|
242
252
|
e = DbType.find(:first)
|
243
253
|
e.sample_binary = binary_string
|
244
|
-
e.send(:write_attribute, :binary, binary_string)
|
245
254
|
e.save!
|
246
255
|
e = DbType.find(:first)
|
247
256
|
assert_equal binary_string, e.sample_binary
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbc-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0.beta2
|
9
|
+
version: 1.0.0
|
11
10
|
platform: java
|
12
11
|
authors:
|
13
12
|
- Nick Sieger, Ola Bini and JRuby contributors
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-10-14 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -72,7 +71,6 @@ files:
|
|
72
71
|
- lib/arjdbc.rb
|
73
72
|
- lib/jdbc_adapter.rb
|
74
73
|
- lib/pg.rb
|
75
|
-
- lib/active_record/connection_adapters/cachedb_adapter.rb
|
76
74
|
- lib/active_record/connection_adapters/derby_adapter.rb
|
77
75
|
- lib/active_record/connection_adapters/h2_adapter.rb
|
78
76
|
- lib/active_record/connection_adapters/hsqldb_adapter.rb
|
@@ -91,7 +89,6 @@ files:
|
|
91
89
|
- lib/arel/engines/sql/compilers/hsqldb_compiler.rb
|
92
90
|
- lib/arel/engines/sql/compilers/jdbc_compiler.rb
|
93
91
|
- lib/arel/engines/sql/compilers/mssql_compiler.rb
|
94
|
-
- lib/arjdbc/cachedb.rb
|
95
92
|
- lib/arjdbc/db2.rb
|
96
93
|
- lib/arjdbc/derby.rb
|
97
94
|
- lib/arjdbc/discover.rb
|
@@ -108,8 +105,6 @@ files:
|
|
108
105
|
- lib/arjdbc/sqlite3.rb
|
109
106
|
- lib/arjdbc/sybase.rb
|
110
107
|
- lib/arjdbc/version.rb
|
111
|
-
- lib/arjdbc/cachedb/adapter.rb
|
112
|
-
- lib/arjdbc/cachedb/connection_methods.rb
|
113
108
|
- lib/arjdbc/db2/adapter.rb
|
114
109
|
- lib/arjdbc/derby/adapter.rb
|
115
110
|
- lib/arjdbc/derby/connection_methods.rb
|
@@ -155,7 +150,6 @@ files:
|
|
155
150
|
- lib/jdbc_adapter/version.rb
|
156
151
|
- lib/arjdbc/jdbc/adapter_java.jar
|
157
152
|
- test/abstract_db_create.rb
|
158
|
-
- test/cachedb_simple_test.rb
|
159
153
|
- test/db2_simple_test.rb
|
160
154
|
- test/derby_migration_test.rb
|
161
155
|
- test/derby_multibyte_test.rb
|
@@ -197,7 +191,6 @@ files:
|
|
197
191
|
- test/sybase_jtds_simple_test.rb
|
198
192
|
- test/activerecord/connection_adapters/type_conversion_test.rb
|
199
193
|
- test/activerecord/connections/native_jdbc_mysql/connection.rb
|
200
|
-
- test/db/cachedb.rb
|
201
194
|
- test/db/db2.rb
|
202
195
|
- test/db/derby.rb
|
203
196
|
- test/db/h2.rb
|
@@ -262,13 +255,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
262
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
263
256
|
none: false
|
264
257
|
requirements:
|
265
|
-
- - "
|
258
|
+
- - ">="
|
266
259
|
- !ruby/object:Gem::Version
|
267
260
|
segments:
|
268
|
-
-
|
269
|
-
|
270
|
-
- 1
|
271
|
-
version: 1.3.1
|
261
|
+
- 0
|
262
|
+
version: "0"
|
272
263
|
requirements: []
|
273
264
|
|
274
265
|
rubyforge_project: jruby-extras
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'arjdbc/cachedb'
|
data/lib/arjdbc/cachedb.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'arjdbc/mssql/tsql_helper'
|
2
|
-
|
3
|
-
module ::ArJdbc
|
4
|
-
module CacheDB
|
5
|
-
include TSqlMethods
|
6
|
-
|
7
|
-
def self.column_selector
|
8
|
-
[ /cache/i, lambda { | cfg, col | col.extend( ::ArJdbc::CacheDB::Column ) } ]
|
9
|
-
end
|
10
|
-
|
11
|
-
module Column
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_table(name, options = { })
|
15
|
-
super(name, options)
|
16
|
-
primary_key = options[:primary_key] || "id"
|
17
|
-
execute "ALTER TABLE #{name} ADD CONSTRAINT #{name}_PK PRIMARY KEY(#{primary_key})" unless options[:id] == false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class ActiveRecord::Base
|
2
|
-
class << self
|
3
|
-
def cachedb_connection( config )
|
4
|
-
config[:port] ||= 1972
|
5
|
-
config[:url] ||= "jdbc:Cache://#{config[:host]}:#{config[:port]}/#{ config[:database]}"
|
6
|
-
config[:driver] ||= "com.intersys.jdbc.CacheDriver"
|
7
|
-
jdbc_connection(config)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/test/cachedb_simple_test.rb
DELETED
data/test/db/cachedb.rb
DELETED