1

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&#39;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:

  1. delphi finds and reads file contents into a TStringStream with LoadfromFile MyStream.LoadFromFile(Sp_xmlfile);
  2. 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 &#39; 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.

4

1 回答 1

1

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):

  • double each single quote inside of the constant and prepend it by '\'. So, a ' will become \''.
  • double quotes rather not need a special handling.
  • probably disable macros handling, because '&' may be a macro specifier in the data access library.
于 2012-08-19T06:56:06.613 回答