Hi All Does anyone know how to use the MySQL cmd in Asterisk with LIKE and % in the query? I have: exten => s,5,Set(query=SELECT name from contacts where tel like %${number}) exten => s,6,MySQL(Connect connid hostname username password dbname) exten => s,7,MySQL(Query resultid ${connid} ${query}) But there seems to be a problem with the % sign and I don't know how to hash it out. It works without the % sign. Thanks Kind Regards Garth
Try enclosing in single quotes. ie. SELECT name from contacts where tel like '%${number}' Jon Farmer Telford, Shropshire, UK ----- Original Message ---- From: Garth van Sittert <garth@bitco.co.za> To: Asterisk Users Mailing List - Non-Commercial Discussion <asterisk-users@lists.digium.com> Sent: Monday, 4 December, 2006 12:38:07 PM Subject: [asterisk-users] MySQL cmd % pattern matching Hi All Does anyone know how to use the MySQL cmd in Asterisk with LIKE and % in the query? I have: exten => s,5,Set(query=SELECT name from contacts where tel like %${number}) exten => s,6,MySQL(Connect connid hostname username password dbname) exten => s,7,MySQL(Query resultid ${connid} ${query}) But there seems to be a problem with the % sign and I don't know how to hash it out. It works without the % sign. Thanks Kind Regards Garth _______________________________________________ --Bandwidth and Colocation provided by Easynews.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users ___________________________________________________________ All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine http://uk.docs.yahoo.com/nowyoucan.html
Garth van Sittert wrote:> exten => s,5,Set(query=SELECT name from contacts where tel like > %${number}) > exten => s,6,MySQL(Connect connid hostname username password dbname) > exten => s,7,MySQL(Query resultid ${connid} ${query}) >This is how I would do it: exten => s,5,MYSQL(Query resultid ${connid} SELECT name FROM contacts WHERE tel = ${number}) exten => s,6,MYSQL(Fetch fetchid ${resultid} contact.name) exten => s,7,MYSQL(Disconnect ${connid}) exten => s,8,MYSQL(Clear ${resultid}) Doug -- Ben Franklin quote: "Those who would give up Essential Liberty to purchase a little Temporary Safety, deserve neither Liberty nor Safety."
I have it working as your example, Doug, but unfortunately I need the like phrase as the numbers all contain spaces or sometimes even brackets. Garth Doug Lytle wrote:> Garth van Sittert wrote: >> exten => s,5,Set(query=SELECT name from contacts where tel like >> %${number}) >> exten => s,6,MySQL(Connect connid hostname username password dbname) >> exten => s,7,MySQL(Query resultid ${connid} ${query}) >> > This is how I would do it: > > exten => s,5,MYSQL(Query resultid ${connid} SELECT name FROM contacts > WHERE tel = ${number}) > exten => s,6,MYSQL(Fetch fetchid ${resultid} contact.name) > exten => s,7,MYSQL(Disconnect ${connid}) > exten => s,8,MYSQL(Clear ${resultid}) > > Doug >
Ah, I found the solution to my problem: I slashed out the ' to give: exten => s,5,Set(query=SELECT name from contacts where tel like \'%${number}\') exten => s,6,MySQL(Connect connid hostname username password dbname) exten => s,7,MySQL(Query resultid ${connid} ${query}) Kind Regards Garth Garth van Sittert wrote:> Hi All > > Does anyone know how to use the MySQL cmd in Asterisk with LIKE and % > in the query? > > I have: > > exten => s,5,Set(query=SELECT name from contacts where tel like > %${number}) > exten => s,6,MySQL(Connect connid hostname username password dbname) > exten => s,7,MySQL(Query resultid ${connid} ${query}) > > But there seems to be a problem with the % sign and I don't know how > to hash it out. > It works without the % sign. > > Thanks > > Kind Regards > Garth > > _______________________________________________ > --Bandwidth and Colocation provided by Easynews.com -- > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users