Solved

Delphi TIBQuery.SQL.Text contains ' gives an error

Posted on 2006-07-04
3
292 Views
Last Modified: 2010-04-05
Hi Experts,

When executing a query runtime in Delphi which contains a " ' " (single quote) I terminates the query in gives an error?
What is the correct why of working with params which contains a ' ?

If not mistaken I am looking for something similar than PHP's stripslashes().

Thanks in advance!
0
Comment
Question by:Marius0188
3 Comments
 

Author Comment

by:Marius0188
ID: 17038021
For that matter please show me how to handle any invalid characters in a query params?
0
 
LVL 4

Expert Comment

by:kenpem
ID: 17038218
If the content of the query is under complete control of the code, use TWO single quotes within the string, as in:

Qry.SQL.Text := 'It doesn''t matter';

This is standard Object Pascal, to embed a single quote without terminating the string.

If possible, use the parameter functions to avoid conflicts:

Qry.SQL.Text := 'UPDATE Customer SET CustName = :uName';
Qry.ParamByName('uName') := EditBox1.Text;   // note that param syntax changes depending on BDE/ADO choice.

and now it shouldn't matter if the name is O'Donnell.

Hope this helps. Otherwise, paste here the bit of code that's bothering you and we'll have a go.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 17040607
there is also a quotedstr-function,
which does the double of the quotes if needed

meikl :-)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question