I have Delphi application with mydac stored procedure component which takes an utf8 encoded xml file’s content as string parameter.
It works with navicat and other db managment programs when I put this xml content copy-paste from file to procedure like
CALL sp_saveit('<xml>garry's<otherdata> data data....</xml>);
But when I try to call it from delphi it throws 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 'CALL sp_saveit('<?xml version=\"1.0\" encoding="UTF-8"?><Main><Detail z') at line 1
Am following those steps:
- delphi finds and reads file contents into a TStringStream with LoadfromFile
MyStream.LoadFromFile(Sp_xmlfile); - then am passing contents to stored procedure
T_ContentsSP.ParamByName('XmlFile').AsWideString := MyStream.DataString;
Also I’ve tried to compress this data with delphi’s zlib and send as blob, I’ve tried to change ' with ‘ but result was same.
How can I send a long string with single and double quotes inside as parameter for sp with delphi?
p.s : sorry for my english.
From your post, I see that you tried to use a constant value (
I put this xml content copy-paste) and a parameter (T_ContentsSP.ParamByName('XmlFile')). Also, try to show error text for the command you are used, and not for a different command.When you are using parameters you does not need to do any special preparation. Data access components have transparently send parameter values to a DBMS. If they have tracing output, then check the trace, what library is sending to a DBMS. Parameter usage is always prefered agains literal usage !
When you are using a constant, then you should (more):
'will become\''.