0

I am trying to write a query to dump a single LONGBLOB data into a file.

SELECT data FROM table WHERE id = 123 
INTO DUMPFILE fileName

which data, fileName, and id are the fields in the table.

SQL syntax error near fileName occurred when I try to run this query in HeidiSQL 10.2.0.

Does anyone know how to fix this error?

The database is MariaDB 5.5.


The following query works fine by the way:

SELECT data FROM table WHERE id = 123 
INTO DUMPFILE 'data.pdf'
1
  • May be you have done a kind of SQL-injection due to the bug of the HeidiSQL. It would be better to post a PR on the HeidiSQL's forum.
    – Kondybas
    Sep 3 '19 at 9:53
0

Because the fileName value is from the database you don't need to put the single quotes around it.

SELECT data FROM table WHERE id = 123 
INTO DUMPFILE fileName

I'm not sure how filenames with spaces will come out though if you have any. You could always protect against that by using REPLACE on the filename to either remove them or swap them out with a different character before hand.

1
  • This will not work. Did you try it?
    – Philᵀᴹ
    Sep 3 '19 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.