| Class | ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition |
| In: |
lib/post_gis_adapter.rb
|
| Parent: | ColumnDefinition |
| spatial | [R] | |
| srid | [RW] | |
| with_m | [RW] | |
| with_z | [RW] |
# File lib/post_gis_adapter.rb, line 282
282: def initialize(base = nil, name = nil, type=nil, limit=nil, default=nil,null=nil,srid=-1,with_z=false,with_m=false)
283: super(base, name, type, limit, default,null)
284: @spatial=true
285: @srid=srid
286: @with_z=with_z
287: @with_m=with_m
288: end
# File lib/post_gis_adapter.rb, line 290
290: def to_sql(table_name)
291: if @spatial
292: type_sql = type_to_sql(type.to_sym)
293: type_sql += "M" if with_m and !with_z
294: if with_m and with_z
295: dimension = 4
296: elsif with_m or with_z
297: dimension = 3
298: else
299: dimension = 2
300: end
301:
302: column_sql = "SELECT AddGeometryColumn('#{table_name}','#{name}',#{srid},'#{type_sql}',#{dimension})"
303: column_sql += ";ALTER TABLE #{table_name} ALTER #{name} SET NOT NULL" if null == false
304: column_sql
305: else
306: super
307: end
308: end