spatial_adapter 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/README.rdoc +30 -17
- data/Rakefile +11 -0
- data/init.rb +1 -0
- data/lib/spatial_adapter/base/mysql/adapter.rb +54 -0
- data/lib/spatial_adapter/base/mysql/spatial_column.rb +12 -0
- data/lib/spatial_adapter/base/mysql.rb +9 -0
- data/lib/spatial_adapter/common/schema_dumper.rb +12 -12
- data/lib/spatial_adapter/common/spatial_column.rb +4 -4
- data/lib/spatial_adapter/common/table_definition.rb +8 -10
- data/lib/spatial_adapter/common.rb +10 -0
- data/lib/spatial_adapter/jdbcmysql.rb +50 -0
- data/lib/spatial_adapter/mysql.rb +43 -85
- data/lib/spatial_adapter/mysql2.rb +39 -86
- data/lib/spatial_adapter/postgresql.rb +315 -324
- data/lib/spatial_adapter/version.rb +3 -0
- data/lib/spatial_adapter.rb +3 -7
- data/spatial_adapter.gemspec +39 -0
- data/spec/db/jdbcmysql_raw.rb +70 -0
- data/spec/db/mysql2_raw.rb +9 -9
- data/spec/db/mysql_raw.rb +9 -9
- data/spec/jdbcmysql_spec.rb +25 -0
- data/spec/mysql2_spec.rb +31 -0
- data/spec/mysql_spec.rb +17 -0
- data/spec/postgresql/connection_adapter_spec.rb +34 -39
- data/spec/postgresql/migration_spec.rb +51 -51
- data/spec/postgresql/models_spec.rb +37 -37
- data/spec/postgresql/schema_dumper_spec.rb +12 -12
- data/spec/postgresql_spec.rb +5 -0
- data/spec/{shared_examples.rb → shared/common_model_actions_spec.rb} +2 -2
- data/spec/shared/mysql_connection_adapter_spec.rb +110 -0
- data/spec/{mysql/migration_spec.rb → shared/mysql_migration_spec.rb} +17 -17
- data/spec/shared/mysql_models_spec.rb +58 -0
- data/spec/{mysql/schema_dumper_spec.rb → shared/mysql_schema_dumper_spec.rb} +24 -27
- data/spec/spec_helper.rb +25 -21
- metadata +131 -84
- data/VERSION +0 -1
- data/spec/README.txt +0 -22
- data/spec/mysql/connection_adapter_spec.rb +0 -106
- data/spec/mysql/models_spec.rb +0 -65
- data/spec/mysql2/connection_adapter_spec.rb +0 -106
- data/spec/mysql2/migration_spec.rb +0 -64
- data/spec/mysql2/models_spec.rb +0 -65
- data/spec/mysql2/schema_dumper_spec.rb +0 -56
@@ -1,97 +1,50 @@
|
|
1
1
|
require 'spatial_adapter'
|
2
|
+
require 'spatial_adapter/base/mysql'
|
2
3
|
require 'active_record/connection_adapters/mysql2_adapter'
|
3
4
|
|
4
|
-
ActiveRecord::ConnectionAdapters
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
#Redefinition of columns to add the information that a column is geometric
|
27
|
-
def columns(table_name, name = nil)#:nodoc:
|
28
|
-
sql = "SHOW FIELDS FROM #{quote_table_name(table_name)}"
|
29
|
-
columns = []
|
30
|
-
result = execute(sql, name)
|
31
|
-
result.each do |field|
|
32
|
-
klass = field[1] =~ /geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i ? ActiveRecord::ConnectionAdapters::SpatialMysql2Column : ActiveRecord::ConnectionAdapters::Mysql2Column
|
33
|
-
columns << klass.new(field[0], field[4], field[1], field[2] == "YES")
|
34
|
-
end
|
35
|
-
columns
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
#operations relative to migrations
|
40
|
-
|
41
|
-
#Redefines add_index to support the case where the index is spatial
|
42
|
-
#If the :spatial key in the options table is true, then the sql string for a spatial index is created
|
43
|
-
def add_index(table_name,column_name,options = {})
|
44
|
-
index_name = options[:name] || index_name(table_name,:column => Array(column_name))
|
45
|
-
|
46
|
-
if options[:spatial]
|
47
|
-
execute "CREATE SPATIAL INDEX #{index_name} ON #{table_name} (#{Array(column_name).join(", ")})"
|
48
|
-
else
|
49
|
-
super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
#Check the nature of the index : If it is SPATIAL, it is indicated in the IndexDefinition object (redefined to add the spatial flag in spatial_adapter_common.rb)
|
54
|
-
def indexes(table_name, name = nil)#:nodoc:
|
55
|
-
indexes = []
|
56
|
-
current_index = nil
|
57
|
-
(execute("SHOW KEYS FROM #{table_name}", name) || []).each do |row|
|
58
|
-
if current_index != row[2]
|
59
|
-
next if row[2] == "PRIMARY" # skip the primary key
|
60
|
-
current_index = row[2]
|
61
|
-
indexes << ActiveRecord::ConnectionAdapters::IndexDefinition.new(row[0], row[2], row[1] == "0", [], row[10] == "SPATIAL")
|
5
|
+
module ActiveRecord::ConnectionAdapters
|
6
|
+
class SpatialMysql2Column < Mysql2Column
|
7
|
+
include SpatialAdapter::SpatialColumn
|
8
|
+
extend SpatialAdapter::Base::Mysql::SpatialColumn
|
9
|
+
end
|
10
|
+
|
11
|
+
class Mysql2Adapter
|
12
|
+
include SpatialAdapter::Base::Mysql::Adapter
|
13
|
+
|
14
|
+
#Redefinition of columns to add the information that a column is geometric
|
15
|
+
def columns(table_name, name = nil)#:nodoc:
|
16
|
+
show_fields_from(table_name, name).map do |field|
|
17
|
+
klass = \
|
18
|
+
if field[1] =~ GEOMETRY_REGEXP
|
19
|
+
ActiveRecord::ConnectionAdapters::SpatialMysql2Column
|
20
|
+
else
|
21
|
+
ActiveRecord::ConnectionAdapters::Mysql2Column
|
22
|
+
end
|
23
|
+
klass.new(field[0], field[4], field[1], field[2] == "YES")
|
62
24
|
end
|
63
|
-
indexes.last.columns << row[4]
|
64
|
-
end
|
65
|
-
indexes
|
66
|
-
end
|
67
|
-
|
68
|
-
#Get the table creation options : Only the engine for now. The text encoding could also be parsed and returned here.
|
69
|
-
def options_for(table)
|
70
|
-
result = execute("show table status like '#{table}'")
|
71
|
-
engine = result.first[1]
|
72
|
-
if engine !~ /inno/i #inno is default so do nothing for it in order not to clutter the migration
|
73
|
-
"ENGINE=#{engine}"
|
74
|
-
else
|
75
|
-
nil
|
76
25
|
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
26
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
27
|
+
# Check the nature of the index : If it is SPATIAL, it is indicated in the
|
28
|
+
# IndexDefinition object (redefined to add the spatial flag in
|
29
|
+
# spatial_adapter_common.rb)
|
30
|
+
def indexes(table_name, name = nil)#:nodoc:
|
31
|
+
indexes = []
|
32
|
+
current_index = nil
|
33
|
+
show_keys_from(table_name, name).each do |row|
|
34
|
+
if current_index != row[2]
|
35
|
+
next if row[2] == "PRIMARY" # skip the primary key
|
36
|
+
current_index = row[2]
|
37
|
+
indexes << ActiveRecord::ConnectionAdapters::IndexDefinition \
|
38
|
+
.new(row[0], row[2], row[1] == "0", [], row[10] == "SPATIAL")
|
93
39
|
end
|
40
|
+
indexes.last.columns << row[4]
|
94
41
|
end
|
42
|
+
indexes
|
43
|
+
end
|
44
|
+
|
45
|
+
def options_for(table)
|
46
|
+
engine = show_table_status_like(table).first[1]
|
47
|
+
engine !~ /inno/i ? "ENGINE=#{engine}" : nil
|
95
48
|
end
|
96
49
|
end
|
97
50
|
end
|