activerecord-mysql2rgeo-adapter 2.0.2 → 5.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb +3 -1
- data/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +28 -25
- data/lib/active_record/connection_adapters/mysql2rgeo/create_connection.rb +4 -2
- data/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +49 -24
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb +3 -4
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb +0 -5
- data/lib/active_record/connection_adapters/mysql2rgeo/version.rb +4 -2
- data/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +28 -52
- data/lib/active_record/type/spatial.rb +45 -59
- data/lib/activerecord-mysql2rgeo-adapter.rb +3 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a698ad5caaa0a41779553da7bdff16fab5f61c3feb8d370fe49f424f4ba5cfe1
|
4
|
+
data.tar.gz: 5d7c95ea606c62bce8286b4dbb661b412e80712d9c8049925ee1a96c10fb8c4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f256d79b6770604fa7497d0c9b28a92d9b4452f496cec7e461a2cd6f67dc7dc5d14e10934ffafd75ccc24d9fff50b539c2ab5729342a038eefe909681e95dde
|
7
|
+
data.tar.gz: a6842cf1d6f984d0697e5c5baaa5587116a887aca288d7cfd15dcf02e12655e30a00b356fd9a3125e8ac43904cb16fc8ac78e76f905dc8665bec9dabd50b73e3
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arel # :nodoc:
|
2
4
|
module Visitors # :nodoc:
|
3
5
|
# Different super-class under JRuby JDBC adapter.
|
@@ -5,7 +7,7 @@ module Arel # :nodoc:
|
|
5
7
|
::ArJdbc::MySQL::BindSubstitution
|
6
8
|
else
|
7
9
|
MySQL
|
8
|
-
|
10
|
+
end
|
9
11
|
|
10
12
|
class Mysql2Rgeo < MySQLSuperclass # :nodoc:
|
11
13
|
include RGeo::ActiveRecord::SpatialToSql
|
@@ -1,51 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module Mysql2Rgeo
|
4
6
|
module ColumnMethods
|
5
7
|
def spatial(name, options = {})
|
6
|
-
raise "You must set a type. For example: 't.spatial :
|
7
|
-
column(name, options[:limit][:type], options)
|
8
|
-
end
|
8
|
+
raise "You must set a type. For example: 't.spatial type: :point'" unless options[:type]
|
9
9
|
|
10
|
-
|
11
|
-
multi ? multi_geometry(*args, **options) : args.each { |name| column(name, :geometry, options) }
|
10
|
+
column(name, options[:type], options)
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
|
13
|
+
def geometry(name, options = {})
|
14
|
+
column(name, :geometry, options)
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
17
|
+
def geometry_collection(name, options = {})
|
18
|
+
column(name, :geometrycollection, options)
|
20
19
|
end
|
20
|
+
alias geometrycollection geometry_collection
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def line_string(name, options = {})
|
23
|
+
column(name, :linestring, options)
|
24
24
|
end
|
25
|
+
alias linestring line_string
|
25
26
|
|
26
|
-
def
|
27
|
-
|
27
|
+
def multi_line_string(name, options = {})
|
28
|
+
column(name, :multilinestring, options)
|
28
29
|
end
|
30
|
+
alias multilinestring multi_line_string
|
29
31
|
|
30
|
-
def
|
31
|
-
|
32
|
+
def multi_point(name, options = {})
|
33
|
+
column(name, :multipoint, options)
|
32
34
|
end
|
35
|
+
alias multipoint multi_point
|
33
36
|
|
34
|
-
def
|
35
|
-
|
37
|
+
def multi_polygon(name, options = {})
|
38
|
+
column(name, :multipolygon, options)
|
36
39
|
end
|
40
|
+
alias multipolygon multi_polygon
|
37
41
|
|
38
|
-
def
|
39
|
-
|
42
|
+
def point(name, options = {})
|
43
|
+
column(name, :point, options)
|
40
44
|
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
alias multi_polygon multipolygon
|
46
|
+
def polygon(name, options = {})
|
47
|
+
column(name, :polygon, options)
|
48
|
+
end
|
46
49
|
end
|
47
|
-
|
48
|
-
MySQL::Table.send(:include, ColumnMethods)
|
49
50
|
end
|
51
|
+
|
52
|
+
MySQL::Table.include Mysql2Rgeo::ColumnMethods
|
50
53
|
end
|
51
54
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
if RUBY_ENGINE == "jruby"
|
2
4
|
require "active_record/connection_adapters/jdbcmysql_adapter"
|
3
5
|
else
|
@@ -13,7 +15,7 @@ module ActiveRecord # :nodoc:
|
|
13
15
|
mysql2_connection(config)
|
14
16
|
end
|
15
17
|
|
16
|
-
|
18
|
+
alias_method :jdbcmysql2rgeo_connection, :mysql2rgeo_connection
|
17
19
|
|
18
20
|
else
|
19
21
|
|
@@ -29,7 +31,7 @@ module ActiveRecord # :nodoc:
|
|
29
31
|
|
30
32
|
if Mysql2::Client.const_defined? :FOUND_ROWS
|
31
33
|
if config[:flags].is_a? Array
|
32
|
-
config[:flags].push "FOUND_ROWS"
|
34
|
+
config[:flags].push "FOUND_ROWS"
|
33
35
|
else
|
34
36
|
config[:flags] |= Mysql2::Client::FOUND_ROWS
|
35
37
|
end
|
@@ -1,54 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module Mysql2Rgeo
|
4
6
|
module SchemaStatements
|
5
7
|
# override
|
6
|
-
def
|
7
|
-
|
8
|
+
def indexes(table_name) #:nodoc:
|
9
|
+
indexes = super
|
10
|
+
# HACK(aleks, 06/15/18): MySQL 5 does not support prefix lengths for spatial indexes
|
11
|
+
# https://dev.mysql.com/doc/refman/5.6/en/create-index.html
|
12
|
+
indexes.select { |idx| idx.type == :spatial }.each { |idx| idx.is_a?(Struct) ? idx.lengths = {} : idx.instance_variable_set(:@lengths, {}) }
|
13
|
+
indexes
|
8
14
|
end
|
9
15
|
|
10
16
|
def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
|
11
|
-
if (info =
|
17
|
+
if (info = RGeo::ActiveRecord.geometric_type_from_name(type.to_s.delete("_")))
|
12
18
|
type = limit[:type] || type if limit.is_a?(::Hash)
|
13
|
-
type = 'geometry' if type.to_s.eql? 'spatial'
|
14
19
|
type = type.to_s.delete("_").upcase
|
15
20
|
end
|
16
21
|
super
|
17
22
|
end
|
18
23
|
|
19
|
-
def spatial_column_constructor(name)
|
20
|
-
RGeo::ActiveRecord::DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS[name]
|
21
|
-
end
|
22
|
-
|
23
24
|
# override
|
24
25
|
def native_database_types
|
25
26
|
# Add spatial types
|
27
|
+
# Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
|
26
28
|
super.merge(
|
27
|
-
geometry:
|
28
|
-
|
29
|
-
linestring:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
geometry: { name: "geometry" },
|
30
|
+
geometrycollection: { name: "geometrycollection" },
|
31
|
+
linestring: { name: "linestring" },
|
32
|
+
multi_line_string: { name: "multilinestring" },
|
33
|
+
multi_point: { name: "multipoint" },
|
34
|
+
multi_polygon: { name: "multipolygon" },
|
35
|
+
spatial: { name: "geometry" },
|
36
|
+
point: { name: "point" },
|
37
|
+
polygon: { name: "polygon" }
|
36
38
|
)
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
def create_table_definition(*args)
|
41
|
-
Mysql2Rgeo::TableDefinition.new(*args)
|
42
|
-
end
|
43
|
-
|
44
|
-
def initialize_type_map(m)
|
41
|
+
def initialize_type_map(m = type_map)
|
45
42
|
super
|
46
43
|
%w(
|
47
44
|
geometry
|
45
|
+
geometrycollection
|
48
46
|
point
|
49
47
|
linestring
|
50
48
|
polygon
|
51
|
-
geometrycollection
|
52
49
|
multipoint
|
53
50
|
multilinestring
|
54
51
|
multipolygon
|
@@ -56,6 +53,34 @@ module ActiveRecord
|
|
56
53
|
m.register_type(geo_type, Type::Spatial.new(geo_type))
|
57
54
|
end
|
58
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# override
|
60
|
+
def create_table_definition(*args)
|
61
|
+
Mysql2Rgeo::TableDefinition.new(*args)
|
62
|
+
end
|
63
|
+
|
64
|
+
# override
|
65
|
+
def new_column_from_field(table_name, field)
|
66
|
+
type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
|
67
|
+
if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(field[:Default])
|
68
|
+
default, default_function = nil, field[:Default]
|
69
|
+
else
|
70
|
+
default, default_function = field[:Default], nil
|
71
|
+
end
|
72
|
+
|
73
|
+
SpatialColumn.new(
|
74
|
+
field[:Field],
|
75
|
+
default,
|
76
|
+
type_metadata,
|
77
|
+
field[:Null] == "YES",
|
78
|
+
table_name,
|
79
|
+
default_function,
|
80
|
+
field[:Collation],
|
81
|
+
comment: field[:Comment].presence
|
82
|
+
)
|
83
|
+
end
|
59
84
|
end
|
60
85
|
end
|
61
86
|
end
|
@@ -11,8 +11,7 @@ module ActiveRecord # :nodoc:
|
|
11
11
|
# @geometric_type = geo_type_from_sql_type(sql_type)
|
12
12
|
build_from_sql_type(sql_type_metadata.sql_type)
|
13
13
|
end
|
14
|
-
super(name, default, sql_type_metadata, null, table_name, default_function, collation)
|
15
|
-
@comment = comment
|
14
|
+
super(name, default, sql_type_metadata, null, table_name, default_function, collation, comment: comment)
|
16
15
|
if spatial?
|
17
16
|
if @srid
|
18
17
|
@limit = { type: @geometric_type.type_name.underscore }
|
@@ -35,9 +34,9 @@ module ActiveRecord # :nodoc:
|
|
35
34
|
false
|
36
35
|
end
|
37
36
|
|
37
|
+
alias :geographic? :geographic
|
38
38
|
alias :has_z? :has_z
|
39
39
|
alias :has_m? :has_m
|
40
|
-
alias :geographic? :geographic
|
41
40
|
|
42
41
|
def limit
|
43
42
|
if spatial?
|
@@ -66,7 +65,7 @@ module ActiveRecord # :nodoc:
|
|
66
65
|
end
|
67
66
|
|
68
67
|
def build_from_sql_type(sql_type)
|
69
|
-
geo_type, @srid
|
68
|
+
geo_type, @srid = Type::Spatial.parse_sql_type(sql_type)
|
70
69
|
set_geometric_type_from_name(geo_type)
|
71
70
|
end
|
72
71
|
end
|
@@ -12,9 +12,6 @@ module ActiveRecord # :nodoc:
|
|
12
12
|
end
|
13
13
|
|
14
14
|
geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type])
|
15
|
-
base_type = info[:type] || :geometry
|
16
|
-
|
17
|
-
# puts name.dup << " - " << type.to_s << " - " << options.to_s << " :: " << geo_type.to_s << " - " << base_type.to_s
|
18
15
|
|
19
16
|
options[:spatial_type] = geo_type
|
20
17
|
column = super(name, geo_type.downcase.to_sym, options)
|
@@ -26,8 +23,6 @@ module ActiveRecord # :nodoc:
|
|
26
23
|
end
|
27
24
|
end
|
28
25
|
|
29
|
-
SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial)
|
30
|
-
|
31
26
|
module ColumnDefinitionUtils
|
32
27
|
class << self
|
33
28
|
def geo_type(type = "GEOMETRY")
|
@@ -1,20 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# The activerecord-mysql2rgeo-adapter gem installs the *mysql2rgeo*
|
2
4
|
# connection adapter into ActiveRecord.
|
3
5
|
|
4
6
|
# :stopdoc:
|
5
7
|
|
6
|
-
require "active_record/connection_adapters/mysql2_adapter"
|
7
8
|
require "rgeo/active_record"
|
9
|
+
|
10
|
+
# autoload AbstractAdapter to avoid circular require and void context warnings
|
11
|
+
module ActiveRecord
|
12
|
+
module ConnectionAdapters
|
13
|
+
AbstractAdapter
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require "active_record/connection_adapters/mysql2_adapter"
|
8
18
|
require "active_record/connection_adapters/mysql2rgeo/version"
|
9
19
|
require "active_record/connection_adapters/mysql2rgeo/column_methods"
|
10
20
|
require "active_record/connection_adapters/mysql2rgeo/schema_statements"
|
11
21
|
require "active_record/connection_adapters/mysql2rgeo/spatial_table_definition"
|
12
22
|
require "active_record/connection_adapters/mysql2rgeo/spatial_column"
|
13
23
|
require "active_record/connection_adapters/mysql2rgeo/spatial_expressions"
|
14
|
-
require "arel/visitors/bind_visitor"
|
15
24
|
require "active_record/connection_adapters/mysql2rgeo/arel_tosql"
|
16
25
|
require "active_record/type/spatial"
|
17
26
|
require "active_record/connection_adapters/mysql2rgeo/create_connection"
|
27
|
+
require "active_record/tasks/database_tasks"
|
18
28
|
|
19
29
|
# :startdoc:
|
20
30
|
|
@@ -25,27 +35,28 @@ module ActiveRecord
|
|
25
35
|
|
26
36
|
SPATIAL_COLUMN_OPTIONS =
|
27
37
|
{
|
28
|
-
geometry:
|
29
|
-
geometrycollection:
|
30
|
-
linestring:
|
31
|
-
multilinestring:
|
32
|
-
multipoint:
|
33
|
-
multipolygon:
|
34
|
-
spatial:
|
35
|
-
point:
|
36
|
-
polygon:
|
38
|
+
geometry: {},
|
39
|
+
geometrycollection: {},
|
40
|
+
linestring: {},
|
41
|
+
multilinestring: {},
|
42
|
+
multipoint: {},
|
43
|
+
multipolygon: {},
|
44
|
+
spatial: { type: "geometry" },
|
45
|
+
point: {},
|
46
|
+
polygon: {}
|
37
47
|
}
|
38
48
|
|
39
49
|
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
|
40
50
|
DEFAULT_SRID = 0
|
41
51
|
|
42
|
-
ADAPTER_NAME = "Mysql2Rgeo".freeze
|
43
|
-
|
44
52
|
def initialize(connection, logger, connection_options, config)
|
45
53
|
super
|
46
54
|
|
47
55
|
@visitor = Arel::Visitors::Mysql2Rgeo.new(self)
|
48
|
-
|
56
|
+
end
|
57
|
+
|
58
|
+
def adapter_name
|
59
|
+
"Mysql2Rgeo"
|
49
60
|
end
|
50
61
|
|
51
62
|
def self.spatial_column_options(key)
|
@@ -60,45 +71,10 @@ module ActiveRecord
|
|
60
71
|
!mariadb? && version >= "5.7.6"
|
61
72
|
end
|
62
73
|
|
63
|
-
# Returns an array of indexes for the given table.
|
64
|
-
def indexes(table_name, name = nil) #:nodoc:
|
65
|
-
if name
|
66
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
67
|
-
Passing name to #indexes is deprecated without replacement.
|
68
|
-
MSG
|
69
|
-
end
|
70
|
-
|
71
|
-
indexes = []
|
72
|
-
current_index = nil
|
73
|
-
execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
|
74
|
-
each_hash(result) do |row|
|
75
|
-
if current_index != row[:Key_name]
|
76
|
-
next if row[:Key_name] == "PRIMARY" # skip the primary key
|
77
|
-
current_index = row[:Key_name]
|
78
|
-
|
79
|
-
mysql_index_type = row[:Index_type].downcase.to_sym
|
80
|
-
index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil
|
81
|
-
index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil
|
82
|
-
options = [row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence]
|
83
|
-
indexes << if mysql_index_type == :spatial
|
84
|
-
options.push(true)
|
85
|
-
Mysql2Rgeo::SpatialIndexDefinition.new(*options)
|
86
|
-
else
|
87
|
-
IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
indexes.last.columns << row[:Column_name]
|
92
|
-
indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part] && mysql_index_type != :spatial
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
indexes
|
97
|
-
end
|
98
|
-
|
99
74
|
def quote(value)
|
100
|
-
|
101
|
-
|
75
|
+
dbval = value.try(:value_for_database) || value
|
76
|
+
if RGeo::Feature::Geometry.check_type(dbval)
|
77
|
+
"ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(dbval)},#{dbval.srid})"
|
102
78
|
else
|
103
79
|
super
|
104
80
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module Type
|
3
5
|
class Spatial < Value # :nodoc:
|
@@ -14,66 +16,61 @@ module ActiveRecord
|
|
14
16
|
|
15
17
|
# sql_type: geometry, geometry(Point), geometry(Point,4326), ...
|
16
18
|
#
|
17
|
-
# returns [geo_type, srid
|
19
|
+
# returns [geo_type, srid]
|
18
20
|
# geo_type: geography, geometry, point, line_string, polygon, ...
|
19
21
|
# srid: 1234
|
20
|
-
# has_z: false
|
21
|
-
# has_m: false
|
22
22
|
def self.parse_sql_type(sql_type)
|
23
|
-
geo_type, srid
|
23
|
+
geo_type, srid = nil, 0, false, false
|
24
24
|
|
25
|
-
if sql_type =~ /
|
25
|
+
if sql_type =~ /(geography|geometry)\((.*)\)$/i
|
26
|
+
# geometry(Point)
|
26
27
|
# geometry(Point,4326)
|
27
|
-
params = Regexp.last_match(
|
28
|
-
if params.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
if params.last =~ /(\d+)/
|
35
|
-
srid = Regexp.last_match(1).to_i
|
36
|
-
end
|
37
|
-
else
|
38
|
-
# geometry(Point)
|
39
|
-
geo_type = params[0]
|
28
|
+
params = Regexp.last_match(2).split(",")
|
29
|
+
if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
|
30
|
+
geo_type = Regexp.last_match(1)
|
31
|
+
end
|
32
|
+
if params.last =~ /(\d+)/
|
33
|
+
srid = Regexp.last_match(1).to_i
|
40
34
|
end
|
41
35
|
else
|
42
36
|
# geometry
|
37
|
+
# otherType(a,b)
|
43
38
|
geo_type = sql_type
|
44
39
|
end
|
45
|
-
[geo_type, srid
|
40
|
+
[geo_type, srid]
|
46
41
|
end
|
47
42
|
|
48
|
-
def
|
49
|
-
|
43
|
+
def spatial_factory
|
44
|
+
@spatial_factory ||=
|
45
|
+
RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
|
46
|
+
geo_type: @geo_type,
|
47
|
+
sql_type: @sql_type,
|
48
|
+
srid: @srid
|
49
|
+
)
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
:geometry
|
52
|
+
def klass
|
53
|
+
type == :geometry ? RGeo::Feature::Geometry : super
|
54
54
|
end
|
55
55
|
|
56
56
|
def spatial?
|
57
57
|
true
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
|
62
|
-
RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
|
63
|
-
geo_type: @geo_type,
|
64
|
-
sql_type: @sql_type,
|
65
|
-
srid: @srid
|
66
|
-
)
|
60
|
+
def type
|
61
|
+
:geometry
|
67
62
|
end
|
68
63
|
|
69
64
|
# support setting an RGeo object or a WKT string
|
70
65
|
def serialize(value)
|
71
66
|
return if value.nil?
|
67
|
+
|
72
68
|
geo_value = cast_value(value)
|
73
69
|
|
74
70
|
# TODO - only valid types should be allowed
|
75
71
|
# e.g. linestring is not valid for point column
|
76
72
|
raise "maybe should raise" unless RGeo::Feature::Geometry.check_type(geo_value)
|
73
|
+
|
77
74
|
geo_value
|
78
75
|
end
|
79
76
|
|
@@ -81,35 +78,24 @@ module ActiveRecord
|
|
81
78
|
|
82
79
|
def cast_value(value)
|
83
80
|
return if value.nil?
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
rescue
|
103
|
-
nil
|
104
|
-
end
|
105
|
-
else
|
106
|
-
begin
|
107
|
-
RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(value)
|
108
|
-
rescue
|
109
|
-
nil
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
81
|
+
|
82
|
+
::String === value ? parse_wkt(value) : value
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_wkt(string)
|
86
|
+
marker = string[4, 1]
|
87
|
+
if marker == "\x00" || marker == "\x01"
|
88
|
+
srid = string[0, 4].unpack(marker == "\x01" ? "V" : "N").first
|
89
|
+
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(string[4..-1])
|
90
|
+
elsif string[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
|
91
|
+
srid = string[0, 8].to_i(16)
|
92
|
+
srid = [srid].pack("V").unpack("N").first if string[9, 1] == "1"
|
93
|
+
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(string[8..-1])
|
94
|
+
else
|
95
|
+
RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(string)
|
96
|
+
end
|
97
|
+
rescue RGeo::Error::ParseError, RGeo::Error::InvalidGeometry
|
98
|
+
nil
|
113
99
|
end
|
114
100
|
end
|
115
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-mysql2rgeo-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 5.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yongdae Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: rgeo-activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '6.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '6.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +116,7 @@ files:
|
|
116
116
|
- lib/activerecord-mysql2rgeo-adapter.rb
|
117
117
|
homepage: http://github.com/stadia/activerecord-mysql2rgeo-adapter
|
118
118
|
licenses:
|
119
|
-
-
|
119
|
+
- 0BSD
|
120
120
|
metadata: {}
|
121
121
|
post_install_message:
|
122
122
|
rdoc_options: []
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.6
|
137
|
+
rubygems_version: 2.7.6
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: ActiveRecord adapter for MySQL, based on RGeo.
|