[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kexi/kexidb/drivers/mySQL
From:       Jaroslaw Staniek <js () iidea ! pl>
Date:       2005-02-27 21:06:27
Message-ID: 20050227210627.30C09148A2 () office ! kde ! org
[Download RAW message or body]

CVS commit by staniek: 

KexiDB
- MySQL Driver: a hack to enable local connections without using 
  a local socket file: if user doesn't want to use local socket file,
  host name is automatically set (internally) to "127.0.0.1" 
  before connecting. This is especially usable when we're using SSH
  tunneling.


  M +1 -6      mysqlconnection.cpp   1.23
  M +33 -20    mysqlconnection_p.cpp   1.2
  M +3 -3      mysqlconnection_p.h   1.3


--- koffice/kexi/kexidb/drivers/mySQL/mysqlconnection.cpp  #1.22:1.23
@@ -51,10 +51,5 @@ MySqlConnection::~MySqlConnection() {
 
 bool MySqlConnection::drv_connect() {
-  return d->db_connect(
-                m_data->hostName.local8Bit(), 
-                m_data->userName.local8Bit(),
-                m_data->password.local8Bit(),
-                m_data->port,
-                m_data->localSocketFileName);
+  return d->db_connect(*m_data);
 }
 

--- koffice/kexi/kexidb/drivers/mySQL/mysqlconnection_p.cpp  #1.1:1.2
@@ -28,4 +28,6 @@ Boston, MA 02111-1307, USA.
 #include "mysqlconnection_p.h"
 
+#include <kexidb/connectiondata.h>
+
 #ifdef MYSQLMIGRATE_H
 #define NAMESPACE KexiMigration
@@ -64,6 +66,7 @@ void MySqlConnectionInternal::storeError
     the port that the remote server is listening on.
  */
-bool MySqlConnectionInternal::db_connect(QCString host, QCString user,
-  QCString password, unsigned short int port, QString socket)
+//bool MySqlConnectionInternal::db_connect(QCString host, QCString user,
+//  QCString password, unsigned short int port, QString socket)
+bool MySqlConnectionInternal::db_connect(const KexiDB::ConnectionData& data)
 {
         if (!(mysql = mysql_init(mysql)))
@@ -72,8 +75,11 @@ bool MySqlConnectionInternal::db_connect
         KexiDBDrvDbg << "MySqlConnectionInternal::connect()" << endl;
         QCString localSocket;
-        if (host.isEmpty() || (host=="localhost")) {
-                if (socket.isEmpty()) {
+        QString hostName = data.hostName;
+        if (hostName.isEmpty() || hostName.lower()=="localhost") {
+                if (data.useLocalSocketFile) {
+                        if (data.localSocketFileName.isEmpty()) {
+        //! @todo move the list of default sockets to a generic method
                         QStringList sockets;
-#ifndef Q_WS_WIN
+        #ifndef Q_WS_WIN
                         sockets.append("/var/lib/mysql/mysql.sock");
                         sockets.append("/var/run/mysqld/mysqld.sock");
@@ -87,15 +93,22 @@ bool MySqlConnectionInternal::db_connect
                                 }
                         }
-#endif
+        #endif
                 }
                 else
-                        localSocket=socket.local8Bit();
+                                localSocket = QFile::encodeName(data.localSocketFileName);
+                }
+                else {
+                        //we're not using local socket
+                        hostName = "127.0.0.1"; //this will force mysql to connect to localhost
+                }
         }
 
-        mysql_real_connect(mysql, host, user, password, 0, port, localSocket, 0);
+/*! @todo is latin1() encoding here valid? waht about using UTF for passwords? */
+        mysql_real_connect(mysql, hostName.latin1(), data.userName.latin1(), 
+                data.password.latin1(), 0, data.port, localSocket, 0);
         if(mysql_errno(mysql) == 0)
                 return true;
 
-        storeError(); //store error msg, if any - can be destroyed after disconenct()
+        storeError(); //store error msg, if any - can be destroyed after disconnect()
         db_disconnect();
 //      setError(ERR_DB_SPECIFIC,err);

--- koffice/kexi/kexidb/drivers/mySQL/mysqlconnection_p.h  #1.2:1.3
@@ -39,4 +39,6 @@ class QString;
 namespace NAMESPACE {
 
+class ConnectionData;
+
 //! Internal MySQL connection data.
 /*! Provides a low-level API for accessing MySQL databases, that can
@@ -51,6 +52,5 @@ class MySqlConnectionInternal
                 ~MySqlConnectionInternal();
                 //! Connect to a MySQL database
-                bool db_connect(QCString host, QCString user, QCString password,
-                                unsigned short int port, QString socket);
+                bool db_connect(const KexiDB::ConnectionData& data);
                 //! Disconnect from the database
                 bool db_disconnect();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic