[Gambas-user] Mysql query question

Ron ron at ...1740...
Wed Nov 5 01:09:12 CET 2008


Benoit Minisini wrote:
> On mardi 4 novembre 2008, Ron wrote:
>   
>> Hi,
>>
>> I'm replacing my buggy mysql query's for correct ones...
>>
>> All is well except for this one...
>>
>> DIM sTable as String = "remarks_tags"
>>
>> Main.hDB.Exec("SELECT text FROM " & sTable & " ORDER BY rand() LIMIT 1")
>> This works ok...
>>
>> Replaced by...
>>
>> Main.hDB.Exec("SELECT text FROM &1 ORDER BY rand() LIMIT 1", sTable)
>>
>> Which results in an SQL query syntax error, is this correct behavior?
>>
>> Any ideas?
>>
>> Regards,
>> Ron_2nd
>>
>>     
>
> &1, &2... are there for quoting SQL values, not SQL table or field names. 
>
> Moreover, if you want to insert a table or field name in a SQL request, you 
> should use the DB.Quote() function:
>
> Main.hDB.Exec("SELECT text FROM " & DB.Quote(sTable) & " ORDER BY rand() LIMIT 
> 1")
>
>   

Ok got it, works ok now.

Thanks.






More information about the User mailing list