FR with MySQL - Stored Procedures

Thomas Martens thomas.martens at desy.de
Thu May 10 11:16:24 CEST 2007


I added your hack to my version too.
I also don't get any errors till now. It seems to work with SP, and also
normal SQL-querys.

I've modified your patch with some comments and also added a
mysql_version check, so that the patch will only apply to MySQL version
> 5.

Here is the diff...so please, a FR developer take a look at it;)

Thanks, Thomas

--- sql_mysql.c 2007-05-08 15:55:47.000000000 +0200
+++ sql_mysql.c 2007-05-10 10:56:33.000000000 +0200
@@ -75,6 +75,7 @@

        mysql_init(&(mysql_sock->conn));
        mysql_options(&(mysql_sock->conn), MYSQL_READ_DEFAULT_GROUP,
"freeradius");
+
        if (!(mysql_sock->sock = mysql_real_connect(&(mysql_sock->conn),
                                                    config->sql_server,
                                                    config->sql_login,
@@ -82,7 +83,16 @@
                                                    config->sql_db,

atoi(config->sql_port),
                                                    NULL,
-                                                   CLIENT_FOUND_ROWS)))
{
+                                                   CLIENT_FOUND_ROWS
+                                                   #if MYSQL_VERSION_ID
>= 50000
+                                                       /*
+                                                        * the
CLIENT_MULTI_STATEMENTS flag also include the
+                                                        *
CLIENT_MULTI_RESULT flag, these are necessary for
+                                                        * Stored
Procedures (MySQL 5.x)
+                                                        */
+                                                       |
CLIENT_MULTI_STATEMENTS
+                                                   #endif
+                                                   ))) {
                radlog(L_ERR, "rlm_sql_mysql: Couldn't connect socket to
MySQL server %s@%s:%s", config->sql_login, config->sql_server,
config->sql_db);
                radlog(L_ERR, "rlm_sql_mysql: Mysql error '%s'",
mysql_error(&mysql_sock->conn));
                mysql_sock->sock = NULL;
@@ -289,6 +299,18 @@
        if (sqlsocket->row == NULL) {
                return sql_check_error(mysql_errno(mysql_sock->sock));
        }
+
+       #if MYSQL_VERSION_ID >= 50000
+               /*
+                * Stored Procedures return two results (the result and
affected rows),
+                * so FR fails with a mysql errorcode 2014
(CR_COMMANDS_OUT_OF_SYNC),
+                * when a second mysql-query is executed
+                *
+                * so we drop the second result (assume FR expect just
one result)
+                */
+               mysql_next_result(mysql_sock->sock);
+       #endif
+
        return 0;
 }





More information about the Freeradius-Users mailing list