activerecord-jdbc-adapter 1.0.1-java → 1.0.2-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 +6 -0
- data/lib/arjdbc/db2/adapter.rb +6 -1
- data/lib/arjdbc/derby/adapter.rb +23 -107
- data/lib/arjdbc/discover.rb +1 -1
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/mssql/adapter.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +10 -1
- data/lib/arjdbc/sqlite3/adapter.rb +6 -1
- data/lib/arjdbc/version.rb +1 -1
- data/test/postgres_simple_test.rb +21 -0
- metadata +5 -5
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 1.0.2
|
2
|
+
|
3
|
+
- ACTIVERECORD_JDBC-134: Fix conflicting adapter/column superclasses
|
4
|
+
- ACTIVERECORD_JDBC-135: Fix regression on PG with boolean and :limit
|
5
|
+
- Slew of Derby fixes courtesy of Denis Odorcic
|
6
|
+
|
1
7
|
== 1.0.1
|
2
8
|
|
3
9
|
- Fix db:test:purge issue affecting all adapters in 1.0.0 due to
|
data/lib/arjdbc/db2/adapter.rb
CHANGED
@@ -129,11 +129,16 @@ module ArJdbc
|
|
129
129
|
def modify_types(tp)
|
130
130
|
tp[:primary_key] = 'int not null generated by default as identity (start with 1) primary key'
|
131
131
|
tp[:string][:limit] = 255
|
132
|
-
tp[:integer]
|
132
|
+
tp[:integer][:limit] = nil
|
133
133
|
tp[:boolean] = {:name => "smallint"}
|
134
134
|
tp
|
135
135
|
end
|
136
136
|
|
137
|
+
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
|
138
|
+
limit = nil if type.to_sym == :integer
|
139
|
+
super(type, limit, precision, scale)
|
140
|
+
end
|
141
|
+
|
137
142
|
def adapter_name
|
138
143
|
'DB2'
|
139
144
|
end
|
data/lib/arjdbc/derby/adapter.rb
CHANGED
@@ -61,10 +61,14 @@ module ::ArJdbc
|
|
61
61
|
128
|
62
62
|
end
|
63
63
|
|
64
|
-
# Convert the
|
65
|
-
# a limit
|
64
|
+
# Convert the specified column type to a SQL string.
|
65
|
+
# In Derby, the following cannot specify a limit:
|
66
|
+
# - integer
|
67
|
+
# - boolean (smallint)
|
68
|
+
# - timestamp
|
69
|
+
# - date
|
66
70
|
def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
|
67
|
-
return super unless
|
71
|
+
return super unless [:integer, :boolean, :timestamp, :date].include? type
|
68
72
|
|
69
73
|
native = native_database_types[type.to_s.downcase.to_sym]
|
70
74
|
native.is_a?(Hash) ? native[:name] : native
|
@@ -72,9 +76,11 @@ module ::ArJdbc
|
|
72
76
|
|
73
77
|
def modify_types(tp)
|
74
78
|
tp[:primary_key] = "int generated by default as identity NOT NULL PRIMARY KEY"
|
75
|
-
tp[:integer][:limit] = nil
|
76
79
|
tp[:string][:limit] = 256
|
80
|
+
tp[:integer][:limit] = nil
|
77
81
|
tp[:boolean] = {:name => "smallint"}
|
82
|
+
tp[:timestamp][:limit] = nil
|
83
|
+
tp[:date][:limit] = nil
|
78
84
|
tp
|
79
85
|
end
|
80
86
|
|
@@ -82,6 +88,7 @@ module ::ArJdbc
|
|
82
88
|
def add_column_options!(sql, options)
|
83
89
|
options.delete(:default) if options.has_key?(:default) && options[:default].nil?
|
84
90
|
options.delete(:null) if options.has_key?(:null) && (options[:null].nil? || options[:null] == true)
|
91
|
+
sql << " DEFAULT #{quote(options.delete(:default))}" if options.has_key?(:default)
|
85
92
|
super
|
86
93
|
end
|
87
94
|
|
@@ -109,14 +116,9 @@ module ::ArJdbc
|
|
109
116
|
end
|
110
117
|
|
111
118
|
def rename_table(name, new_name)
|
112
|
-
execute "RENAME TABLE #{name} TO #{new_name}"
|
119
|
+
execute "RENAME TABLE #{quote_table_name(name)} TO #{quote_table_name(new_name)}"
|
113
120
|
end
|
114
121
|
|
115
|
-
COLUMN_INFO_STMT = "SELECT C.COLUMNNAME, C.REFERENCEID, C.COLUMNNUMBER FROM SYS.SYSCOLUMNS C, SYS.SYSTABLES T WHERE T.TABLEID = '%s' AND T.TABLEID = C.REFERENCEID ORDER BY C.COLUMNNUMBER"
|
116
|
-
|
117
|
-
COLUMN_TYPE_STMT = "SELECT COLUMNDATATYPE, COLUMNDEFAULT FROM SYS.SYSCOLUMNS WHERE REFERENCEID = '%s' AND COLUMNNAME = '%s'"
|
118
|
-
|
119
|
-
AUTO_INC_STMT = "SELECT AUTOINCREMENTSTART, AUTOINCREMENTINC, COLUMNNAME, REFERENCEID, COLUMNDEFAULT FROM SYS.SYSCOLUMNS WHERE REFERENCEID = '%s' AND COLUMNNAME = '%s'"
|
120
122
|
AUTO_INC_STMT2 = "SELECT AUTOINCREMENTSTART, AUTOINCREMENTINC, COLUMNNAME, REFERENCEID, COLUMNDEFAULT FROM SYS.SYSCOLUMNS WHERE REFERENCEID = (SELECT T.TABLEID FROM SYS.SYSTABLES T WHERE T.TABLENAME = '%s') AND COLUMNNAME = '%s'"
|
121
123
|
|
122
124
|
def add_quotes(name)
|
@@ -135,42 +137,6 @@ module ::ArJdbc
|
|
135
137
|
name.gsub(/"/,'""')
|
136
138
|
end
|
137
139
|
|
138
|
-
def reinstate_auto_increment(name, refid, coldef)
|
139
|
-
stmt = AUTO_INC_STMT % [refid, strip_quotes(name)]
|
140
|
-
data = execute(stmt).first
|
141
|
-
if data
|
142
|
-
start = data['autoincrementstart']
|
143
|
-
if start
|
144
|
-
coldef << " GENERATED " << (data['columndefault'].nil? ? "ALWAYS" : "BY DEFAULT ")
|
145
|
-
coldef << "AS IDENTITY (START WITH "
|
146
|
-
coldef << start
|
147
|
-
coldef << ", INCREMENT BY "
|
148
|
-
coldef << data['autoincrementinc']
|
149
|
-
coldef << ")"
|
150
|
-
return true
|
151
|
-
end
|
152
|
-
end
|
153
|
-
false
|
154
|
-
end
|
155
|
-
|
156
|
-
def reinstate_auto_increment(name, refid, coldef)
|
157
|
-
stmt = AUTO_INC_STMT % [refid, strip_quotes(name)]
|
158
|
-
data = execute(stmt).first
|
159
|
-
if data
|
160
|
-
start = data['autoincrementstart']
|
161
|
-
if start
|
162
|
-
coldef << " GENERATED " << (data['columndefault'].nil? ? "ALWAYS" : "BY DEFAULT ")
|
163
|
-
coldef << "AS IDENTITY (START WITH "
|
164
|
-
coldef << start
|
165
|
-
coldef << ", INCREMENT BY "
|
166
|
-
coldef << data['autoincrementinc']
|
167
|
-
coldef << ")"
|
168
|
-
return true
|
169
|
-
end
|
170
|
-
end
|
171
|
-
false
|
172
|
-
end
|
173
|
-
|
174
140
|
def auto_increment_stmt(tname, cname)
|
175
141
|
stmt = AUTO_INC_STMT2 % [tname, strip_quotes(cname)]
|
176
142
|
data = execute(stmt).first
|
@@ -192,19 +158,20 @@ module ::ArJdbc
|
|
192
158
|
|
193
159
|
|
194
160
|
def add_column(table_name, column_name, type, options = {})
|
195
|
-
if option_not_null = options[:null] == false
|
196
|
-
|
161
|
+
if option_not_null = (options[:null] == false)
|
162
|
+
options.delete(:null)
|
197
163
|
end
|
198
164
|
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])}"
|
199
165
|
add_column_options!(add_column_sql, options)
|
200
166
|
execute(add_column_sql)
|
201
167
|
if option_not_null
|
202
168
|
alter_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ALTER #{quote_column_name(column_name)} NOT NULL"
|
169
|
+
execute(alter_column_sql)
|
203
170
|
end
|
204
171
|
end
|
205
172
|
|
206
173
|
def execute(sql, name = nil)
|
207
|
-
if sql =~
|
174
|
+
if sql =~ /\A\s*(UPDATE|INSERT)/i
|
208
175
|
i = sql =~ /\swhere\s/im
|
209
176
|
if i
|
210
177
|
sql[i..-1] = sql[i..-1].gsub(/!=\s*NULL/, 'IS NOT NULL').gsub(/=\sNULL/i, 'IS NULL')
|
@@ -238,22 +205,6 @@ module ::ArJdbc
|
|
238
205
|
sql
|
239
206
|
end
|
240
207
|
|
241
|
-
# I don't think this method is ever called ??? (stepheneb)
|
242
|
-
def create_column(name, refid, colno)
|
243
|
-
stmt = COLUMN_TYPE_STMT % [refid, strip_quotes(name)]
|
244
|
-
coldef = ""
|
245
|
-
data = execute(stmt).first
|
246
|
-
if data
|
247
|
-
coldef << add_quotes(expand_double_quotes(strip_quotes(name)))
|
248
|
-
coldef << " "
|
249
|
-
coldef << data['columndatatype']
|
250
|
-
if !reinstate_auto_increment(name, refid, coldef) && data['columndefault']
|
251
|
-
coldef << " DEFAULT " << data['columndefault']
|
252
|
-
end
|
253
|
-
end
|
254
|
-
coldef
|
255
|
-
end
|
256
|
-
|
257
208
|
SIZEABLE = %w(VARCHAR CLOB BLOB)
|
258
209
|
|
259
210
|
def structure_dump #:nodoc:
|
@@ -298,21 +249,8 @@ module ::ArJdbc
|
|
298
249
|
definition
|
299
250
|
end
|
300
251
|
|
301
|
-
# Support for removing columns added via derby bug issue:
|
302
|
-
# https://issues.apache.org/jira/browse/DERBY-1489
|
303
|
-
#
|
304
|
-
# This feature has not made it into a formal release and is not in Java 6.
|
305
|
-
# If the normal strategy fails we fall back on a strategy by creating a new
|
306
|
-
# table without the new column and there after moving the data to the new
|
307
|
-
#
|
308
252
|
def remove_column(table_name, column_name)
|
309
|
-
|
310
|
-
execute "ALTER TABLE #{table_name} DROP COLUMN #{column_name} RESTRICT"
|
311
|
-
rescue
|
312
|
-
alter_table(table_name) do |definition|
|
313
|
-
definition.columns.delete(definition[column_name])
|
314
|
-
end
|
315
|
-
end
|
253
|
+
execute "ALTER TABLE #{quote_table_name(table_name)} DROP COLUMN #{quote_column_name(column_name)} RESTRICT"
|
316
254
|
end
|
317
255
|
|
318
256
|
# Notes about changing in Derby:
|
@@ -328,23 +266,23 @@ module ::ArJdbc
|
|
328
266
|
if options.include?(:null)
|
329
267
|
# This seems to only work with 10.2 of Derby
|
330
268
|
if options.delete(:null) == false
|
331
|
-
execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} NOT NULL"
|
269
|
+
execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} NOT NULL"
|
332
270
|
else
|
333
|
-
execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} NULL"
|
271
|
+
execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} NULL"
|
334
272
|
end
|
335
273
|
end
|
336
274
|
|
337
275
|
# anything left to do?
|
338
276
|
unless options.empty?
|
339
277
|
begin
|
340
|
-
execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET DATA TYPE #{type_to_sql(type, options[:limit])}"
|
278
|
+
execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DATA TYPE #{type_to_sql(type, options[:limit])}"
|
341
279
|
rescue
|
342
280
|
transaction do
|
343
281
|
temp_new_column_name = "#{column_name}_newtype"
|
344
282
|
# 1) ALTER TABLE t ADD COLUMN c1_newtype NEWTYPE;
|
345
283
|
add_column table_name, temp_new_column_name, type, options
|
346
284
|
# 2) UPDATE t SET c1_newtype = c1;
|
347
|
-
execute "UPDATE #{table_name} SET #{temp_new_column_name} = CAST(#{column_name} AS #{type_to_sql(type, options[:limit])})"
|
285
|
+
execute "UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(temp_new_column_name)} = CAST(#{quote_column_name(column_name)} AS #{type_to_sql(type, options[:limit])})"
|
348
286
|
# 3) ALTER TABLE t DROP COLUMN c1;
|
349
287
|
remove_column table_name, column_name
|
350
288
|
# 4) ALTER TABLE t RENAME COLUMN c1_newtype to c1;
|
@@ -354,18 +292,8 @@ module ::ArJdbc
|
|
354
292
|
end
|
355
293
|
end
|
356
294
|
|
357
|
-
# Support for renaming columns:
|
358
|
-
# https://issues.apache.org/jira/browse/DERBY-1490
|
359
|
-
#
|
360
|
-
# This feature is expect to arrive in version 10.3.0.0:
|
361
|
-
# http://wiki.apache.org/db-derby/DerbyTenThreeRelease)
|
362
|
-
#
|
363
295
|
def rename_column(table_name, column_name, new_column_name) #:nodoc:
|
364
|
-
|
365
|
-
execute "ALTER TABLE #{table_name} ALTER RENAME COLUMN #{column_name} TO #{new_column_name}"
|
366
|
-
rescue
|
367
|
-
alter_table(table_name, :rename => {column_name => new_column_name})
|
368
|
-
end
|
296
|
+
execute "RENAME COLUMN #{quote_table_name(table_name)}.#{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}"
|
369
297
|
end
|
370
298
|
|
371
299
|
def primary_keys(table_name)
|
@@ -386,20 +314,8 @@ module ::ArJdbc
|
|
386
314
|
end
|
387
315
|
end
|
388
316
|
|
389
|
-
# For DDL it appears you can quote "" column names, but in queries (like insert it errors out?)
|
390
317
|
def quote_column_name(name) #:nodoc:
|
391
|
-
name
|
392
|
-
if /^(references|integer|key|group|year)$/i =~ name
|
393
|
-
%Q{"#{name.upcase}"}
|
394
|
-
elsif /[A-Z]/ =~ name && /[a-z]/ =~ name
|
395
|
-
%Q{"#{name}"}
|
396
|
-
elsif name =~ /[\s-]/
|
397
|
-
%Q{"#{name.upcase}"}
|
398
|
-
elsif name =~ /^[_\d]/
|
399
|
-
%Q{"#{name.upcase}"}
|
400
|
-
else
|
401
|
-
name
|
402
|
-
end
|
318
|
+
%Q{"#{name.to_s.upcase.gsub(/"/, '""')}"}
|
403
319
|
end
|
404
320
|
|
405
321
|
def quoted_true
|
data/lib/arjdbc/discover.rb
CHANGED
Binary file
|
data/lib/arjdbc/mssql/adapter.rb
CHANGED
@@ -25,7 +25,7 @@ module ::ArJdbc
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.column_selector
|
28
|
-
[/sqlserver|tds/i, lambda {|cfg,col| col.extend(::ArJdbc::MsSQL::Column)}]
|
28
|
+
[/sqlserver|tds|Microsoft SQL/i, lambda {|cfg,col| col.extend(::ArJdbc::MsSQL::Column)}]
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.jdbc_connection_class
|
data/lib/arjdbc/mysql/adapter.rb
CHANGED
@@ -358,6 +358,10 @@ module ::ArJdbc
|
|
358
358
|
end
|
359
359
|
|
360
360
|
module ActiveRecord::ConnectionAdapters
|
361
|
+
# Remove any vestiges of core/Ruby MySQL adapter
|
362
|
+
remove_const(:MysqlColumn) if const_defined?(:MysqlColumn)
|
363
|
+
remove_const(:MysqlAdapter) if const_defined?(:MysqlAdapter)
|
364
|
+
|
361
365
|
class MysqlColumn < JdbcColumn
|
362
366
|
include ArJdbc::MySQL::Column
|
363
367
|
|
@@ -26,6 +26,15 @@ module ::ArJdbc
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def extract_limit(sql_type)
|
30
|
+
case sql_type
|
31
|
+
when /^bigint/i; 8
|
32
|
+
when /^smallint/i; 2
|
33
|
+
when /^bool/i; nil # ACTIVERECORD_JDBC-135
|
34
|
+
else super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
def simplified_type(field_type)
|
30
39
|
return :integer if field_type =~ /^serial/i
|
31
40
|
return :string if field_type =~ /\[\]$/i || field_type =~ /^interval/i
|
@@ -71,7 +80,7 @@ module ::ArJdbc
|
|
71
80
|
tp[:primary_key] = "serial primary key"
|
72
81
|
tp[:string][:limit] = 255
|
73
82
|
tp[:integer][:limit] = nil
|
74
|
-
tp[:boolean]
|
83
|
+
tp[:boolean] = { :name => "boolean" }
|
75
84
|
tp[:float] = { :name => "float" }
|
76
85
|
tp[:decimal] = { :name => "decimal" }
|
77
86
|
tp
|
@@ -297,6 +297,9 @@ module ::ArJdbc
|
|
297
297
|
end
|
298
298
|
|
299
299
|
module ActiveRecord::ConnectionAdapters
|
300
|
+
remove_const(:SQLite3Adapter) if const_defined?(:SQLite3Adapter)
|
301
|
+
remove_const(:SQLiteAdapter) if const_defined?(:SQLiteAdapter)
|
302
|
+
|
300
303
|
class SQLite3Column < JdbcColumn
|
301
304
|
include ArJdbc::SQLite3::Column
|
302
305
|
|
@@ -336,13 +339,15 @@ module ActiveRecord::ConnectionAdapters
|
|
336
339
|
end
|
337
340
|
|
338
341
|
def jdbc_connection_class(spec)
|
339
|
-
ArJdbc::SQLite3.jdbc_connection_class
|
342
|
+
::ArJdbc::SQLite3.jdbc_connection_class
|
340
343
|
end
|
341
344
|
|
342
345
|
def jdbc_column_class
|
343
346
|
ActiveRecord::ConnectionAdapters::SQLite3Column
|
344
347
|
end
|
345
348
|
end
|
349
|
+
|
350
|
+
SQLiteAdapter = SQLite3Adapter
|
346
351
|
end
|
347
352
|
|
348
353
|
# Fake out sqlite3/version driver for AR tests
|
data/lib/arjdbc/version.rb
CHANGED
@@ -28,3 +28,24 @@ class PostgresDeserializationTest < Test::Unit::TestCase
|
|
28
28
|
assert_equal expected.sample_float, actual.sample_float
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
class PostgresSchemaDumperTest < Test::Unit::TestCase
|
33
|
+
def setup
|
34
|
+
DbTypeMigration.up
|
35
|
+
@connection = ActiveRecord::Base.connection
|
36
|
+
strio = StringIO.new
|
37
|
+
ActiveRecord::SchemaDumper::dump(ActiveRecord::Base.connection, strio)
|
38
|
+
@dump = strio.string
|
39
|
+
end
|
40
|
+
|
41
|
+
def teardown
|
42
|
+
DbTypeMigration.down
|
43
|
+
end
|
44
|
+
|
45
|
+
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
|
46
|
+
def test_schema_dump_should_not_have_limits_on_boolean
|
47
|
+
lines = @dump.grep(/boolean/)
|
48
|
+
assert !lines.empty?
|
49
|
+
lines.each {|line| assert line !~ /limit/ }
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
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-10-
|
17
|
+
date: 2010-10-20 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -43,8 +43,8 @@ dependencies:
|
|
43
43
|
segments:
|
44
44
|
- 2
|
45
45
|
- 6
|
46
|
-
-
|
47
|
-
version: 2.6.
|
46
|
+
- 2
|
47
|
+
version: 2.6.2
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
50
|
description: |-
|