Hi,
When using sql_xquery() like this:
sql_xquery("ca", "SELECT * FROM gateways", "gateways");
... what's a good way to check if any rows were returned? Since one does not have a $dbr(gateways=>rows) value in this scenario, what should one do?
- is_avp_set("$xavp(gateways=>id)")) does not appear to operate on XAVPs, or at least, the fixup functions reject them:
ERROR: avpops [avpops.c:935]: fixup_is_avp_set(): bad attribute name <$xavp(gateways=>id)>
- the 'defined' operator does not appear to return a negative condition here:
if(!defined $xavp(gateways=>id))
This condition evaluates to true.
Much appreciated!
-- Alex
Hello,
I withdraw this question on grounds of idiocy. My query was returning a row when I thought it wasn't.
In actual fact,
if(!defined $xavp(gateways=>id))
works just fine, because the xavp list is null in that case.
On 04/05/2014 11:32 AM, Alex Balashov wrote:
Hi,
When using sql_xquery() like this:
sql_xquery("ca", "SELECT * FROM gateways", "gateways");
... what's a good way to check if any rows were returned? Since one does not have a $dbr(gateways=>rows) value in this scenario, what should one do?
- is_avp_set("$xavp(gateways=>id)")) does not appear to operate on
XAVPs, or at least, the fixup functions reject them:
ERROR: avpops [avpops.c:935]: fixup_is_avp_set(): bad attribute name <$xavp(gateways=>id)>
- the 'defined' operator does not appear to return a negative condition
here:
if(!defined $xavp(gateways=>id))
This condition evaluates to true.
Much appreciated!
-- Alex
When I use xquery, I generally use it with a stored procedure that returns a value if not matched... so I always return at least one row with a variable of 'fail', -1, etc. to evaluate.
I like this for a variety of reasons (ie changing sql without changing the config)... but that being said...
Wouldn't this still work for you:
if($dbr(gateways=>rows)>0) { }
Fred Posner The Palner Group, Inc. 503-914-0999 (direct) 954-472-2896 (fax)
On 04/05/2014 11:32 AM, Alex Balashov wrote:
Hi,
When using sql_xquery() like this:
sql_xquery("ca", "SELECT * FROM gateways", "gateways");
... what's a good way to check if any rows were returned? Since one does not have a $dbr(gateways=>rows) value in this scenario, what should one do?
- is_avp_set("$xavp(gateways=>id)")) does not appear to operate on
XAVPs, or at least, the fixup functions reject them:
ERROR: avpops [avpops.c:935]: fixup_is_avp_set(): bad attribute name <$xavp(gateways=>id)>
- the 'defined' operator does not appear to return a negative condition
here:
if(!defined $xavp(gateways=>id))
This condition evaluates to true.
Much appreciated!
-- Alex
On 04/05/2014 11:42 AM, Fred Posner wrote:
When I use xquery, I generally use it with a stored procedure that returns a value if not matched... so I always return at least one row with a variable of 'fail', -1, etc. to evaluate.
I actually do that too in many cases, but only because I often need to pass back additional data about what went wrong (for logging) if no row was found, so returning a row regardless, with a status column (with a value like -1) and hijacking another column for some kind of human-readable explanation.
I like this for a variety of reasons (ie changing sql without changing the config)... but that being said...
Wouldn't this still work for you:
if($dbr(gateways=>rows)>0) { }
I don't think so. As I understood the documentation, at least, $dbr doesn't get populated in this case; the rows just go straight to an xavp list. I suppose I should verify that.
I don't think so. As I understood the documentation, at least, $dbr doesn't get populated in this case; the rows just go straight to an xavp list. I suppose I should verify that.
Looks like you're right.
Tested various methods.
Fred Posner The Palner Group, Inc. 503-914-0999 (direct) 954-472-2896 (fax)
On 04/05/2014 11:45 AM, Alex Balashov wrote:
On 04/05/2014 11:42 AM, Fred Posner wrote:
When I use xquery, I generally use it with a stored procedure that returns a value if not matched... so I always return at least one row with a variable of 'fail', -1, etc. to evaluate.
I actually do that too in many cases, but only because I often need to pass back additional data about what went wrong (for logging) if no row was found, so returning a row regardless, with a status column (with a value like -1) and hijacking another column for some kind of human-readable explanation.
I like this for a variety of reasons (ie changing sql without changing the config)... but that being said...
Wouldn't this still work for you:
if($dbr(gateways=>rows)>0) { }
I don't think so. As I understood the documentation, at least, $dbr doesn't get populated in this case; the rows just go straight to an xavp list. I suppose I should verify that.
On 04/05/2014 12:14 PM, Fred Posner wrote:
I don't think so. As I understood the documentation, at least, $dbr doesn't get populated in this case; the rows just go straight to an xavp list. I suppose I should verify that.
Looks like you're right.
Tested various methods.
This does make me wonder if there is a "leak" of result handles here, since sql_result_free() is not possible, but presumably there's an internal result handle still getting allocated. Or maybe that was for the memory allocated to the $dbr(...) data only and independent of the underlying DB API.
dunno if this helps but i use $sqlrows(ca) to check whether there are rows returned
Kelvin Chua
On Sat, Apr 5, 2014 at 9:15 AM, Alex Balashov abalashov@evaristesys.comwrote:
On 04/05/2014 12:14 PM, Fred Posner wrote:
I don't think so. As I understood the documentation, at least, $dbr doesn't get populated in this case; the rows just go straight to an xavp list. I suppose I should verify that.
Looks like you're right.
Tested various methods.
This does make me wonder if there is a "leak" of result handles here, since sql_result_free() is not possible, but presumably there's an internal result handle still getting allocated. Or maybe that was for the memory allocated to the $dbr(...) data only and independent of the underlying DB API.
-- Alex Balashov - Principal Evariste Systems LLC 235 E Ponce de Leon Ave Suite 106 Decatur, GA 30030 United States Tel: +1-678-954-0670 Web: http://www.evaristesys.com/, http://www.alexbalashov.com/
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Does that work for SELECT queries? The documentation says it's only for INSERT, UPDATE and DELETE.
On 6 April 2014 02:14:24 CEST, Kelvin Chua kelchy@gmail.com wrote:
dunno if this helps but i use $sqlrows(ca) to check whether there are rows returned
Kelvin Chua
On Sat, Apr 5, 2014 at 9:15 AM, Alex Balashov abalashov@evaristesys.comwrote:
On 04/05/2014 12:14 PM, Fred Posner wrote:
I don't think so. As I understood the documentation, at least,
$dbr
doesn't get populated in this case; the rows just go straight to
an
xavp list. I suppose I should verify that.
Looks like you're right.
Tested various methods.
This does make me wonder if there is a "leak" of result handles here, since sql_result_free() is not possible, but presumably there's an
internal
result handle still getting allocated. Or maybe that was for the
memory
allocated to the $dbr(...) data only and independent of the
underlying DB
API.
-- Alex Balashov - Principal Evariste Systems LLC 235 E Ponce de Leon Ave Suite 106 Decatur, GA 30030 United States Tel: +1-678-954-0670 Web: http://www.evaristesys.com/, http://www.alexbalashov.com/
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing
list
sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
-- Sent from my mobile, and thus lacking in the refinement one might expect from a fully fledged keyboard.
Alex Balashov - Principal Evariste Systems LLC 235 E Ponce de Leon Ave Suite 106 Decatur, GA 30030 United States Tel: +1-678-954-0671 Web: http://www.evaristesys.com/, http://www.alexbalashov.com
On 04/05/2014 09:01 PM, Alex Balashov wrote:
Does that work for SELECT queries? The documentation says it's only for INSERT, UPDATE and DELETE.
It did not during my test this afternoon.
--fred
On 6 April 2014 02:14:24 CEST, Kelvin Chua kelchy@gmail.com wrote:
dunno if this helps but i use $sqlrows(ca) to check whether there are rows returned Kelvin Chua On Sat, Apr 5, 2014 at 9:15 AM, Alex Balashov <abalashov@evaristesys.com <mailto:abalashov@evaristesys.com>> wrote: On 04/05/2014 12:14 PM, Fred Posner wrote: > I don't think so. As I understood the documentation, at least, $dbr > doesn't get populated in this case; the rows just go straight to an > xavp list. I suppose I should verify that. > Looks like you're right. Tested various methods. This does make me wonder if there is a "leak" of result handles here, since sql_result_free() is not possible, but presumably there's an internal result handle still getting allocated. Or maybe that was for the memory allocated to the $dbr(...) data only and independent of the underlying DB API. -- Alex Balashov - Principal Evariste Systems LLC 235 E Ponce de Leon Ave Suite 106 Decatur, GA 30030 United States Tel: +1-678-954-0670 <tel:%2B1-678-954-0670> Web: http://www.evaristesys.com/, http://www.alexbalashov.com/ _________________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org <mailto:sr-users@lists.sip-router.org> http://lists.sip-router.org/__cgi-bin/mailman/listinfo/sr-__users <http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users> ------------------------------------------------------------------------ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
-- Sent from my mobile, and thus lacking in the refinement one might expect from a fully fledged keyboard.
Alex Balashov - Principal Evariste Systems LLC 235 E Ponce de Leon Ave Suite 106 Decatur, GA 30030 United States Tel: +1-678-954-0671 Web: http://www.evaristesys.com/, http://www.alexbalashov.com
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
no, it's not for SELECT. $dbr for SELECTs
Kelvin Chua
On Sat, Apr 5, 2014 at 6:16 PM, Fred Posner fred@palner.com wrote:
On 04/05/2014 09:01 PM, Alex Balashov wrote:
Does that work for SELECT queries? The documentation says it's only for INSERT, UPDATE and DELETE.
It did not during my test this afternoon.
--fred
On 6 April 2014 02:14:24 CEST, Kelvin Chua kelchy@gmail.com wrote:
dunno if this helps but i use $sqlrows(ca) to check whether there are rows returned Kelvin Chua On Sat, Apr 5, 2014 at 9:15 AM, Alex Balashov <abalashov@evaristesys.com <mailto:abalashov@evaristesys.com>> wrote: On 04/05/2014 12:14 PM, Fred Posner wrote: > I don't think so. As I understood the documentation, at least, $dbr > doesn't get populated in this case; the rows just go straight to an > xavp list. I suppose I should verify that. > Looks like you're right. Tested various methods. This does make me wonder if there is a "leak" of result handles here, since sql_result_free() is not possible, but presumably there's an internal result handle still getting allocated. Or maybe that was for the memory allocated to the $dbr(...) data only and independent of the underlying DB API. -- Alex Balashov - Principal Evariste Systems LLC 235 E Ponce de Leon Ave Suite 106 Decatur, GA 30030 United States Tel: +1-678-954-0670 <tel:%2B1-678-954-0670> Web: http://www.evaristesys.com/, http://www.alexbalashov.com/ _________________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org <mailto:sr-users@lists.sip-
router.org> http://lists.sip-router.org/__cgi-bin/mailman/listinfo/sr-__users< http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users%3E
------------------------------------------------------------
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing
list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
-- Sent from my mobile, and thus lacking in the refinement one might expect from a fully fledged keyboard.
Alex Balashov - Principal Evariste Systems LLC 235 E Ponce de Leon Ave Suite 106 Decatur, GA 30030 United States Tel: +1-678-954-0671 Web: http://www.evaristesys.com/, http://www.alexbalashov.com
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
On 04/06/2014 12:37 AM, Kelvin Chua wrote:
$dbr for SELECTs
Unless it's not, because you're using sql_xquery(). :-)
Have you tried something like...
if (sql_xquery("ca", "SELECT * FROM gateways", "gateways") == 1) { #do stuff } else { #dang nabbit }
Fred Posner The Palner Group, Inc. 503-914-0999 (direct) 954-472-2896 (fax)
On 04/06/2014 02:37 PM, Alex Balashov wrote:
On 04/06/2014 12:37 AM, Kelvin Chua wrote:
$dbr for SELECTs
Unless it's not, because you're using sql_xquery(). :-)
On 04/07/2014 08:57 AM, Fred Posner wrote:
Have you tried something like...
if (sql_xquery("ca", "SELECT * FROM gateways", "gateways") == 1) { #do stuff } else { #dang nabbit }
I haven't, but I've been satisfied with this as a solution:
sql_xquery("ca", "SELECT * FROM gateways", "gateways");
if(!defined $xavp(gateways)) { # dang nabbit }
On Saturday 05 April 2014 17:32:18 Alex Balashov wrote:
When using sql_xquery() like this:
sql_xquery("ca", "SELECT * FROM gateways", "gateways");
... what's a good way to check if any rows were returned? Since one does not have a $dbr(gateways=>rows) value in this scenario, what should one do?
All sqlops query functions have (undocumented) return values:
-1: error in parameters or query execution 1: query successful, at least one row in resultset (for SELECTs) 2: query successful, no rows returned
It might be useful to extend $sqlrows() to return the number of rows in the resultset.
On 04/08/2014 03:45 AM, Alex Hermann wrote:
All sqlops query functions have (undocumented) return values:
-1: error in parameters or query execution 1: query successful, at least one row in resultset (for SELECTs) 2: query successful, no rows returned
Ah, right! I forgot to check the undocumented return values. :-)
Thanks!