Class: ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter

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

Instance Method Summary collapse

Instance Method Details

#columns_without_cache(table_name, name = nil) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 17

def columns_without_cache(table_name, name = nil) #:nodoc:
  table_name = table_name.to_s
  # get ignored_columns by original table name
  ignored_columns = ignored_table_columns(table_name)

  (owner, desc_table_name, db_link) = @connection.describe(table_name)

  @@do_not_prefetch_primary_key[table_name] =
    !has_primary_key?(table_name, owner, desc_table_name, db_link) ||
    has_primary_key_trigger?(table_name, owner, desc_table_name, db_link)

  table_cols = "    select column_name as name, data_type as sql_type, data_default, nullable,\n           decode(data_type, 'NUMBER', data_precision,\n                             'FLOAT', data_precision,\n                             'VARCHAR2', decode(char_used, 'C', char_length, data_length),\n                             'CHAR', decode(char_used, 'C', char_length, data_length),\n                              null) as limit,\n           decode(data_type, 'NUMBER', data_scale, null) as scale\n      from all_tab_columns\#{db_link}\n     where owner      = '\#{owner}'\n       and table_name = '\#{desc_table_name}'\n     order by column_id\n  SQL\n    \n  raw_geom_infos = column_spatial_info(desc_table_name)\n\n  # added deletion of ignored columns\n  select_all(table_cols, name).delete_if do |row|\n    ignored_columns && ignored_columns.include?(row['name'].downcase)\n  end.map do |row|\n    limit, scale = row['limit'], row['scale']\n    if limit || scale\n      row['sql_type'] += \"(\#{(limit || 38).to_i}\" + ((scale = scale.to_i) > 0 ? \",\#{scale})\" : \")\")\n    end\n    \n    # clean up odd default spacing from Oracle\n    if row['data_default']\n      row['data_default'].sub!(/^(.*?)\\s*$/, '\\1')\n\n      # If a default contains a newline these cleanup regexes need to\n      # match newlines.\n      row['data_default'].sub!(/^'(.*)'$/m, '\\1')\n      row['data_default'] = nil if row['data_default'] =~ /^(null|empty_[bc]lob\\(\\))$/i\n    end\n\n    if row['sql_type'] =~ /sdo_geometry/i\n      raw_geom_info = raw_geom_infos[oracle_downcase(row['name'])]\n      if(raw_geom_info.nil?)\n        puts \"Couldn't find geom info for \#{row['name']} in \#{raw_geom_infos.inspect}\"\n      end\n      ActiveRecord::ConnectionAdapters::SpatialOracleColumn.new(\n        oracle_downcase(row['name']),\n        row['data_default'],\n        raw_geom_info.type,\n        row['nullable'] == 'Y',\n        raw_geom_info.srid,\n        raw_geom_info.with_z,\n        raw_geom_info.with_m)\n    else\n      OracleEnhancedColumn.new(oracle_downcase(row['name']),\n                       row['data_default'],\n                       row['sql_type'],\n                       row['nullable'] == 'Y',\n                       # pass table name for table specific column definitions\n                       table_name,\n                       # pass column type if specified in class definition\n                       get_type_for_column(table_name, oracle_downcase(row['name'])))\n    end\n  end\nend\n"

#spatial?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/spatial_adapter/oracle_enhanced.rb', line 12

def spatial?
  rval = select_value("select object_id from all_objects where owner = 'MDSYS' and object_name = 'SDO_GEOMETRY'").to_i
  rval > 0 ? true : false
end