[mythtv] Patch: non-default MySQL port support

Sam Varshavchik mrsam at courier-mta.com
Sun Apr 16 00:53:57 UTC 2006


The following patch implements the ability to talk to a MySQL server that 
listens on a non-default port number.

After I applied this patch, I was able to run mythtv-setup in an account 
without an existing mythtv configuration.  After mythtv-setup couldn't 
connect using its default, built-in, config, it threw me into the initial 
database setup screen, where I entered the mysql server host and port, and 
the other details, after which myth succesfully connected to the server, and 
created a new schema.  I'll be doing more testing, but it looks good.

I also think that it would be helpful to add one more fix to mythdbcon.cpp, 
something on the order of:

       if (dbparms.dbPort && dbparms.dbHostName = "localhost")
               m_db->setHostName("127.0.0.1");


"localhost" is a magic value hardcoded into the mysql client library, that 
causes mysql to try to connect to mysql's default local unix socket, instead 
of the tcp port.  Even if you specify a non-default port to connect to, 
mysql will still try to connect to the default unix socket.  Using an 
explicit 127.0.0.1 in place of "localhost" avoids this.

There appears to be no way to connect to a non-default unix socket. Qt's 
MySQL driver always sets the "unix_socket" parameter to mysql_real_connect() 
to a NULL :-(  Unless you are aware of the special meaning of "localhost" to 
MySQL, you'll be tearing your hair out, trying to get myth connect to a 
non-default port on localhost.




--- libs/libmyth/dbsettings.cpp.db	2005-03-04 19:00:39.000000000 -0500
+++ libs/libmyth/dbsettings.cpp	2006-04-15 16:59:24.000000000 -0400
@@ -48,6 +48,7 @@
 protected:
     TransientLabel    *info;
     TransientLineEdit *dbHostName;
+    TransientLineEdit *dbPort;
     TransientLineEdit *dbName;
     TransientLineEdit *dbUserName;
     TransientLineEdit *dbPassword;
@@ -130,6 +131,13 @@
                                         "the machine hosting the database. "
                                         "This information is required."));
     addChild(dbHostName);
+
+    dbPort +    dbPort->setLabel(QObject::tr("Host Port"));
+    dbPort->setHelpText(QObject::tr("The port number the database is running "
+				    "on, if it's not the default database "
+				    "port."));
+    addChild(dbPort);
     
     dbName      dbName->setLabel(QObject::tr("Database"));
@@ -245,6 +253,10 @@
     dbHostName->setValue(params.dbHostName);
     if (params.dbHostName.isEmpty())
         dbHostName->setLabel("* " + dbHostName->getLabel());
+
+    if (params.dbPort)
+	    dbPort->setValue(QString::number(params.dbPort));
+
     dbUserName->setValue(params.dbUserName);
     if (params.dbUserName.isEmpty())
         dbUserName->setLabel("* " + dbUserName->getLabel());
@@ -279,6 +291,7 @@
     DatabaseParams params      
     params.dbHostName    +    params.dbPort             params.dbUserName         params.dbPassword         params.dbName        --- libs/libmyth/mythcontext.cpp.db	2006-01-25 05:22:57.000000000 -0500
+++ libs/libmyth/mythcontext.cpp	2006-04-15 17:01:10.000000000 -0400
@@ -590,8 +590,12 @@
     
     VERBOSE(VB_IMPORTANT, QString("Writing settings file %1").arg(path));
     QTextStream s(f);
-    s << "DBHostName=" << params.dbHostName << endl
-      << "DBUserName=" << params.dbUserName << endl
+    s << "DBHostName=" << params.dbHostName << endl;
+
+    if (params.dbPort)
+      s << "DBPort=" << params.dbPort << endl;
+
+    s << "DBUserName=" << params.dbUserName << endl
       << "DBPassword=" << params.dbPassword << endl
       << "DBName="     << params.dbName     << endl
       << "DBType="     << params.dbType     << endl
@@ -752,6 +756,8 @@
         
         params.dbHostName                                          params.dbHostName);
+	params.dbPort +				    params.dbPort);
         params.dbName                                              params.dbName);
         params.dbUserName @@ -2730,6 +2736,7 @@
     DatabaseParams params;
     
     params.dbHostName +    params.dbPort          params.dbUserName      params.dbPassword      params.dbName     @@ -2766,6 +2773,7 @@
     
     // only rewrite file if it has changed
     if (params.dbHostName   !+	params.dbPort       !         params.dbUserName   !         params.dbPassword   !         params.dbName       !--- libs/libmyth/mythcontext.h.db	2006-01-21 23:29:43.000000000 -0500
+++ libs/libmyth/mythcontext.h	2006-04-15 16:45:22.000000000 -0400
@@ -130,6 +130,7 @@
 struct DatabaseParams
 {
     QString dbHostName;         ///< database server
+    int     dbPort;             ///< database port
     QString dbUserName;         ///< DB user name 
     QString dbPassword;         ///< DB password
     QString dbName;             ///< database name
--- libs/libmyth/mythdbcon.cpp.db	2006-02-03 17:24:39.000000000 -0500
+++ libs/libmyth/mythdbcon.cpp	2006-04-15 16:51:12.000000000 -0400
@@ -55,6 +55,8 @@
         m_db->setUserName(dbparms.dbUserName);
         m_db->setPassword(dbparms.dbPassword);
         m_db->setHostName(dbparms.dbHostName);
+	if (dbparms.dbPort)
+		m_db->setPort(dbparms.dbPort);
         connected  
         if (!connected && dbparms.wolEnabled)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20060415/f48b3a70/attachment.pgp 


More information about the mythtv-dev mailing list