bmsd/mysql.c

changeset 799
cf145b35d65f
parent 747
b6fbe6821468
child 843
29e7223e37ae
--- a/bmsd/mysql.c	Tue Jul 19 13:55:53 2022 +0200
+++ b/bmsd/mysql.c	Fri Jul 22 12:15:05 2022 +0200
@@ -3,7 +3,7 @@
  * @brief MySQL/MariaDB access.
  * @author Michiel Broek <mbroek at mbse dot eu>
  *
- * Copyright (C) 2018-2021
+ * Copyright (C) 2018-2022
  *
  * This file is part of the bms (Brewery Management System)
  *
@@ -32,6 +32,8 @@
 MYSQL_RES			*res_set;
 MYSQL_ROW			row;
 
+my_bool				reconnect = 1;
+
 extern sys_config       	Config;
 extern sys_node_list		*nodes;
 extern sys_fermenter_list	*fermenters;
@@ -72,6 +74,8 @@
 	return 1;
     }
 
+    mysql_options(con, MYSQL_OPT_RECONNECT, &reconnect);
+
     if (mysql_real_connect(con, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) {
 	syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con));
 	return 2;
@@ -475,34 +479,11 @@
 	return 0;
     }
 
-    /* Any error execpt server gone away */
-    if (err != 2006)
-	return rc;
-
-    syslog(LOG_NOTICE, "Trying to reconnect");
-    /* Try to reconnect and do the query again */
-    mysql_close(con);
-    if (mysql_real_connect(con, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) {
-        syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con));
-        return 2;
-    }
-    syslog(LOG_NOTICE, "MySQL: reconnected.");
-    rc = mysql_query(con, query);
-    if (rc) {
-        syslog(LOG_NOTICE, "MySQL: error %u (%s)", mysql_errno(con), mysql_error(con));
-        syslog(LOG_NOTICE, query);
-    }
     return rc;
 }
 
 
 
-void bms_mysql_ping(void)
-{
-}
-
-
-
 void node_mysql_insert(sys_node_list *node)
 {
     char	*query = malloc(1024), first[73], last[73];

mercurial