+ $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, '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)) {
+ // 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 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: */ outputHtml(__LINE__.':'.$sql."<br />");
+ $result = SQL_QUERY($sql, $F, $L, false);
+ } // END - if
+ } 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
+ $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: */ outputHtml(__LINE__.':'.$columnName."----------------".$begin."<br />");
+
+ // Remove brackes
+ $columnName = str_replace('(', '', str_replace(')', '', $columnName));
+ //* DEBUG: */ outputHtml(__LINE__.':'.$columnName."----------------".$begin."<br />");
+
+ // Continue
+ $begin++;
+ } // END while
+ } // END - if
+
+ // Show indexes
+ $result = SQL_QUERY_ESC("SHOW INDEX FROM `%s`",
+ array($tableName), __FILE__, __LINE__);
+
+ // Walk through all
+ $skip = false;
+ while ($content = SQL_FETCHARRAY($result)) {
+ // Is it found?
+ //* DEBUG: */ outputHtml("<pre>".print_r($content, true)."</pre>");
+ if (($content['Column_name'] == $columnName) || ($content['Key_name'] == $columnName)) {
+ // Skip this query!
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skiped: %s", $sql));
+ $skip = true;
+ break;
+ } // END - if
+ } // END - while
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Shall we run it?
+ if ($skip === false) {
+ // Send it to the SQL_QUERY() function
+ //* DEBUG: */ outputHtml(__LINE__.':'.$sql."<br />");
+ $result = SQL_QUERY($sql, $F, $L, false);
+ } // END - if
+ } else {
+ // Other ALTER TABLE query
+ //* DEBUG: */ outputHtml(__LINE__.':'.$sql."<br />");
+ $result = SQL_QUERY($sql, $F, $L, false);
+ }
+
+ // Return result
+ return $result;
+}
+
+// Getter for SQL link
+function SQL_GET_LINK () {
+ // Init link
+ $link = null;
+
+ // Is it in the globals?
+ if (isset($GLOBALS['sql_link'])) {
+ // Then take it
+ $link = $GLOBALS['sql_link'];
+ } // END - if
+
+ // Return it
+ return $link;
+}
+
+// Setter for link
+function SQL_SET_LINK ($link) {
+ // Is this a resource or null?
+ if ((!is_resource($link)) && (!is_null($link))) {
+ // This should never happen!
+ debug_report_bug(sprintf("link is not resource or null. Type: %s", gettype($link)));
+ } // END - if
+
+ // Set it
+ $GLOBALS['sql_link'] = $link;
+}
+
+// Checks if the link is up
+function SQL_IS_LINK_UP () {
+ // Default is not up
+ $linkUp = false;
+
+ // Do we have cached this?
+ if (isset($GLOBALS['sql_link_res'])) {
+ // Then use this
+ $linkUp = $GLOBALS['sql_link_res'];
+ } else {
+ // Get it
+ $linkUp = is_resource(SQL_GET_LINK());
+
+ // And cache it
+ $GLOBALS['sql_link_res'] = $linkUp;
+ }