This commit is contained in:
Mario Vavti 2016-05-09 11:58:10 +02:00
commit a3e94591bc
4 changed files with 26 additions and 13 deletions

View File

@ -446,7 +446,7 @@ class Network extends \Zotlabs\Web\Controller {
$ordering = "commented"; $ordering = "commented";
if($load) { if($load) {
// Fetch a page full of parent items for this page // Fetch a page full of parent items for this page
$r = q("SELECT distinct item.id AS item_id, $ordering FROM item $r = q("SELECT distinct item.id AS item_id, $ordering FROM item
@ -469,7 +469,7 @@ class Network extends \Zotlabs\Web\Controller {
); );
$_SESSION['loadtime'] = datetime_convert(); $_SESSION['loadtime'] = datetime_convert();
} }
// Then fetch all the children of the parents that are on this page // Then fetch all the children of the parents that are on this page
$parents_str = ''; $parents_str = '';
$update_unseen = ''; $update_unseen = '';

View File

@ -59,8 +59,9 @@ abstract class dba_driver {
const NULL_DATE = '0000-00-00 00:00:00'; const NULL_DATE = '0000-00-00 00:00:00';
const UTC_NOW = 'UTC_TIMESTAMP()'; const UTC_NOW = 'UTC_TIMESTAMP()';
protected $debug = 0;
protected $db; protected $db;
public $debug = 0;
public $connected = false; public $connected = false;
public $error = false; public $error = false;
@ -302,10 +303,10 @@ function q($sql) {
$stmt = vsprintf($sql, $args); $stmt = vsprintf($sql, $args);
if($stmt === false) { if($stmt === false) {
if(version_compare(PHP_VERSION, '5.4.0') >= 0) if(version_compare(PHP_VERSION, '5.4.0') >= 0)
logger('dba: vsprintf error: ' . db_logger('dba: vsprintf error: ' .
print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1), true),LOGGER_NORMAL,LOG_CRIT); print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1), true),LOGGER_NORMAL,LOG_CRIT);
else else
logger('dba: vsprintf error: ' . print_r(debug_backtrace(), true),LOGGER_NORMAL,LOG_CRIT); db_logger('dba: vsprintf error: ' . print_r(debug_backtrace(), true),LOGGER_NORMAL,LOG_CRIT);
} }
return $db->q($stmt); return $db->q($stmt);
} }
@ -314,7 +315,7 @@ function q($sql) {
* This will happen occasionally trying to store the * This will happen occasionally trying to store the
* session data after abnormal program termination * session data after abnormal program termination
*/ */
logger('dba: no database: ' . print_r($args,true),LOGGER_NORMAL,LOG_CRIT); db_logger('dba: no database: ' . print_r($args,true),LOGGER_NORMAL,LOG_CRIT);
return false; return false;
} }
@ -385,7 +386,19 @@ function db_getfunc($f) {
if(isset($lookup[$f]) && isset($lookup[$f][ACTIVE_DBTYPE])) if(isset($lookup[$f]) && isset($lookup[$f][ACTIVE_DBTYPE]))
return $lookup[$f][ACTIVE_DBTYPE]; return $lookup[$f][ACTIVE_DBTYPE];
logger('Unable to abstract DB function "'. $f . '" for dbtype ' . ACTIVE_DBTYPE, LOGGER_DEBUG, LOG_ERR); db_logger('Unable to abstract DB function "'. $f . '" for dbtype ' . ACTIVE_DBTYPE, LOGGER_DEBUG, LOG_ERR);
return $f; return $f;
} }
// The logger function may make DB calls internally to query the system logging parameters.
// This can cause a recursion if database debugging is enabled.
// So this function preserves the current database debugging state and then turns it off while
// doing the logger() call
function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) {
global $db;
$saved = $db->debug;
$db->debug = false;
logger($s,$level,$syslog);
$db->debug = $saved;
}

View File

@ -38,7 +38,7 @@ class dba_mysqli extends dba_driver {
if($this->error) { if($this->error) {
logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR); db_logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR);
if(file_exists('dbfail.out')) { if(file_exists('dbfail.out')) {
file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND); file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND);
} }
@ -46,13 +46,13 @@ class dba_mysqli extends dba_driver {
if(($result === true) || ($result === false)) { if(($result === true) || ($result === false)) {
if($this->debug) { if($this->debug) {
logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returns ' . (($result) ? 'true' : 'false'), LOGGER_NORMAL,(($result) ? LOG_INFO : LOG_ERR)); db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returns ' . (($result) ? 'true' : 'false'), LOGGER_NORMAL,(($result) ? LOG_INFO : LOG_ERR));
} }
return $result; return $result;
} }
if($this->debug) { if($this->debug) {
logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . $result->num_rows . ' results.', LOGGER_NORMAL, LOG_INFO); db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . $result->num_rows . ' results.', LOGGER_NORMAL, LOG_INFO);
} }
$r = array(); $r = array();
@ -61,7 +61,7 @@ class dba_mysqli extends dba_driver {
$r[] = $x; $r[] = $x;
$result->free_result(); $result->free_result();
if($this->debug) { if($this->debug) {
logger('dba_mysqli: ' . printable(print_r($r,true)), LOGGER_NORMAL, LOG_INFO); db_logger('dba_mysqli: ' . printable(print_r($r,true)), LOGGER_NORMAL, LOG_INFO);
} }
} }
return $r; return $r;

View File

@ -50,7 +50,7 @@ class dba_postgres extends dba_driver {
$this->error = pg_last_error($this->db); $this->error = pg_last_error($this->db);
if($result === false || $this->error) { if($result === false || $this->error) {
//logger('dba_postgres: ' . printable($sql) . ' returned false.' . "\n" . $this->error); //db_logger('dba_postgres: ' . printable($sql) . ' returned false.' . "\n" . $this->error);
if(file_exists('dbfail.out')) if(file_exists('dbfail.out'))
file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND);
} }
@ -67,7 +67,7 @@ class dba_postgres extends dba_driver {
$r[] = $x; $r[] = $x;
pg_free_result($result); pg_free_result($result);
if($this->debug) if($this->debug)
logger('dba_postgres: ' . printable(print_r($r,true))); db_logger('dba_postgres: ' . printable(print_r($r,true)));
} }
return $r; return $r;
} }