New topic: Single Quote in a SQLSelect Statement:
<http://forums.realsoftware.com/viewtopic.php?t=31432> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message Jennifer Post subject: Single Quote in a SQLSelect Statement:Posted: Sun Dec 06, 2009 1:16 am Joined: Fri Sep 30, 2005 9:30 pm Posts: 1690 Location: U.S.A. Is there a way to write a sql select statement that uses user entered info from getting an error if the user enters a single quote? I have the following code and it works unless the account name has a single quote in the name. For example, I type in "D's" and I get an error. Would it be easier just to parse the input for the single quote? Code:s = "select * from accounts where name ='" + account_ComboBox.text + "'" rs = db.SQLSelect(s) _________________ Education, not legislation! Top timhare Post subject: Re: Single Quote in a SQLSelect Statement:Posted: Sun Dec 06, 2009 1:43 am Joined: Fri Jan 06, 2006 3:21 pm Posts: 6892 Location: Portland, OR USA Use ReplaceAll to change a single quote into two single quotes. Code:s = ReplaceAll(account_ComboBox.text, "'", "''") s = "select * from accounts where name ='" + s+ "'" rs = db.SQLSelect(s) Tim Top Jennifer Post subject: Re: Single Quote in a SQLSelect Statement:Posted: Sun Dec 06, 2009 2:56 am Joined: Fri Sep 30, 2005 9:30 pm Posts: 1690 Location: U.S.A. Good answer. Thank you. I didn't even think of that. _________________ Education, not legislation! Top jefftullin Post subject: Re: Single Quote in a SQLSelect Statement:Posted: Sun Dec 06, 2009 4:59 am Joined: Wed Nov 15, 2006 3:50 pm Posts: 1047 Quote:Use ReplaceAll to change a single quote into two single quotes. Second most common problem in the databases forum. (The first is: why didn't my code work? A: you have to check for errors after every sql statement is executed) These are tip numbers 8 and 12 in the sticky post which appears at the top of the Database Forum. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
