Class: ActiveRecord::ConnectionAdapters::OracleColumnDefinition

Inherits:
ColumnDefinition
  • Object
show all
Defined in:
lib/spatial_adapter/oracle_enhanced.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base = nil, name = nil, type = nil, limit = nil, default = nil, null = nil, srid = -1,, with_z = false, with_m = false) ⇒ OracleColumnDefinition

Returns a new instance of OracleColumnDefinition.



328
329
330
331
332
333
334
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 328

def initialize(base = nil, name = nil, type=nil, limit=nil, default=nil,null=nil,srid=-1,with_z=false,with_m=false)
  super(base, name, type, limit, default,null)
  @spatial=true
  @srid=srid
  @with_z=with_z
  @with_m=with_m
end

Instance Attribute Details

#spatialObject (readonly)

Returns the value of attribute spatial.



326
327
328
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 326

def spatial
  @spatial
end

#sridObject

Returns the value of attribute srid.



325
326
327
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 325

def srid
  @srid
end

#with_mObject

Returns the value of attribute with_m.



325
326
327
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 325

def with_m
  @with_m
end

#with_zObject

Returns the value of attribute with_z.



325
326
327
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 325

def with_z
  @with_z
end

Instance Method Details

#sql_create_statements(table_name) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 336

def sql_create_statements(table_name)
    type_sql = type_to_sql(type)
    
    #column_sql = "SELECT AddGeometryColumn('#{table_name}','#{name}',#{srid},'#{type_sql}',#{dimension})"
    column_sql = "ALTER TABLE #{table_name} ADD (#{name} #{type_sql}"
    column_sql += " NOT NULL" if null == false
    column_sql += ")"
    stmts = [column_sql]
    if srid == 8307 # There are others we should probably support, but this is common
      dim_elems = ["MDSYS.SDO_DIM_ELEMENT('X', -180.0, 180.0, 0.005)",
                   "MDSYS.SDO_DIM_ELEMENT('Y', -90.0, 90.0, 0.005)"]
    else
      dim_elems = ["MDSYS.SDO_DIM_ELEMENT('X', -1000, 1000, 0.005)",
                   "MDSYS.SDO_DIM_ELEMENT('Y', -1000, 1000, 0.005)"]
    end
    if @with_z
      dim_elems << "MDSYS.SDO_DIM_ELEMENT('Z', -1000, 1000, 0.005)"
    end
    if @with_m
      dim_elems << "MDSYS.SDO_DIM_ELEMENT('M', -1000, 1000, 0.005)"
    end
    
    stmts <<  "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = '#{table_name.to_s.upcase}' AND COLUMN_NAME = '#{name.to_s.upcase}'"
    stmts << "INSERT INTO USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES (" +
             "'#{table_name}', '#{name}', MDSYS.SDO_DIM_ARRAY(#{dim_elems.join(',')}),#{srid})"
    stmts
end

#to_sql(table_name) ⇒ Object



364
365
366
367
368
369
370
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 364

def to_sql(table_name)
  if @spatial
    raise "Got here!"
  else
    super
  end
end