New topic: Masking special characters
<http://forums.realsoftware.com/viewtopic.php?t=41609> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message vfran Post subject: Masking special charactersPosted: Mon Nov 28, 2011 2:30 pm Joined: Mon Dec 07, 2009 7:30 pm Posts: 62 I have a slight problem with users entering names in DB with single quotes. This causes problems to search from db later. Eg user enters name: "Kellog's" Later when trying to retrieve data about the record: "Kellog's" a nil error occurs. I can read the db into a listbox fine using: sql = "SELECT name FROM carblist ORDER BY name" But when searching specifically for name with single quotes I get an error? sql = "SELECT * FROM '"+listevalg+"' WHERE name= '"+ app.foodselect+"'" Does anyone have a suggestion? Thanks Top markwalsh Post subject: Re: Masking special charactersPosted: Mon Nov 28, 2011 2:54 pm Joined: Wed May 20, 2009 4:43 pm Posts: 630 vfran wrote:I have a slight problem with users entering names in DB with single quotes. This causes problems to search from db later. Eg user enters name: "Kellog's" Later when trying to retrieve data about the record: "Kellog's" a nil error occurs. I can read the db into a listbox fine using: sql = "SELECT name FROM carblist ORDER BY name" But when searching specifically for name with single quotes I get an error? sql = "SELECT * FROM '"+listevalg+"' WHERE name= '"+ app.foodselect+"'" Does anyone have a suggestion? Thanks You need to escape the single quotes by replacing them with 2 single quotes when used in an SQL statement: sql = "SELECT * FROM '"+listevalg+"' WHERE name= '" + replaceAll(app.foodselect, "'", "''") + "'" The same applies if 'listevalg' could contain single quotes as well. _________________ RB 2009r4 Windows XP Top vfran Post subject: Re: Masking special charactersPosted: Mon Nov 28, 2011 3:12 pm Joined: Mon Dec 07, 2009 7:30 pm Posts: 62 Thanks, Mark! I got it Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 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]
