[mythtv] Patch: non-default MySQL port support

Chris Petersen lists at forevermore.net
Sun Apr 16 03:01:03 UTC 2006


http://svn.mythtv.org/trac/newticket

(or you'll likely never be heard)

-Chris

Sam Varshavchik wrote:
> 
> 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 = new TransientLineEdit(true);
> +    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 = new TransientLineEdit(true);
>     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 = gContext->GetDatabaseParams();
>         params.dbHostName    = dbHostName->getValue();
> +    params.dbPort        = dbPort->getValue().toInt();
>     params.dbUserName    = dbUserName->getValue();
>     params.dbPassword    = dbPassword->getValue();
>     params.dbName        = dbName->getValue();
> --- 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 = getResponse("Database host name:",
>                                         params.dbHostName);
> +    params.dbPort = intResponse("Database non-default port:",
> +                    params.dbPort);
>         params.dbName     = getResponse("Database name:",
>                                         params.dbName);
>         params.dbUserName = getResponse("Database user name:",
> @@ -2730,6 +2736,7 @@
>     DatabaseParams params;
>         params.dbHostName = d->m_settings->GetSetting("DBHostName", 
> "localhost");
> +    params.dbPort     = d->m_settings->GetNumSetting("DBPort", 0);
>     params.dbUserName = d->m_settings->GetSetting("DBUserName", "mythtv");
>     params.dbPassword = d->m_settings->GetSetting("DBPassword", "mythtv");
>     params.dbName     = d->m_settings->GetSetting("DBName",     
> "mythconverg");
> @@ -2766,6 +2773,7 @@
>         // only rewrite file if it has changed
>     if (params.dbHostName   != cur_params.dbHostName          ||
> +    params.dbPort       != cur_params.dbPort              ||
>         params.dbUserName   != cur_params.dbUserName          ||
>         params.dbPassword   != cur_params.dbPassword          ||
>         params.dbName       != cur_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 = m_db->open();
> 
>         if (!connected && dbparms.wolEnabled)
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


More information about the mythtv-dev mailing list