Some more fixes and dependency between bonus<->sql_patches
[mailer.git] / inc / db / lib-mysql3.php
index 7a33983a1ec2d59cb71e9ae08a518dc84280d4c5..ccf777eb426e302cf4bd49168928ea2e649dbc2b 100644 (file)
@@ -451,7 +451,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
                } // END - if
 
                // Shall we run it?
-               if (!isSqlTableIndexAdded($tableName, $tableArray[3])) {
+               if (!isSqlTableIndexAdded($tableName, $tableArray[3], $keyName)) {
                        // Send it to the SQL_QUERY() function
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql);
                        $result = SQL_QUERY($sql, $F, $L, $enableCodes);
@@ -552,23 +552,24 @@ function SQL_PREPARE_SQL_STRING ($sqlString, $enableCodes = true) {
 }
 
 // Check if there is a SQL table created
-function isSqlTableCreated ($table) {
+function isSqlTableCreated ($tableName) {
        // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__][$table])) {
+       if (!isset($GLOBALS[__FUNCTION__][$tableName])) {
                // Check if the table is there
                $result = SQL_QUERY_ESC("SHOW TABLES FROM `{?__DB_NAME?}` WHERE `Tables_in_{?__DB_NAME?}`='{?_MYSQL_PREFIX?}_%s'",
-                       array($table), __FILE__, __LINE__);
+                       array($tableName), __FILE__, __LINE__);
 
                // Is there an entry?
-               $GLOBALS[__FUNCTION__][$table] = (SQL_NUMROWS($result) == 1);
+               $GLOBALS[__FUNCTION__][$tableName] = (SQL_NUMROWS($result) == 1);
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',numRows=' . intval($GLOBALS[__FUNCTION__][$tableName]));
        } // END - if
 
        // Return cache
-       return $GLOBALS[__FUNCTION__][$table];
+       return $GLOBALS[__FUNCTION__][$tableName];
 }
 
 // Checks depending on the mode if the table is there
-function isSqlTableIndexAdded ($tableName, $mode) {
+function isSqlTableIndexAdded ($tableName, $mode, $keyName) {
        // Do we have cache?
        if (!isset($GLOBALS[__FUNCTION__][$tableName][$mode])) {
                // Show indexes
@@ -580,8 +581,8 @@ function isSqlTableIndexAdded ($tableName, $mode) {
                // But should we DROP?
                if ($mode == 'DROP') {
                        // Then skip if nothing found
-                       $GLOBALS[__FUNCTION__][$tableName][$mode] = true;
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Going to drop key ' . $keyName);
+                       $GLOBALS[__FUNCTION__][$tableName][$mode] = true;
                } // END - if
 
                // Walk through all