0

I am seeing this error locally when I hit a page:

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:

What does this mean? This query does not fail on production but it does locally. On digitalOcean I see this:

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

Is there a mismatch between my my msql versions?

The query (activeRecord in Rails 4.15) in question is this:

 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

The thing is... if I change it locally, I run the risk that production breaks. What should I do? What is the root of this problem?

5
  • Its rails and activeRecord Commented Oct 18, 2018 at 3:36
  • 1
    and reference_number > ) ... the error message seems to be saying that the second parameter is not getting bound from your Rails code. You might want to include the code which is making this MySQL call. Commented Oct 18, 2018 at 3:40
  • So you dont see that error in production when you hit that page? Commented Oct 18, 2018 at 4:21
  • 1
    (1) selected_catalog_item.reference_number is nil, you should update your test suite to cover this case. (2) Why are you using string interpolation for SQL? You should be using placeholders. Commented Oct 18, 2018 at 4:50
  • Is it likely the case that I my local data is terrible and incomplete? Commented Oct 18, 2018 at 13:43

1 Answer 1

1

Look into this

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:

and reference_number > ) is wrong mysql adapters. It's up to your data in local and production are different, selected_catalog_item has no reference_number, so it causes the issue

reference_number > #{selected_catalog_item.reference_number}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.