为什么 ActiveRecord 无法为 GeoRuby 设备输出有效的 SQL INSERT 语句?
我正在使用 spatial_adapter 和 GeoRuby 创建一个具有地理位置的 Rails 应用程序。在开发模式下运行实际应用程序时,一切正常,但当尝试使用 YAML 固定装置时,我收到 MySQL 语法错误。我正在使用以下固定装置:
one:
name: Event One
starts_at: 2011-04-20 12:00:00
ends_at: 2011-04-20 16:00:00
topics:
- topic1
- topic2
pos: !ruby/object:Point
x: 10
y: 10
使用 Test::Ruby
或 RSpec 运行它会给出以下错误:
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '), '2011-05-05 20:57:34', '2011-05-05 20:57:34', 908014535)'
at line 1: INSERT INTO `events` (`name`, `starts_at`, `ends_at`, `pos`, `created_at`, `updated_at`, `id`) VALUES ('Lindy Jam', '2011-04-20 12:00:00', '2011-04-20 16:00:00', GeomFromWKB(0x010100000000000000000024400000000000002440,), '2011-05-05 20:57:34', '2011-05-05 20:57:34', 908014535)
关键似乎在这一点上:
GeomFromWKB(0x010100000000000000000024400000000000002440,),
括号内有一个额外的逗号。我不知道这是从哪里来的,但它适用于开发模式应用程序中的常规插入。
堆栈跟踪是:
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `rescue in log'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract_adapter.rb:199:in `log'
/var/lib/gems/1.9.1/gems/mysql2-0.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:314:in `execute'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:239:in `insert_fixture'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:646:in `block in insert_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:582:in `each'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:582:in `insert_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:526:in `block (4 levels) in create_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:526:in `each'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:526:in `block (3 levels) in create_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:524:in `block (2 levels) in create_fixtures'
/var/lib/gems/1.9.1/gems/mysql2-0.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:232:in `disable_referential_integrity'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:515:in `block in create_fixtures'
/var/lib/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/benchmarkable.rb:55:in `silence'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:514:in `create_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:973:in `load_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:938:in `setup_fixtures'
/var/lib/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:425:in `_run_setup_callbacks'
/var/lib/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/testing/setup_and_teardown.rb:34:in `run'
我在 Ubuntu 11.04 上运行 Rails 3.0.7 和 Ruby 1.9.2。
I am creating a rails application with geographical locations using spatial_adapter and GeoRuby. When running the actual application in development mode, everything works fine, but when trying to use YAML fixtures, I get a MySQL syntax error. I am using the following fixture:
one:
name: Event One
starts_at: 2011-04-20 12:00:00
ends_at: 2011-04-20 16:00:00
topics:
- topic1
- topic2
pos: !ruby/object:Point
x: 10
y: 10
Running this, either with Test::Ruby
or RSpec gives the following error:
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '), '2011-05-05 20:57:34', '2011-05-05 20:57:34', 908014535)'
at line 1: INSERT INTO `events` (`name`, `starts_at`, `ends_at`, `pos`, `created_at`, `updated_at`, `id`) VALUES ('Lindy Jam', '2011-04-20 12:00:00', '2011-04-20 16:00:00', GeomFromWKB(0x010100000000000000000024400000000000002440,), '2011-05-05 20:57:34', '2011-05-05 20:57:34', 908014535)
The key seems to be at this point:
GeomFromWKB(0x010100000000000000000024400000000000002440,),
With an extra comma inside the parenthesis. I don't know where this is coming from, but it is working for regular insertions in the development-mode app.
The stack trace is:
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `rescue in log'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract_adapter.rb:199:in `log'
/var/lib/gems/1.9.1/gems/mysql2-0.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:314:in `execute'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:239:in `insert_fixture'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:646:in `block in insert_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:582:in `each'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:582:in `insert_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:526:in `block (4 levels) in create_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:526:in `each'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:526:in `block (3 levels) in create_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:524:in `block (2 levels) in create_fixtures'
/var/lib/gems/1.9.1/gems/mysql2-0.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:232:in `disable_referential_integrity'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:515:in `block in create_fixtures'
/var/lib/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/benchmarkable.rb:55:in `silence'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:514:in `create_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:973:in `load_fixtures'
/var/lib/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/fixtures.rb:938:in `setup_fixtures'
/var/lib/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:425:in `_run_setup_callbacks'
/var/lib/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/testing/setup_and_teardown.rb:34:in `run'
I am running rails 3.0.7 with Ruby 1.9.2 on Ubuntu 11.04.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果发现这是
spatial_adapter
中的错误。它期望几何对象上有一个srid
属性,但由于某种原因,当装置创建 GeoRuby 对象时没有设置该属性。临时解决方法是在 YAML 文件中手动添加
srid
属性,如下所示:其中
-1
只是“未指定 srid”的占位符。Turns out it's an error in
spatial_adapter
. It expects there to be ansrid
attribute on the geometry objects, but for some reason one isn't set when the fixtures create a GeoRuby object.A temporary workaround is to manually add an
srid
attribute in the YAML file like this:Where
-1
is just a placeholder for "unspecified srid".