+// Wrapper function to make code more readable
+function SQL_HASZEROAFFECTED () {
+ // Just pass it through
+ return (SQL_AFFECTEDROWS() === 0);
+}
+
+// Private function to prepare the SQL query string
+function SQL_PREPARE_SQL_STRING ($sqlString, $enableCodes = true) {
+ // Is it already cached?
+ if (!isset($GLOBALS['sql_strings'][$sqlString])) {
+ // Compile config+expression code
+ $sqlString2 = FILTER_COMPILE_EXPRESSION_CODE(FILTER_COMPILE_CONFIG($sqlString));
+
+ // Do final compilation
+ $GLOBALS['sql_strings'][$sqlString] = doFinalCompilation($sqlString2, false, $enableCodes);
+ //die($sqlString.'<br />'.$sqlString2.'<br />'.$GLOBALS['sql_strings'][$sqlString]);
+ } // END - if
+
+ // Return it
+ return $GLOBALS['sql_strings'][$sqlString];
+}
+
+// Check if there is a SQL table created
+function isSqlTableCreated ($tableName) {
+ // Do we have cache?
+ 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($tableName), __FILE__, __LINE__);
+
+ // Is there an entry?
+ $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__][$tableName];
+}
+
+// Is a table column there?
+function isSqlTableColumnFound ($tableName, $columnName) {
+ // Do we have cache?
+ if (!isset($GLOBALS[__FUNCTION__][$tableName][$columnName])) {
+ // And column name as well
+ $columnName = str_replace('`', '', $columnName);
+
+ // Get column information
+ $result = SQL_QUERY_ESC("SHOW COLUMNS FROM `%s` LIKE '%s'",
+ array($tableName, $columnName), __FUNCTION__, __LINE__);
+
+ // Determine it
+ $GLOBALS[__FUNCTION__][$tableName][$columnName] = (!SQL_HASZERONUMS($result));
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ',hasZeroNums=' . intval(SQL_HASZERONUMS($result)) . ',numRows=' . intval($GLOBALS[__FUNCTION__][$tableName][$columnName]));
+
+ // Free result
+ SQL_FREERESULT($result);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$tableName][$columnName];
+}
+
+// Checks depending on the mode if the table is there
+function isSqlTableIndexAdded ($tableName, $mode, $keyName) {
+ // Do we have cache?
+ if (!isset($GLOBALS[__FUNCTION__][$tableName][$mode])) {
+ // Show indexes
+ $result = SQL_QUERY_ESC("SHOW INDEX FROM `%s`", array($tableName), __FUNCTION__, __LINE__);
+
+ // Non-skipping is default for ADD
+ $GLOBALS[__FUNCTION__][$tableName][$mode] = false;
+
+ // But should we DROP?
+ if ($mode == 'DROP') {
+ // Then skip if nothing found
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Going to drop key ' . $keyName);
+ $GLOBALS[__FUNCTION__][$tableName][$mode] = true;
+ } // END - if
+
+ // Walk through all
+ while ($content = SQL_FETCHARRAY($result)) {
+ // Is it found?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName='.$keyName.',content=<pre>' . print_r($content, true) . '</pre>');
+ if (($content['Key_name'] == $keyName) && ($mode == 'ADD')) {
+ // Skip this query!
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("ADD: Skiped: %s", $sql));
+ $GLOBALS[__FUNCTION__][$tableName][$mode] = true;
+ break;
+ } elseif (($content['Key_name'] == $keyName) && ($mode == 'DROP')) {
+ // Don't skip this!
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("DROP: Not skiped: %s", $sql));
+ $GLOBALS[__FUNCTION__][$tableName][$mode] = false;
+ break;
+ }
+ } // END - while
+
+ // Free result
+ SQL_FREERESULT($result);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$tableName][$mode];
+}
+