changeset 19528:a7fcd12d0d83

mysql: Don't require connect setting to have host-parameter if option_file is set. The option_file could also specify the host.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 31 Dec 2015 04:26:01 +0200
parents 207586dae1e1
children 0c2e2cba8a5b
files src/lib-sql/driver-mysql.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-sql/driver-mysql.c	Wed Dec 30 08:21:46 2015 -0500
+++ b/src/lib-sql/driver-mysql.c	Thu Dec 31 04:26:01 2015 +0200
@@ -72,7 +72,8 @@
 
 static const char *mysql_prefix(struct mysql_db *db)
 {
-	return t_strdup_printf("mysql(%s)", db->host);
+	return db->host == NULL ? "mysql" :
+		t_strdup_printf("mysql(%s)", db->host);
 }
 
 static int driver_mysql_connect(struct sql_db *_db)
@@ -88,7 +89,12 @@
 
 	sql_db_set_state(&db->api, SQL_DB_STATE_CONNECTING);
 
-	if (*db->host == '/') {
+	if (db->host == NULL) {
+		/* assume option_file overrides the host, or if not we'll just
+		   connect to localhost */
+		unix_socket = NULL;
+		host = NULL;
+	} else if (*db->host == '/') {
 		unix_socket = db->host;
 		host = NULL;
 	} else {
@@ -235,7 +241,7 @@
 			*field = p_strdup(db->pool, value);
 	}
 
-	if (db->host == NULL)
+	if (db->host == NULL && db->option_file == NULL)
 		i_fatal("mysql: No hosts given in connect string");
 
 	db->mysql = mysql_init(NULL);