New topic: 

Why are strings written this way in queries?

<http://forums.realsoftware.com/viewtopic.php?t=30611>

       Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic         Author  
Message       dudleyH           Post subject: Why are strings written this way 
in queries?Posted: Thu Oct 22, 2009 7:24 pm                        
Joined: Wed Oct 14, 2009 7:41 pm
Posts: 4              Can someone explain why when using a String in a query 
you need to use the form:

'" + string + "'

instead of just string

example:

  rs = app.hhtDB.SQLSelect("Select * from address_list where first_name = '" + 
string + "'")
  which works

why not

  rs = app.hhtDB.SQLSelect("Select * from address_list where first_name = 
string")
  
makes me wonder what format first_name is really in?   
                            Top                dglass           Post subject: 
Re: Why are strings written this way in queries?Posted: Thu Oct 22, 2009 8:48 
pm                        
Joined: Fri Sep 30, 2005 9:29 am
Posts: 612
Location: California              If 'string' is a variable then the first 
format passes the value of the variable to the SQL engine.  The second format 
simply passes the word string to the SQL engine.

So,

Select * from address_list where first_name = '" + string + "'"

Could actually be:

Select * from address_list where first_name = 'bob'
or
Select * from address_list where first_name = 'tom'
or
Select * from address_list where first_name = 'steve'

Depending on what value is held in string

While

Select * from address_list where first_name = string

Will, 
a) either fail because there is no column named string, or
b) always be 

Select * from address_list where first_name = string

and to be honest, string would be a very uncommon first name.   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 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]

Reply via email to