Countless fixes, ext-grade started:
[mailer.git] / inc / db / lib-mysql3.php
index 6a11f697f10bdbd08f0b8cc81bf3be3c357240df..03f3079edc7d89284f4ccb775c91db511b7490d7 100644 (file)
@@ -378,7 +378,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
        $tableName = str_replace('`', '', $tableArray[2]);
 
        // Debug log
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ',tableName=' . $tableName);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ',tableName=' . $tableName . ',tableArray=<pre>' . print_r($tableArray, true) . '</pre>');
 
        // Shall we add/drop?
        if (((strpos($sql, 'ADD') !== false) || (strpos($sql, 'DROP') !== false) || (strpos($sql, 'CHANGE') !== false)) && ($noIndex === true)) {
@@ -424,14 +424,15 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
                // Skip this query silently because InnoDB does not understand fulltext indexes
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,tableName=%s,hasZeroNums=%d,file=%s,line=%s", $sql, $tableName, intval((is_bool($result)) ? 0 : isSqlTableColumnFound($columnName)), $F, $L));
        } elseif ($noIndex === false) {
-               // And column name as well
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableArray=<pre>' . print_r($tableArray, true) . '</pre>');
+               // And column name as well without backticks
                $keyName = str_replace('`', '', $tableArray[5]);
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . ',tableArray=<pre>' . print_r($tableArray, true) . '</pre>');
 
                // Is this "UNIQUE" or so? FULLTEXT has been handled the elseif() block above
-               if (in_array(strtoupper($keyName), array('INDEX', 'UNIQUE', 'KEY', 'FULLTEXT'))) {
+               if (in_array(strtoupper($tableArray[4]), array('INDEX', 'UNIQUE', 'KEY', 'FULLTEXT'))) {
                        // Init loop
-                       $begin = 1; $keyName = ',';
+                       $begin = 1;
+                       $keyName = ',';
                        while (strpos($keyName, ',') !== false) {
                                // Use last
                                $keyName = str_replace('`', '', $tableArray[count($tableArray) - $begin]);
@@ -447,13 +448,18 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
                } // END - if
 
                // Shall we run it?
-               if (!isSqlTableIndexAdded($tableName, $tableArray[3], $keyName)) {
-                       // Send it to the SQL_QUERY() function
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql);
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ', tableArray[3]=' . $tableArray[3] . ',keyName=' . $keyName);
+               if ((!isSqlTableIndexAdded($tableName, $tableArray[3], $keyName)) && ($tableArray[3] == 'ADD')) {
+                       // Send it to the SQL_QUERY() function to add it
+                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql);
+                       $result = SQL_QUERY($sql, $F, $L, $enableCodes);
+               } elseif ((isSqlTableIndexAdded($tableName, $tableArray[3], $keyName)) && ($tableArray[3] == 'DROP')) {
+                       // Send it to the SQL_QUERY() function to drop it
+                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql);
                        $result = SQL_QUERY($sql, $F, $L, $enableCodes);
                } else {
                        // Not executed
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not executed: ' . $sql);
+                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not executed: ' . $sql);
                }
        } else {
                // Other ALTER TABLE query