Date: Monday, February 13, 2006 @ 13:44:23
  Author: zsolt
    Path: /cvsroot/carob/libmysequoia/src

Modified: CarobMySQL.cpp (1.47 -> 1.48)

- try to guess the default port to connect if no port was given. The strategy 
is the following: if from the config file the 3306 port was read first try to 
connect to sequoia hardcoded port (25322) and if this fails then tries the port 
3306.


----------------+
 CarobMySQL.cpp |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)


Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.47 
libmysequoia/src/CarobMySQL.cpp:1.48
--- libmysequoia/src/CarobMySQL.cpp:1.47        Fri Feb  3 14:30:16 2006
+++ libmysequoia/src/CarobMySQL.cpp     Mon Feb 13 13:44:23 2006
@@ -101,6 +101,8 @@
 {
   LOG4CXX_DEBUG(logger, "Entering connect: host=" << host << " user=" << user 
<< " passwd=" << passwd << " db=" << db << " port=" << port);
   
+  bool defaultport = port == 0;
+  
   if (mysqlPtr->status != MYSQL_STATUS_READY)
   {
     set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
@@ -150,7 +152,10 @@
     
   if (!port)
   {
-    port = mysqlPtr->options.port;
+    //check if the cnf file contains the hardcoded mysql port (3306)
+    //if so, then first try to connect to the default sequoia port (25322)
+    //and if is unsuccessful, then to the 3306 port.
+    port = mysqlPtr->options.port == 3306 ? 25322 : mysqlPtr->options.port;
     if (!port)
       port = 25322;
   }
@@ -179,7 +184,25 @@
     ConnectionParameters connectionParameters(fromString(host), port, 
       fromString(db), fromString(user), fromString(passwd), DEBUG_LEVEL_DEBUG);
 
-    Connection *newConnectionPtr = new Connection(connectionParameters);
+    Connection *newConnectionPtr;
+    
+    try {
+      newConnectionPtr = new Connection(connectionParameters);
+    }
+    catch (CarobException &e)
+    {
+      //if the default port was given and the connection to port 25322
+      //failed we try the 3306 port
+      if (defaultport && (port == 25322))
+      {
+        ConnectionParameters connectionParameters2(fromString(host), 3306,
+          fromString(db), fromString(user), fromString(passwd), 
DEBUG_LEVEL_DEBUG);
+        newConnectionPtr = new Connection(connectionParameters2);
+      }
+      else
+        throw;
+    }
+    
     if (newConnectionPtr)
     {
       //TODO handle not enough memory
@@ -307,8 +330,10 @@
 
   if (mysqlPtr->status != MYSQL_STATUS_GET_RESULT)
   {
-    set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
-    LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
+       //If the status is not get_result we don't throw cr_commands_out_of_sync
+       //this is required by PHP5
+/*    set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+    LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");*/
     return 0;
   }
 

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to