ActiveRecord-JDBC 0.3 → 0.3.1

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.
@@ -1,3 +1,7 @@
1
+ == 0.3.1
2
+
3
+ * Derby critical fixes shortly after 0.3
4
+
1
5
  == 0.3
2
6
 
3
7
  * Release coincides with JRuby 1.0.0RC1 release
data/Rakefile CHANGED
@@ -84,7 +84,7 @@ begin
84
84
  Rake::Task['manifest'].invoke # Always regen manifest, so Hoe has up-to-date list of files
85
85
 
86
86
  require 'hoe'
87
- Hoe.new("ActiveRecord-JDBC", "0.3") do |p|
87
+ Hoe.new("ActiveRecord-JDBC", "0.3.1") do |p|
88
88
  p.rubyforge_name = "jruby-extras"
89
89
  p.url = "http://jruby-extras.rubyforge.org/ActiveRecord-JDBC"
90
90
  p.author = "Nick Sieger, Ola Bini and JRuby contributors"
@@ -24,7 +24,7 @@ module JdbcSpec
24
24
  return value if value.is_a? Time
25
25
  time_array = ParseDate.parsedate value
26
26
  time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
27
- Time.send(Base.default_timezone, *time_array) rescue nil
27
+ Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
28
28
  end
29
29
 
30
30
  def guess_date_or_time(value)
@@ -27,7 +27,7 @@ module JdbcSpec
27
27
  return value if value.is_a? Time
28
28
  time_array = ParseDate.parsedate value
29
29
  time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
30
- Time.send(Base.default_timezone, *time_array) rescue nil
30
+ Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
31
31
  end
32
32
 
33
33
  def guess_date_or_time(value)
@@ -119,7 +119,88 @@ module JdbcSpec
119
119
  def rename_table(name, new_name)
120
120
  execute "RENAME TABLE #{name} TO #{new_name}"
121
121
  end
