0

I have this query

  db.query("
  UPDATE tm
  SET DESCRIPTION = 'SQL Injection (CALL \'C_DB_FUNCTION\')'
  WHERE DESCRIPTION = 'SQL Injection (CALL \'C DB FUNCTION\')';
  ")

This query is working on the DB, but when I tried to run it via ruby with mysql2 gem, I got the below 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 'C_DB_FUNCTION')' (Mysql2::Error)

I guess its because the backslash,

How I can escape it or fix it ?

Thanks!

3
  • 1
    add escape slash '\'. dev.mysql.com/doc/refman/5.7/en/… Commented Sep 28, 2016 at 11:26
  • 1
    db.query(" UPDATE tm SET DESCRIPTION = 'SQL Injection (CALL \\'C_DB_FUNCTION\\')' WHERE DESCRIPTION = 'SQL Injection (CALL \\'C DB FUNCTION\\')'; ") Commented Sep 28, 2016 at 11:26
  • @dinesh thanks ! write it as an answer and I will mark it as the correct answer for this issue. Commented Sep 28, 2016 at 11:29

1 Answer 1

3

Special Character Escape Sequences please find the http://dev.mysql.com/doc/refman/5.7/en/string-literals.html#character-escape-sequences

db.query(" UPDATE tm SET DESCRIPTION = 'SQL Injection (CALL \\'C_DB_FUNCTION\\')' WHERE DESCRIPTION = 'SQL Injection (CALL \\'C DB FUNCTION\\')'; ")

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.