[libgda] Correction for bug #691069, MySQL: Cannot specify the protocol



commit 25d2de4ed5de311c836faa676b08eeeab1e876ae
Author: Vivien Malerba <malerba gnome-db org>
Date:   Thu Jan 3 22:36:59 2013 +0100

    Correction for bug #691069, MySQL: Cannot specify the protocol

 providers/mysql/gda-mysql-provider.c         |   53 ++++++++++++++++++++++++-
 providers/mysql/mysql_specs_create_db.xml.in |   27 +++++++++++++
 providers/mysql/mysql_specs_drop_db.xml.in   |   30 ++++++++++++++
 providers/mysql/mysql_specs_dsn.xml.in       |   29 ++++++++++++++
 4 files changed, 136 insertions(+), 3 deletions(-)
---
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index 4087aa4..e7396bd 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -473,6 +473,7 @@ gda_mysql_provider_get_version (G_GNUC_UNUSED GdaServerProvider  *provider)
 
 /*
  * Open a MYSQL connection.
+ * If @port <= 0 then @port is not used.
  */
 static MYSQL *
 real_open_connection (const gchar  *host,
@@ -483,6 +484,7 @@ real_open_connection (const gchar  *host,
 		      const gchar  *password,
 		      gboolean      use_ssl,
 		      gboolean      compress,
+		      const gchar  *proto,
 		      GError      **error)
 {
 	unsigned int flags = CLIENT_FOUND_ROWS;
@@ -496,6 +498,13 @@ real_open_connection (const gchar  *host,
 		return NULL;
 	}
 
+	if (port > 65535) {
+		g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_MISUSE_ERROR,
+			     "%s", 
+			     _("Invalid port number"));
+		return NULL;
+	} 
+
 	/* Defaults. */
 	if (!socket) {
 		if (!host)
@@ -512,6 +521,37 @@ real_open_connection (const gchar  *host,
 	MYSQL *mysql = g_new0 (MYSQL, 1);
 	mysql_init (mysql);
 
+	if ((port > 0) || proto) {
+		gint p = MYSQL_PROTOCOL_DEFAULT;
+		if (proto) {
+			if (! g_ascii_strcasecmp (proto, "DEFAULT"))
+				p = MYSQL_PROTOCOL_DEFAULT;
+			else if (! g_ascii_strcasecmp (proto, "TCP"))
+				p = MYSQL_PROTOCOL_TCP;
+			else if (! g_ascii_strcasecmp (proto, "SOCKET"))
+				p = MYSQL_PROTOCOL_SOCKET;
+			else if (! g_ascii_strcasecmp (proto, "PIPE"))
+				p = MYSQL_PROTOCOL_PIPE;
+			else if (! g_ascii_strcasecmp (proto, "MEMORY"))
+				p = MYSQL_PROTOCOL_MEMORY;
+			else {
+				g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_OPEN_ERROR,
+					     _("Unknown MySQL protocol '%s'"), proto);
+				g_free (mysql);
+				return NULL;
+			}
+		}
+		else
+			p = MYSQL_PROTOCOL_TCP;
+
+		if (mysql_options (mysql, MYSQL_OPT_PROTOCOL, (const char *) &p)) {
+			g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_OPEN_ERROR,
+				     "%s", mysql_error (mysql));
+			g_free (mysql);
+			return NULL;
+		}
+	}
+
 	MYSQL *return_mysql = mysql_real_connect (mysql, host,
 						  username, password,
 #if MYSQL_VERSION_ID >= 32200
@@ -612,11 +652,12 @@ gda_mysql_provider_open_connection (GdaServerProvider               *provider,
 	if (!password)
 		password = gda_quark_list_find (params, "PASSWORD");
 
-	const gchar *port, *unix_socket, *use_ssl, *compress;
+	const gchar *port, *unix_socket, *use_ssl, *compress, *proto;
 	port = gda_quark_list_find (params, "PORT");
 	unix_socket = gda_quark_list_find (params, "UNIX_SOCKET");
 	use_ssl = gda_quark_list_find (params, "USE_SSL");
 	compress = gda_quark_list_find (params, "COMPRESS");
+	proto = gda_quark_list_find (params, "PROTOCOL");
 	
 	/* open the real connection to the database */
 	/* TO_ADD: C API specific function calls;
@@ -624,11 +665,12 @@ gda_mysql_provider_open_connection (GdaServerProvider               *provider,
 	// TO_IMPLEMENT;
 	
 	GError *error = NULL;
-	MYSQL *mysql = real_open_connection (host, (port != NULL) ? atoi (port) : 0,
+	MYSQL *mysql = real_open_connection (host, (port != NULL) ? atoi (port) : -1,
 					     unix_socket, db_name,
 					     user, password,
 					     (use_ssl && ((*use_ssl == 't') || (*use_ssl == 'T'))) ? TRUE : FALSE,
 					     (compress && ((*compress == 't') || (*compress == 'T'))) ? TRUE : FALSE,
+					     proto,
 					     &error);
 	if (!mysql) {
 		GdaConnectionEvent *event_error = gda_connection_point_available_event (cnc, GDA_CONNECTION_EVENT_ERROR);
@@ -969,6 +1011,7 @@ gda_mysql_provider_perform_operation (GdaServerProvider               *provider,
 		gint         port = -1;
 		const gchar *socket = NULL;
 		gboolean     usessl = FALSE;
+		const gchar *proto = NULL;
 
 		value = gda_server_operation_get_value_at (op, "/SERVER_CNX_P/HOST");
 		if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
@@ -994,8 +1037,12 @@ gda_mysql_provider_perform_operation (GdaServerProvider               *provider,
 		if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
 			password = g_value_get_string (value);
 
+		value = gda_server_operation_get_value_at (op, "/SERVER_CNX_P/PROTO");
+		if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
+			proto = g_value_get_string (value);
+
 		mysql = real_open_connection (host, port, socket,
-                                              "mysql", login, password, usessl, FALSE, error);
+                                              "mysql", login, password, usessl, FALSE, proto, error);
                 if (!mysql)
                         return FALSE;
 		else {
diff --git a/providers/mysql/mysql_specs_create_db.xml.in b/providers/mysql/mysql_specs_create_db.xml.in
index 3453887..3f344c9 100644
--- a/providers/mysql/mysql_specs_create_db.xml.in
+++ b/providers/mysql/mysql_specs_create_db.xml.in
@@ -8,6 +8,7 @@
     <parameter id="ADM_LOGIN" _name="Administrator login" _descr="Login name (which has the rights to create databases)" gdatype="gchararray"/>
     <parameter id="ADM_PASSWORD" _name="Administrator password" gdatype="gchararray" plugin="string:HIDDEN=true"/>
     <parameter id="USE_SSL" _name="Require SSL" _descr="Whether or not to use SSL to establish the connection" gdatype="gboolean"/>
+    <parameter id="PROTOCOL" _name="Connection protocol" _descr="Explicitly specifies a connection protocol to use. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want" gdatype="string" source="proto:0"/>
   </parameters>
 
     <!-- DSN parameters -->
@@ -164,5 +165,31 @@
         </gda_array_row>
       </gda_array_data>
     </gda_array>
+    <gda_array name="proto">
+      <gda_array_field name="id" gdatype="gchararray"/>
+      <gda_array_field name="text" gdatype="gchararray"/>
+      <gda_array_data>
+        <gda_array_row>
+          <gda_value>DEFAULT</gda_value>
+          <_gda_value>Automatic</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>TCP</gda_value>
+          <_gda_value>TCP: TCP/IP connection to local or remote server.</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>SOCKET</gda_value>
+          <_gda_value>Socket: Unix socket file connection to local server (Local Unix server only).</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>PIPE</gda_value>
+          <_gda_value>Pipe: Named-pipe connection to local or remote server (Windows server only)</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>MEMORY</gda_value>
+          <_gda_value>Memory: Shared-memory connection to local server (Local Windows server only)</_gda_value>
+        </gda_array_row>
+      </gda_array_data>
+    </gda_array>
   </sources>
 </serv_op>
diff --git a/providers/mysql/mysql_specs_drop_db.xml.in b/providers/mysql/mysql_specs_drop_db.xml.in
index be10e2c..2474308 100644
--- a/providers/mysql/mysql_specs_drop_db.xml.in
+++ b/providers/mysql/mysql_specs_drop_db.xml.in
@@ -8,6 +8,7 @@
     <parameter id="USE_SSL" _name="Require SSL" _descr="Whether or not to use SSL to establish the connection" gdatype="gboolean"/>
     <parameter id="ADM_LOGIN" _name="Administrator login" _descr="Login name (which has the rights to create databases)" gdatype="gchararray"/>
     <parameter id="ADM_PASSWORD" _name="Administrator password" gdatype="gchararray" plugin="string:HIDDEN=true"/>
+    <parameter id="PROTOCOL" _name="Connection protocol" _descr="Explicitly specifies a connection protocol to use. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want" gdatype="string" source="proto:0"/>
   </parameters>
 
     <!-- DSN parameters -->
@@ -15,4 +16,33 @@
     <parameter id="DB_NAME" _name="Database name" _descr="The name of a database to create" gdatype="gchararray" nullok="FALSE"/>
     <parameter id="DB_IFEXISTS" _name="Only if existing" _descr="Drop database only if it exists" gdatype="gboolean"/>
   </parameters>
+
+  <sources>
+    <gda_array name="proto">
+      <gda_array_field name="id" gdatype="gchararray"/>
+      <gda_array_field name="text" gdatype="gchararray"/>
+      <gda_array_data>
+        <gda_array_row>
+          <gda_value>DEFAULT</gda_value>
+          <_gda_value>Automatic</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>TCP</gda_value>
+          <_gda_value>TCP: TCP/IP connection to local or remote server.</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>SOCKET</gda_value>
+          <_gda_value>Socket: Unix socket file connection to local server (Local Unix server only).</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>PIPE</gda_value>
+          <_gda_value>Pipe: Named-pipe connection to local or remote server (Windows server only)</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>MEMORY</gda_value>
+          <_gda_value>Memory: Shared-memory connection to local server (Local Windows server only)</_gda_value>
+        </gda_array_row>
+      </gda_array_data>
+    </gda_array>
+  </sources>
 </serv_op>
diff --git a/providers/mysql/mysql_specs_dsn.xml.in b/providers/mysql/mysql_specs_dsn.xml.in
index c1db88c..8eedaea 100644
--- a/providers/mysql/mysql_specs_dsn.xml.in
+++ b/providers/mysql/mysql_specs_dsn.xml.in
@@ -7,5 +7,34 @@
     <parameter id="UNIX_SOCKET" _name="UNIX Socket" _descr="Full path of the UNIX socket to use when connecting locally" gdatype="gchararray"/>
     <parameter id="USE_SSL" _name="Require SSL" _descr="Whether or not to use SSL to establish the connection" gdatype="gboolean"/>
     <parameter id="COMPRESS" _name="Compress" _descr="Use compression protocol" gdatype="gboolean"/>
+    <parameter id="PROTOCOL" _name="Connection protocol" _descr="Explicitly specifies a connection protocol to use. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want" gdatype="string" source="proto:0"/>
   </parameters>
+  <sources>
+    <gda_array name="proto">
+      <gda_array_field name="id" gdatype="gchararray"/>
+      <gda_array_field name="text" gdatype="gchararray"/>
+      <gda_array_data>
+        <gda_array_row>
+          <gda_value>DEFAULT</gda_value>
+          <_gda_value>Automatic</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>TCP</gda_value>
+          <_gda_value>TCP: TCP/IP connection to local or remote server.</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>SOCKET</gda_value>
+          <_gda_value>Socket: Unix socket file connection to local server (Local Unix server only).</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>PIPE</gda_value>
+          <_gda_value>Pipe: Named-pipe connection to local or remote server (Windows server only)</_gda_value>
+        </gda_array_row>
+        <gda_array_row>
+          <gda_value>MEMORY</gda_value>
+          <_gda_value>Memory: Shared-memory connection to local server (Local Windows server only)</_gda_value>
+        </gda_array_row>
+      </gda_array_data>
+    </gda_array>
+  </sources>
 </data-set-spec>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]