X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fdb%2Flib-mysql3.php;h=02e1722fe25d3d1b08db80b59f99d2429e2c38b6;hp=1ef2a798899b380b8fb3b5eb421993a345495dcc;hb=4b32c7be676d4a191c869a5745f2890240852fb0;hpb=07e126c776ca39d4e8d6a751af02b08221e664e2;ds=sidebyside diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 1ef2a79889..02e1722fe2 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -85,10 +85,9 @@ function SQL_QUERY ($sqlString, $F, $L) { // Run SQL command //* DEBUG: */ print('F=' . basename($F) . ',L=' . $L . 'sql=' . htmlentities($sqlString) . '
'); $result = mysql_query($sqlString, SQL_GET_LINK()) - or addFatalMessage(__FUNCTION__, __LINE__, $F . ' (' . $L . '):' . mysql_error() . '
-Query string:
-' . $sqlString); - /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sqlString . ',numRows=' . SQL_NUMROWS($result) . ',affected=' . SQL_AFFECTEDROWS()); + or debug_report_bug('[' . __FUNCTION__ . ':' . __LINE__ . '] ' . $F . ' (' . $L . '):' . mysql_error() . "\n". +'Query string:' . $sqlString); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sqlString . ',numRows=' . SQL_NUMROWS($result) . ',affected=' . SQL_AFFECTEDROWS()); // Calculate query time $queryTime = microtime(true) - $querytimeBefore; @@ -135,6 +134,9 @@ Query string:
// SQL num rows function SQL_NUMROWS ($result) { + // Valid link resource? + if (!SQL_IS_LINK_UP()) return false; + // Link is not up, no rows by default $lines = false; @@ -145,9 +147,9 @@ function SQL_NUMROWS ($result) { // Is the result empty? Then we have an error! if (empty($lines)) $lines = '0'; - } elseif (SQL_IS_LINK_UP()) { - // No resource given, no lines found! - $lines = '0'; + } else { + // No resource given, please fix this + trigger_error('No resource given! result[]=' . gettype($result)); } // Return lines @@ -403,14 +405,14 @@ function SQL_ALTER_TABLE ($sql, $F, $L) { // 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))) { + if (((SQL_HASZERONUMS($result)) && (strpos($sql, 'ADD') !== false)) || ((SQL_NUMROWS($result) == 1) && (strpos($sql, 'DROP') !== false))) { // Do the query //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Executing: ' . $sql); $result = SQL_QUERY($sql, $F, $L, false); // Skip further attempt(s) break; - } elseif ((((SQL_NUMROWS($result) == 1) && (strpos($sql, 'ADD') !== false)) || ((SQL_NUMROWS($result) == '0') && (strpos($sql, 'DROP') !== false))) && ($columnName != 'KEY')) { + } elseif ((((SQL_NUMROWS($result) == 1) && (strpos($sql, 'ADD') !== false)) || ((SQL_HASZERONUMS($result)) && (strpos($sql, 'DROP') !== false))) && ($columnName != 'KEY')) { // Abort here because it is alreay there //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: ' . $sql); break; @@ -545,5 +547,11 @@ function SQL_IS_LINK_UP () { return $linkUp; } +// Wrapper function to make code more readable +function SQL_HASZERONUMS ($result) { + // Just pass it through + return (SQL_NUMROWS($result) === 0); +} + // [EOF] ?>