[OpenSIPS-Users] db_mysql_convert_rows says no rows but there is one

Calvin Ellison calvin.ellison at voxox.com
Fri Mar 20 17:17:49 EST 2020


We developed a small patch to check if there is a second result set
when the first result set has zero rows. It's pretty specific and
probably shouldn't be merged, but might help someone else if they are
stuck in a similar situation.

modules/db_mysql/dbase.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/modules/db_mysql/dbase.c b/modules/db_mysql/dbase.c
index cb2abcff3..e487c2ed1 100644
--- a/modules/db_mysql/dbase.c
+++ b/modules/db_mysql/dbase.c
@@ -863,8 +863,17 @@ static int db_mysql_store_result(const db_con_t*
_h, db_res_t** _r)
                return -2;
        }

-       if (!CON_HAS_PS(_h))
-               CON_RESULT(_h) = mysql_store_result(CON_CONNECTION(_h));
+        if (!CON_HAS_PS(_h)) {
+                CON_RESULT(_h) = mysql_store_result(CON_CONNECTION(_h));
+                int currentRes = mysql_num_rows(CON_RESULT(_h));
+                if(currentRes == 0) {
+                        int next = mysql_next_result(CON_CONNECTION(_h));
+                        if(next == 0) {
+                                CON_RESULT(_h) =
mysql_store_result(CON_CONNECTION(_h));
+                        }
+                }
+        }
+
        if (!CON_RESULT(_h)) {
                if (mysql_errno(CON_CONNECTION(_h)) > 0) {
                        LM_ERR("driver error: %s\n",
mysql_error(CON_CONNECTION(_h)));
--


Regards,

Calvin Ellison
Senior Voice Operations Engineer
calvin.ellison at voxox.com



More information about the Users mailing list