【发布时间】:2018-10-18 02:32:13
【问题描述】:
当我点击页面时,我在本地看到此错误:
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 'and reference_number > ) ORDER BY reference_number asc LIMIT 1' at line 1:
这是什么意思?此查询在生产中不会失败,但在本地会失败。在 digitalOcean 我看到了这个:
ssh <username>@107.170.112.8
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Wed Oct 17 22:25:21 EDT 2018
System load: 1.26 Processes: 108
Usage of /: 80.1% of 157.36GB Users logged in: 0
Memory usage: 59% IP address for eth0: 107.170.112.8
Swap usage: 2% IP address for eth1: 10.128.133.134
Graph this data and manage this system at:
https://landscape.canonical.com/
414 packages can be updated.
294 updates are security updates.
Last login: Wed Oct 17 22:25:22 2018 from 65.200.165.210
<username>:~$ mysql --version
mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.3
我的 msql 版本之间是否存在不匹配?
有问题的查询(Rails 4.15 中的 activeRecord)是这样的:
other_catalog_item = @current_checkout_location.checked_in_current_catalog_items
.where("catalog_section_id = #{selected_catalog_item.catalog_section_id} and reference_number > #{selected_catalog_item.reference_number}")
.order('reference_number asc')
.limit(1).first
问题是...如果我在本地更改它,我会冒生产中断的风险。我该怎么办?这个问题的根源是什么?
【问题讨论】:
-
它的 rails 和 activeRecord
-
and reference_number > )... 错误消息似乎是说第二个参数没有从您的 Rails 代码中绑定。您可能希望包含进行此 MySQL 调用的代码。 -
所以当您点击该页面时,您没有在生产中看到该错误?
-
(1)
selected_catalog_item.reference_number是nil,您应该更新您的测试套件以涵盖这种情况。 (2) 为什么要对 SQL 使用字符串插值?您应该使用占位符。 -
我的本地数据是否很糟糕且不完整?
标签: mysql ruby-on-rails activerecord