Class: ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition
- Inherits:
-
ColumnDefinition
- Object
- ColumnDefinition
- ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition
- Defined in:
- lib/spatial_adapter/postgresql.rb
Instance Attribute Summary collapse
-
#geographic ⇒ Object
Returns the value of attribute geographic.
-
#spatial ⇒ Object
readonly
Returns the value of attribute spatial.
-
#srid ⇒ Object
Returns the value of attribute srid.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
-
#with_m ⇒ Object
Returns the value of attribute with_m.
-
#with_z ⇒ Object
Returns the value of attribute with_z.
Instance Method Summary collapse
-
#initialize(base = nil, name = nil, type = nil, limit = nil, default = nil, null = nil, srid = -1,, with_z = false, with_m = false, geographic = false) ⇒ PostgreSQLColumnDefinition
constructor
A new instance of PostgreSQLColumnDefinition.
- #sql_type ⇒ Object
- #to_sql ⇒ Object
Constructor Details
#initialize(base = nil, name = nil, type = nil, limit = nil, default = nil, null = nil, srid = -1,, with_z = false, with_m = false, geographic = false) ⇒ PostgreSQLColumnDefinition
Returns a new instance of PostgreSQLColumnDefinition.
275 276 277 278 279 280 281 282 283 |
# File 'lib/spatial_adapter/postgresql.rb', line 275 def initialize(base = nil, name = nil, type=nil, limit=nil, default=nil, null=nil, srid=-1, with_z=false, with_m=false, geographic=false) super(base, name, type, limit, default, null) @table_name = nil @spatial = true @srid = srid @with_z = with_z @with_m = with_m @geographic = geographic end |
Instance Attribute Details
#geographic ⇒ Object
Returns the value of attribute geographic.
272 273 274 |
# File 'lib/spatial_adapter/postgresql.rb', line 272 def geographic @geographic end |
#spatial ⇒ Object (readonly)
Returns the value of attribute spatial.
273 274 275 |
# File 'lib/spatial_adapter/postgresql.rb', line 273 def spatial @spatial end |
#srid ⇒ Object
Returns the value of attribute srid.
272 273 274 |
# File 'lib/spatial_adapter/postgresql.rb', line 272 def srid @srid end |
#table_name ⇒ Object
Returns the value of attribute table_name.
271 272 273 |
# File 'lib/spatial_adapter/postgresql.rb', line 271 def table_name @table_name end |
#with_m ⇒ Object
Returns the value of attribute with_m.
272 273 274 |
# File 'lib/spatial_adapter/postgresql.rb', line 272 def with_m @with_m end |
#with_z ⇒ Object
Returns the value of attribute with_z.
272 273 274 |
# File 'lib/spatial_adapter/postgresql.rb', line 272 def with_z @with_z end |
Instance Method Details
#sql_type ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/spatial_adapter/postgresql.rb', line 285 def sql_type if geographic type_sql = SpatialAdapter.geometry_data_types[type.to_sym][:name] type_sql += "Z" if with_z type_sql += "M" if with_m # SRID is not yet supported (defaults to 4326) #type_sql += ", #{srid}" if (srid && srid != -1) type_sql = "geography(#{type_sql})" type_sql else super end end |
#to_sql ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/spatial_adapter/postgresql.rb', line 299 def to_sql if spatial && !geographic type_sql = SpatialAdapter.geometry_data_types[type.to_sym][:name] type_sql += "M" if with_m and !with_z if with_m and with_z dimension = 4 elsif with_m or with_z dimension = 3 else dimension = 2 end column_sql = "SELECT AddGeometryColumn('#{table_name}','#{name}',#{srid},'#{type_sql}',#{dimension})" column_sql += ";ALTER TABLE #{table_name} ALTER #{name} SET NOT NULL" if null == false column_sql else super end end |