-// ALTER TABLE wrapper function
-function SQL_ALTER_TABLE ($sql, $F, $L) {
- // This is the default result...
- $result = false;
-
- // Determine index/fulltext/unique word
- // 12 3 3 2 2 3 3 2 2 3 3 21
- $noIndex = ((ereg("INDEX", $sql) == false) && (ereg("FULLTEXT", $sql) == false) && (ereg("UNIQUE", $sql) == false));
-
- // Extract table name
- $tableArray = explode(" ", $sql);
- $tableName = str_replace("`", "", $tableArray[2]);
-
- // Shall we add/drop?
- if (((ereg("ADD", $sql)) || (ereg("DROP", $sql))) && ($noIndex)) {
- // And column name as well
- $columnName = str_replace("`", "", $tableArray[4]);
-
- // Get column information
- $result = SQL_QUERY_ESC("SHOW COLUMNS FROM %s LIKE '%s'",
- array($tableName, $columnName), __FILE__, __LINE__);
-
- // Do we have no entry on ADD or an entry on DROP?
- // 123 4 4 3 3 4 432 23 4 4 3 3 4 4321
- if (((SQL_NUMROWS($result) == 0) && (ereg("ADD", $sql))) || ((SQL_NUMROWS($result) == 1) && (ereg("DROP", $sql)))) {
- // Do the query
- //* DEBUG: */ print __LINE__.":".$sql."<br />\n";
- $result = SQL_QUERY($sql, $F, $L, false);
- } // END - if
- } elseif ((constant('_TABLE_TYPE') == "InnoDB") && (ereg("FULLTEXT", $sql))) {
- // Skip this query silently
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,file=%s,line=%s", $sql, $F, $L));
- } elseif (!$noIndex) {
- // And column name as well
- $columnName = str_replace("`", "", $tableArray[4]);
-
- // Is this "UNIQUE" or so? FULLTEXT has been handled the elseif() block above
- if (in_array(strtoupper($columnName), array("INDEX", "UNIQUE", "KEY", "FULLTEXT"))) {
- // Init loop
- $begin = 1; $columnName = ",";
- while (strpos($columnName, ",") !== false) {
- // Use last
- $columnName = str_replace("`", "", $tableArray[count($tableArray) - $begin]);
- //* DEBUG: */ print __LINE__.":".$columnName."----------------".$begin."<br />\n";
-
- // Remove brackes
- $columnName = str_replace("(", "", str_replace(")", "", $columnName));
- //* DEBUG: */ print __LINE__.":".$columnName."----------------".$begin."<br />\n";
-
- // Continue
- $begin++;
- } // END while
- } // END - if