+// Creates a MySQL TIMESTAMP compatible string from given Uni* timestamp
+function SQL_EPOCHE_TO_TIMESTAMP ($timestamp) {
+ return generateDateTime($timestamp, 7);
+}
+
+// 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];
+}
+