sequel_oracle_extensions 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.3
1
+ 0.6.4
@@ -29,6 +29,26 @@ module Sequel
29
29
  columns = schema table, options
30
30
  attributes = columns.instance_eval{ remove_instance_variable :@features }
31
31
  attributes[:columns] = Hash[ columns ]
32
+
33
+ # Collect table partitioning information, if applicable.
34
+ if attributes[:partitioning]
35
+ ds, result = metadata_dataset, []
36
+ outm = sql_ident_to_sym_proc ds
37
+ schema, table = ds.schema_and_table(table).map{|k| k.to_s.send(ds.identifier_input_method) if k}
38
+ who = schema.nil? ? 'user' : 'all'
39
+ ds = ds.where :owner => schema unless schema.nil?
40
+
41
+ # Basic partitioning info.
42
+ attributes[:partitioning] = ds.
43
+ select(:partitioning_type.as(:type), :interval, :subpartitioning_type.as(:subtype)).
44
+ from(:"#{who}_part_tables").where(:table_name=>table).first
45
+
46
+ # Partitioning key column info.
47
+ attributes[:partitioning][:key] = ds.
48
+ select(:column_name).from(:"#{who}_part_key_columns").order(:column_position).
49
+ where(:object_type=>'TABLE', :name=>table).map{|r| r.values.flatten }
50
+ end
51
+
32
52
  attributes
33
53
  end
34
54
 
@@ -256,6 +276,19 @@ module Sequel
256
276
  table_constraints table, 'R', options.merge(:table_name_column=>:t__table_name)
257
277
  end
258
278
 
279
+ # Overridden to support various Oracle-specific options.
280
+ def alter_table(name, generator=nil, options=nil, &block)
281
+ if Hash === options
282
+ generator ||= Schema::AlterTableGenerator.new(self, &block)
283
+ alter_table_sql_list(name, generator.operations, options).
284
+ flatten.each {|sql| execute_ddl(sql)}
285
+ remove_cached_schema(name)
286
+ nil
287
+ else
288
+ super(name, generator, &block)
289
+ end
290
+ end
291
+
259
292
  protected
260
293
 
261
294
  # Type-safe (and nil safe) conversion for SQL identifers to Ruby symbols.
@@ -273,12 +306,25 @@ module Sequel
273
306
 
274
307
  # Overridden because Oracle has slightly different syntax.
275
308
  def alter_table_sql(table, op)
276
- alter_table_op =
277
- case op[:op]
278
- when :add_column then "ADD #{column_definition_sql(op)}"
279
- else return super(table, op)
280
- end
281
- "ALTER TABLE #{quote_schema_table(table)} #{alter_table_op}"
309
+ case op[:op]
310
+ when :add_column
311
+ "ALTER TABLE #{quote_schema_table(table)} ADD #{column_definition_sql(op)}"
312
+ else
313
+ return super(table, op)
314
+ end
315
+ end
316
+
317
+ # Overridden to support various Oracle-specific options.
318
+ def alter_table_sql_list(table, operations, options=nil)
319
+ return super(table, operations) unless Hash===options
320
+
321
+ prologue = "ALTER TABLE #{quote_schema_table(table)} "
322
+ sql = operations.map do |op|
323
+ frag = alter_table_sql table, op
324
+ raise ArgumentError unless frag.slice![0,prologue.length] == prologue
325
+ frag
326
+ end
327
+ sql.push(table_options_sql(options)).join ' '
282
328
  end
283
329
 
284
330
  # Overridden to support various Oracle-specific options.
@@ -289,6 +335,12 @@ module Sequel
289
335
  sql << flag_option_sql(options, :validate)
290
336
  sql.join ' '
291
337
  end
338
+
339
+ # Overridden to support various Oracle-specific options.
340
+ def create_table_sql(name, generator, options)
341
+ a, b = super(name, generator, options), table_options_sql(options)
342
+ "#{a}\n#{b}"
343
+ end
292
344
 
293
345
  # Overridden because Oracle has a 30 character maximum identifier length.
294
346
  def default_index_name(table_name, columns)
@@ -346,6 +398,18 @@ module Sequel
346
398
  sql.compact.join ' '
347
399
  end
348
400
 
401
+ # SQL DDL clauses for altering and/or creating tables.
402
+ def table_options_sql(options)
403
+ sql = []
404
+ sql << flag_option_sql(options, :parallel)
405
+ sql << flag_option_sql(options, :logging)
406
+ sql << flag_option_sql(options, :monitoring)
407
+ sql << "TABLESPACE #{quote_identifier(options[:tablespace])}" if options[:tablespace]
408
+ sql << compress_option_sql(options)
409
+ sql << options[:options] if String === options[:options]
410
+ sql.compact.join ' '
411
+ end
412
+
349
413
  # SQL DDL clause for specifying on/off flags
350
414
  def flag_option_sql(attrs, key, off="NO#{key}".upcase, on=key.to_s.upcase, implicit=IMPLICIT_FLAG_ATTRIBUTES[key])
351
415
  case attrs[key]
@@ -458,12 +522,12 @@ module Sequel
458
522
  ]
459
523
  end
460
524
  table_schema.instance_variable_set :@features, {
461
- :owner => :"#{metadata.obj_schema.downcase}",
462
- :clustered => (metadata.clustered? rescue nil),
463
- :temporary => (metadata.is_temporary? rescue nil),
464
- :partitioned => (metadata.is_temporary? rescue nil),
465
- :typed => (metadata.is_typed? rescue nil),
466
- :index_only => (metadata.index_only? rescue nil)
525
+ :owner => :"#{metadata.obj_schema.downcase}",
526
+ :clustered => (metadata.clustered? rescue nil),
527
+ :temporary => (metadata.is_temporary? rescue nil),
528
+ :partitioning => (metadata.partitioned? rescue nil),
529
+ :typed => (metadata.is_typed? rescue nil),
530
+ :index_only => (metadata.index_only? rescue nil)
467
531
  }
468
532
  table_schema
469
533
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sequel_oracle_extensions}
8
- s.version = "0.6.3"
8
+ s.version = "0.6.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Khoobyar"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_oracle_extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Khoobyar