Vorrei riportarvi questo messaggio apparso nella M.L.I.:
" I have a database which conntains a string 'Queen's Head' so
hResult = hConn.Exec("SELECT contacts.* FROM contacts WHERE Title = 'Queen's Head'")
How best to solve this?
bill-lancaster "
" It's because Queen's Head has a ' in the string.
I always use:
Var="Queen's Head"
hResult=hConn.Exec("SELECT contacts.* FROM contacts WHERE Title=" & "\"" & Var & "\"")
or
hResult=hConn.Exec("SELECT contacts.* FROM contacts WHERE Title=" & Chr(34) & Var & Chr(34))
Maybe there other solutions, I'm not a professional programmer.
Johny "
" This is even shorter:
hResult = hConn.Exec("SELECT contacts.* FROM contacts WHERE Title='Queen\\'s Head'")
Since ' is meaningful in MySQL, you have to mask it with \ and since you do
this in a Gambas string constant, you have to double the backslash.
Regards,
Tobi "
" And this work also:
hResult = hConn.Exec("SELECT contacts.* FROM contacts WHERE Title=&1" ,"'Queen's Head'") ' that is the gambas way
or
hResult = hConn.Exec("SELECT contacts.* FROM contacts WHERE Title =" & Replace("'Queen's Head'","'","''")) ' that is the SQL way
** both examples not tested
--
Amicalement
Charlie "