X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fsql-functions.php;h=b56d0dfca89d1f4da2cf204c334ea4e8439e489a;hb=refs%2Fheads%2Fserver-0.2.1-FINAL%2Fwernis4mails-de;hp=b0fa5065174aec57328561c610832519390b39b1;hpb=b52976057a73d26d63b6c98a4fc9efb3e07f40e7;p=mailer.git diff --git a/inc/sql-functions.php b/inc/sql-functions.php index b0fa506517..b56d0dfca8 100644 --- a/inc/sql-functions.php +++ b/inc/sql-functions.php @@ -10,13 +10,8 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : SQL-Funktionen fuer Queries * * -------------------------------------------------------------------- * - * $Revision:: $ * - * $Date:: $ * - * $Tag:: 0.2.1-FINAL $ * - * $Author:: $ * - * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2013 by Mailer Developer Team * + * Copyright (c) 2009 - 2016 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -304,7 +299,9 @@ function sqlQueryEscaped ($sqlString, $data, $file, $line, $run = TRUE, $strip = // Escape all data foreach ($data as $key => $value) { + //* DEBUG: */ logDebugMessage(basename($file) . '/' . __FUNCTION__, $line . '/' . __LINE__, 'key=' . $key . ',value=' . $value . ',run=' . intval($run) . ',strip=' . intval($strip) . ',secure=' . intval($secure)); $dataSecured[$key] = sqlEscapeString($value, $secure, $strip); + //* DEBUG: */ logDebugMessage(basename($file) . '/' . __FUNCTION__, $line . '/' . __LINE__, 'dataSecured[key]=' . $dataSecured[$key]); } // END - foreach // Generate query @@ -510,7 +507,7 @@ function setSqlLink ($file, $line, $link) { $GLOBALS['__sql_link'] = $link; // Re-init cache - $GLOBALS['__is_sql_link_up'] = isValidSqlLink($link); + $GLOBALS['__is_sql_link_up'] = ((function_exists('isValidSqlLink')) && (isValidSqlLink($link))); } // Checks if the link is up @@ -527,7 +524,7 @@ function isSqlLinkUp () { } // Wrapper function to make code more readable -function ifSqlHasZeroNums ($result) { +function ifSqlHasZeroNumRows ($result) { // Just pass it through return (sqlNumRows($result) === 0); } @@ -546,20 +543,23 @@ function sqlPrepareQueryString ($sqlString, $enableCodes = TRUE) { // Is it already cached? if (!isset($GLOBALS['sql_strings']['' . $sqlString . ''])) { // Preserve escaping and compile URI codes+config+expression code - $sqlString2 = FILTER_COMPILE_EXPRESSION_CODE(FILTER_COMPILE_CONFIG($sqlString)); + $sqlString2 = str_replace(chr(92), '{BACKLASH}', $sqlString); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlString2=' . $sqlString2); + $sqlString2 = FILTER_COMPILE_EXPRESSION_CODE(FILTER_COMPILE_CONFIG($sqlString2)); // Debug message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlString2=' . $sqlString2); - // Do final compilation and revert {ESCAPE} + // Do final compilation and revert {BACKSLASH} $GLOBALS['sql_strings']['' . $sqlString . ''] = doFinalCompilation($sqlString2, FALSE, $enableCodes); + $GLOBALS['sql_strings']['' . $sqlString . ''] = str_replace('{BACKLASH}', chr(92), $GLOBALS['sql_strings']['' . $sqlString . '']); } else { // Log message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlString=' . $sqlString . ' - CACHE!'); } // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlString=' . $sqlString . ',enableCodes=' . intval($enableCodes) . ',sql_strings=' . $GLOBALS['sql_strings']['' . $sqlString . ''] . ' - EXIT!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlString=' . $sqlString . ',enableCodes=' . intval($enableCodes) . ',returned sql_string=' . $GLOBALS['sql_strings']['' . $sqlString . ''] . ' - EXIT!'); // Return it return $GLOBALS['sql_strings']['' . $sqlString . '']; @@ -585,7 +585,7 @@ function ifSqlTableExists ($tableName) { array($tableName), __FUNCTION__, __LINE__); // Is a link there? - if (!is_resource($result)) { + if (!isValidSqlResult($result)) { // Is installation phase? if (isInstaller()) { // Then silently abort here @@ -630,7 +630,7 @@ function ifSqlTableColumnExists ($tableName, $columnName, $forceFound = FALSE) { ), __FUNCTION__, __LINE__); // Is a link there? - if (!is_resource($result)) { + if (!isValidSqlResult($result)) { // Is installation phase? if (isInstaller()) { // Then silently abort here @@ -643,7 +643,7 @@ function ifSqlTableColumnExists ($tableName, $columnName, $forceFound = FALSE) { } // END - if // Determine it - $doesExist = (!ifSqlHasZeroNums($result)); + $doesExist = (!ifSqlHasZeroNumRows($result)); // Free result sqlFreeResult($result); @@ -672,7 +672,7 @@ function ifSqlTableIndexExist ($tableName, $keyName, $forceFound = FALSE) { $result = sqlQueryEscaped("SHOW INDEX FROM `%s`", array($tableName), __FUNCTION__, __LINE__); // Is a link there? - if (!is_resource($result)) { + if (!isValidSqlResult($result)) { // Is installation phase? if (isInstaller()) { // Then silently abort here @@ -725,7 +725,7 @@ function getArrayFromSupportedSqlEngines ($requestedEngine = 'ALL') { $result = sqlQuery('SHOW ENGINES', __FUNCTION__, __LINE__); // Are there entries? (Bad if not) - if (!ifSqlHasZeroNums($result)) { + if (!ifSqlHasZeroNumRows($result)) { // Load all and check for active entries while ($content = sqlFetchArray($result)) { // Debug message @@ -777,5 +777,41 @@ WHERE ); } +// Log SQL errors to debug.log in installation phase or call reportBug() +function logSqlError ($file, $line, $message) { + // Remember plain error in last_sql_error + setSqlError($file, $line, $message); + + // Is login set? + if (!empty($GLOBALS['mysql']['login'])) { + // Secure login name in message + $message = str_replace($GLOBALS['mysql']['login'], '***', $message); + } // END - if + + // Is database password set? + if (!empty($GLOBALS['mysql']['password'])) { + // Secure password in message + $message = str_replace($GLOBALS['mysql']['password'], '***', $message); + } // END - if + + // Is database name set? + if (!empty($GLOBALS['mysql']['dbase'])) { + // Secure database name in message + $message = str_replace($GLOBALS['mysql']['dbase'], '***', $message); + } // END - if + + // Is there installation phase? + if (isInstaller()) { + /* + * In installation phase, we don't want SQL errors abort e.g. connection + * tests, so just log it away. + */ + logDebugMessage($file, $line, $message); + } else { + // Regular mode, then call reportBug() + reportBug($file, $line, $message); + } +} + // [EOF] ?>