return $SQL;
}
+// Function to unset __is_sql_link_up
+function unsetSqlLinkUp ($F, $L) {
+ // Unset it
+ //* DEBUG: */ logDebugMessage($F, $L, __FUNCTION__ . ': Called!');
+ SQL_SET_LINK($F, $L, NULL);
+}
+
// Initializes the SQL link by bringing it up if set
function initSqlLink () {
+ // "Unset" the link
+ unsetSqlLinkUp(__FUNCTION__, __LINE__);
+
// Do this only if link is down
assert(!SQL_IS_LINK_UP());
// Is the configuration data set?
if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['dbase']))) {
// Remove cache
- unset($GLOBALS['is_sql_link_up']);
+ unsetSqlLinkUp(__FUNCTION__, __LINE__);
// Connect to DB
- SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
+ SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FUNCTION__, __LINE__);
// Is the link valid?
if (SQL_IS_LINK_UP()) {
enableExitOnError();
// Is it a valid resource?
- if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === TRUE) {
+ if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FUNCTION__, __LINE__) === TRUE) {
// Set database name (required for ext-optimize and ifSqlTableExists())
setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']);
loadIncludeOnce('inc/load_cache.php');
} else {
// Wrong database?
- reportBug(__FILE__, __LINE__, 'Wrong database selected.');
+ reportBug(__FUNCTION__, __LINE__, 'Wrong database selected.');
}
} else {
// No link to database!
- reportBug(__FILE__, __LINE__, 'Database link is not yet up.');
+ reportBug(__FUNCTION__, __LINE__, 'Database link is not yet up.');
}
} else {
// Maybe you forgot to enter your database login?
- reportBug(__FILE__, __LINE__, 'Database login is missing.');
+ reportBug(__FUNCTION__, __LINE__, 'Database login is missing.');
}
}
// Is the file readable?
if (!isFileReadable($FQFN)) {
// Not found, which is bad
- reportBug(__FILE__, __LINE__, sprintf("SQL dump %s/%s.sql is not readable.", $path, $dumpName));
+ reportBug(__FUNCTION__, __LINE__, sprintf("SQL dump %s/%s.sql is not readable.", $path, $dumpName));
} // END - if
// Then read it
// Link is there?
if ((!SQL_IS_LINK_UP()) || (!is_array($data))) {
// Link is down or data is not an array
- /* DEBUG: */ logDebugMessage($F, $L, 'SQL_IS_LINK_UP()=' . intval(SQL_IS_LINK_UP()) . ',data[]=' . gettype($data) . ',sqlString=' . $sqlString . ': ABORTING!');
+ //* DEBUG: */ logDebugMessage($F, $L, 'SQL_IS_LINK_UP()=' . intval(SQL_IS_LINK_UP()) . ',data[]=' . gettype($data) . ',sqlString=' . $sqlString . ': ABORTING!');
return FALSE;
} // END - if
$link = NULL;
// Is it in the globals?
- if (isset($GLOBALS['sql_link'])) {
+ if (isset($GLOBALS['__sql_link'])) {
// Then take it
- $link = $GLOBALS['sql_link'];
+ $link = $GLOBALS['__sql_link'];
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'link[]=' . gettype($link) . ' - FROM GLOBALS!');
} // END - if
// Return it
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'link[]=' . gettype($link) . ' - EXIT!');
return $link;
}
// Setter for link
-function SQL_SET_LINK ($link) {
+function SQL_SET_LINK ($F, $L, $link) {
+ //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'link[]=' . gettype($link) . ' - ENTERED!');
// Is this a resource or null?
if ((ifFatalErrorsDetected()) && (isInstallationPhase())) {
// This may happen in installation phase
+ //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'Some fatal errors detected in installation phase.');
return;
} elseif ((!is_resource($link)) && (!is_null($link))) {
// This should never happen!
- reportBug(__FUNCTION__, __LINE__, sprintf("Type of link is not resource or null, type=%s", gettype($link)));
+ reportBug($F . ':' . __FUNCTION__, $L . ':' . __LINE__, sprintf("Type of link is not resource or null, type=%s", gettype($link)));
} // END - if
// Set it
- $GLOBALS['sql_link'] = $link;
+ $GLOBALS['__sql_link'] = $link;
// Re-init cache
- $GLOBALS['is_sql_link_up'] = is_resource($link);
+ $GLOBALS['__is_sql_link_up'] = is_resource($link);
+ //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, '__is_sql_link_up=' . intval($GLOBALS['__is_sql_link_up']) . ' - EXIT!');
}
// Checks if the link is up
function SQL_IS_LINK_UP () {
// Is there cached this?
- if (!isset($GLOBALS['is_sql_link_up'])) {
- // Determine it
- $GLOBALS['is_sql_link_up'] = is_resource(SQL_GET_LINK());
+ if (!isset($GLOBALS['__is_sql_link_up'])) {
+ // Something bad went wrong
+ reportBug(__FUNCTION__, __LINE__, 'Called before SQL_SET_LINK() was called!');
} // END - if
// Return the result
- return $GLOBALS['is_sql_link_up'];
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '__is_sql_link_up=' . intval($GLOBALS['__is_sql_link_up']) . ' - EXIT!');
+ return $GLOBALS['__is_sql_link_up'];
}
// Wrapper function to make code more readable
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__);
+ array($tableName), __FUNCTION__, __LINE__);
// Is a link there?
if (!is_resource($result)) {