- // Return it
- return $GLOBALS['sql_escapes'][''.$str.''];
-}
-
-// SELECT query string from table, columns and so on... ;-)
-function SQL_RESULT_FROM_ARRAY ($table, $columns, $idRow, $id, $F, $L) {
- // Is columns an array?
- if (!is_array($columns)) {
- // No array
- debug_report_bug(sprintf("columns is not an array. %s != array, file=%s, line=%s",
- gettype($columns),
- basename($F),
- $L
- ));
-
- // Abort here with 'false'
- return false;
- } // END - if
-
- // Prepare the SQL statement
- $sql = "SELECT `".implode("`,`", $columns)."` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s' LIMIT 1";
-
- // Return the result
- return SQL_QUERY_ESC($sql,
- array(
- $table,
- $idRow,
- bigintval($id),
- ), $F, $L
- );
-}
-
-// ALTER TABLE wrapper function
-function SQL_ALTER_TABLE ($sql, $F, $L) {
- // Abort if link is down
- if (!SQL_IS_LINK_UP()) return false;
-
- // This is the default result...
- $result = false;
-
- // Determine index/fulltext/unique word
- $noIndex = (
- (
- strpos($sql, 'INDEX') === false
- ) && (
- strpos($sql, 'KEY') === false
- ) && (
- strpos($sql, 'FULLTEXT') === false
- ) && (
- strpos($sql, 'UNIQUE') === false
- )
- );
-
- // Extract table name
- $tableArray = explode(' ', $sql);
- $tableName = str_replace('`', '', $tableArray[2]);
-
- // Shall we add/drop?
- if (((strpos($sql, 'ADD') !== false) || (strpos($sql, 'DROP') !== false)) && ($noIndex === true)) {
- // Try two columns, one should fix
- foreach (array(4,5) as $idx) {
- // And column name as well
- $columnName = str_replace('`', '', $tableArray[$idx]);
-
- // 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 4 32 23 4 4 3 3 4 4 321
- if (((SQL_NUMROWS($result) == '0') && (strpos($sql, 'ADD') !== false)) || ((SQL_NUMROWS($result) == 1) && (strpos($sql, 'DROP') !== false))) {
- // Do the query
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Executing: ' . $sql);
- $result = SQL_QUERY($sql, $F, $L, false);
-
- // Skip further attempt(s)
- break;
- } elseif ((((SQL_NUMROWS($result) == 1) && (strpos($sql, 'ADD') !== false)) || ((SQL_NUMROWS($result) == '0') && (strpos($sql, 'DROP') !== false))) && ($columnName != 'KEY')) {
- // Abort here because it is alreay there
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: ' . $sql);
- break;
- } elseif ($columnName != 'KEY') {
- // Something didn't fit
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql);
- }
- } // END - foreach
- } elseif ((getConfig('_TABLE_TYPE') == 'InnoDB') && (strpos($sql, 'FULLTEXT') !== false)) {
- // Skip this query silently
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,file=%s,line=%s", $sql, $F, $L));
- } elseif ($noIndex === false) {
- // And column name as well
- //* DEBUG: */ print __LINE__.':tableArray=<pre>' . print_r($tableArray, true) . '</pre>';
- $keyName = str_replace('`', '', $tableArray[5]);
-
- // Is this "UNIQUE" or so? FULLTEXT has been handled the elseif() block above
- if (in_array(strtoupper($keyName), array('INDEX', 'UNIQUE', 'KEY', 'FULLTEXT'))) {
- // Init loop
- $begin = 1; $keyName = ',';
- while (strpos($keyName, ',') !== false) {
- // Use last
- $keyName = str_replace('`', '', $tableArray[count($tableArray) - $begin]);
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $keyName . '----------------' . $begin);
-
- // Remove brackes
- $keyName = str_replace('(', '', str_replace(')', '', $keyName));
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $keyName . '----------------' . $begin);
-
- // Continue
- $begin++;
- } // END while
- } // END - if
-
- // Show indexes
- $result = SQL_QUERY_ESC("SHOW INDEX FROM `%s`", array($tableName), __FILE__, __LINE__);