122
+
123
+ 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"
124
+
125
+ COLUMN_TYPE_STMT = "SELECT COLUMNDATATYPE, COLUMNDEFAULT FROM SYS.SYSCOLUMNS WHERE REFERENCEID = '%s' AND COLUMNNAME = '%s'"
126
+
127
+ AUTO_INC_STMT = "SELECT AUTOINCREMENTSTART, AUTOINCREMENTINC, COLUMNNAME, REFERENCEID, COLUMNDEFAULT FROM SYS.SYSCOLUMNS WHERE REFERENCEID = '%s' AND COLUMNNAME = '%s'"
128
+
129
+
130
+ def add_quotes(name)
131
+ return name unless name
132
+ %Q{"#{name}"}
133
+ end
134
+
135
+ def strip_quotes(str)
136
+ return str unless str
137
+ return str unless /^(["']).*\1$/ =~ str
138
+ str[1..-2]
139
+ end
122
140
 
141
+ def expand_double_quotes(name)
142
+ return name unless name && name['"']
143
+ name.gsub(/"/,'""')
144
+ end
145
+
146
+ def reinstate_auto_increment(name, refid, coldef)
147
+ stmt = AUTO_INC_STMT % [refid, strip_quotes(name)]
148
+ data = execute(stmt).first
149
+ if data
150
+ start = data['autoincrementstart']
151
+ if start
152
+ coldef << " GENERATED " << (data['columndefault'].nil? ? "ALWAYS" : "BY DEFAULT ")
153
+ coldef << "AS IDENTITY (START WITH "
154
+ coldef << start
155
+ coldef << ", INCREMENT BY "
156
+ coldef << data['autoincrementinc']
157
+ coldef << ")"
158
+ return true
159
+ end
160
+ end
161
+ false
162
+ end
163
+
164
+ def create_column(name, refid, colno)
165
+ stmt = COLUMN_TYPE_STMT % [refid, strip_quotes(name)]
166
+ coldef = ""
167
+ data = execute(stmt).first
168
+ if data
169
+ coldef << add_quotes(expand_double_quotes(strip_quotes(name)))
170
+ coldef << " "
171
+ coldef << data['columndatatype']
172
+ if !reinstate_auto_increment(name, refid, coldef) && data['columndefault']
173
+ coldef << " DEFAULT " << data['columndefault']
174
+ end
175
+ end
176
+ coldef
177
+ end
178
+
179
+ def structure_dump #:nodoc:
180
+ data = ""
181
+ execute("select tablename, tableid from sys.systables where schemaid not in (select schemaid from sys.sysschemas where schemaname LIKE 'SYS%')").each do |tbl|
182
+ tid = tbl["tableid"]
183
+ tname = tbl["tablename"]
184
+ data << "CREATE TABLE #{tname} (\n"
185
+ first_col = true
186
+ execute(COLUMN_INFO_STMT % tid).each do |col|
187
+ col_name = add_quotes(col['columnname']);
188
+ create_col_string = create_column(col_name, col['referenceid'],col['columnnumber'].to_i)
189
+ if !first_col
190
+ create_col_string = ",\n #{create_col_string}"
191
+ else
192
+ create_col_string = " #{create_col_string}"
193
+ end
194
+
195
+ data << create_col_string
196
+
197
+ first_col = false
198
+ end
199
+ data << ");\n\n"
200
+ end
201
+ data
202
+ end
203
+
123
204
  # Support for removing columns added via derby bug issue:
124
205
  # https://issues.apache.org/jira/browse/DERBY-1489
125
206
  #
@@ -184,6 +265,12 @@ module JdbcSpec
184
265
  def primary_keys(table_name)
185
266
  @connection.primary_keys table_name.to_s.upcase
186
267
  end
268
+
269
+ def recreate_database(db_name)
270
+ tables.each do |t|
271
+ drop_table t rescue nil
272
+ end
273
+ end
187
274
 
188
275
  # For migrations, exclude the primary key index as recommended
189
276
  # by the HSQLDB docs. This is not a great test for primary key
@@ -212,12 +299,7 @@ module JdbcSpec
212
299
  end
213
300
  end
214
301
  else
215
- vi = value.to_i
216
- if vi.to_s == value
217
- value
218
- else
219
- "'#{quote_string(value)}'"
220
- end
302
+ super
221
303
  end
222
304
  else super
223
305
  end
@@ -25,7 +25,7 @@ module JdbcSpec
25
25
  return value if value.is_a? Time
26
26
  time_array = ParseDate.parsedate value
27
27
  time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
28
- Time.send(Base.default_timezone, *time_array) rescue nil
28
+ Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
29
29
  end
30
30
 
31
31
  def guess_date_or_time(value)
@@ -38,7 +38,7 @@ module JdbcSpec
38
38
  time_array[0] ||= 2000
39
39
  time_array[1] ||= 1
40
40
  time_array[2] ||= 1
41
- Time.send(Base.default_timezone, *time_array) rescue nil
41
+ Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
42
42
  end
43
43
 
44
44
  def cast_to_datetime(value)
@@ -35,7 +35,7 @@ module JdbcSpec
35
35
  return value if value.is_a? Time
36
36
  time_array = ParseDate.parsedate value
37
37
  time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
38
- Time.send(Base.default_timezone, *time_array) rescue nil
38
+ Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
39
39
  end
40
40
 
41
41
  def guess_date_or_time(value)
@@ -111,31 +111,6 @@ module JdbcSpec
111
111
  select_one("select sys_context('userenv','db_name') db from dual")["db"]
112
112
  end
113
113
 
114
- def indexes(table_name, name = nil) #:nodoc:
115
- result = select_all(<<-SQL, name)
116
- SELECT lower(i.index_name) as index_name, i.uniqueness, lower(c.column_name) as column_name
117
- FROM user_indexes i, user_ind_columns c
118
- WHERE i.table_name = '#{table_name.to_s.upcase}'
119
- AND c.index_name = i.index_name
120
- AND i.index_name NOT IN (SELECT index_name FROM user_constraints WHERE constraint_type = 'P')
121
- ORDER BY i.index_name, c.column_position
122
- SQL
123
-
124
- current_index = nil
125
- indexes = []
126
-
127
- result.each do |row|
128
- if current_index != row['index_name']
129
- indexes << IndexDefinition.new(table_name, row['index_name'], row['uniqueness'] == "UNIQUE", [])
130
- current_index = row['index_name']
131
- end
132
-
133
- indexes.last.columns << row['column_name']
134
- end
135
-
136
- indexes
137
- end
138
-
139
114
  def remove_index(table_name, options = {}) #:nodoc:
140
115
  execute "DROP INDEX #{index_name(table_name, options)}"
141
116
  end
@@ -16,7 +16,7 @@ module JdbcSpec
16
16
  return value if value.is_a? Time
17
17
  time_array = ParseDate.parsedate value
18
18
  time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
19
- Time.send(Base.default_timezone, *time_array) rescue nil
19
+ Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
20
20
  end
21
21
 
22
22
  def guess_date_or_time(value)
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ActiveRecord-JDBC
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.3"
6
+ version: 0.3.1
7
7
  date: 2007-05-07 00:00:00 -05:00
8
8
  summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
9
9
  require_paths: