Solved

Delphi TIBQuery.SQL.Text contains ' gives an error

Posted on 2006-07-04
3
294 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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