fixes WRT to db logging. I believe fixes issue #504

This commit is contained in:
Isaac Connor 2014-09-26 14:43:58 -04:00
parent af536624ce
commit bec58a6011
5 changed files with 24 additions and 25 deletions

View File

@ -14,7 +14,7 @@ if ( canView( 'Events' ) ) {
} elseif ( empty($_REQUEST['scale']) ) { } elseif ( empty($_REQUEST['scale']) ) {
ajaxError( "Video Generation Failure, no scale given" ); ajaxError( "Video Generation Failure, no scale given" );
} else { } else {
$sql = 'select E.*,M.Name as MonitorName,M.DefaultRate,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = ?'.monitorLimitSql(); $sql = 'SELECT E.*,M.Name AS MonitorName,M.DefaultRate,M.DefaultScale FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE E.Id = ?'.monitorLimitSql();
if ( !($event = dbFetchOne( $sql, NULL, array( $_REQUEST['id'] ) )) ) if ( !($event = dbFetchOne( $sql, NULL, array( $_REQUEST['id'] ) )) )
ajaxError( "Video Generation Failure, can't load event" ); ajaxError( "Video Generation Failure, can't load event" );
else else

View File

@ -39,9 +39,8 @@ switch ( $_REQUEST['task'] )
$filterFields = array( 'Component', 'Pid', 'Level', 'File', 'Line' ); $filterFields = array( 'Component', 'Pid', 'Level', 'File', 'Line' );
//$filterSql = $filter?' where $total = dbFetchOne( "SELECT count(*) AS Total FROM Logs", 'Total' );
$total = dbFetchOne( "select count(*) as Total from Logs", 'Total' ); $sql = 'SELECT * FROM Logs';
$sql = "select * from Logs";
$where = array(); $where = array();
$values = array(); $values = array();
if ( $minTime ) { if ( $minTime ) {
@ -61,11 +60,10 @@ switch ( $_REQUEST['task'] )
} }
} }
if ( count($where) ) if ( count($where) )
$sql.= " where ".join( " and ", $where ); $sql.= ' WHERE '.join( ' AND ', $where );
$sql .= " order by ".$sortField." ".$sortOrder." limit ".$limit; $sql .= " order by ".$sortField." ".$sortOrder." limit ".$limit;
$logs = array(); $logs = array();
foreach ( dbFetchAll( $sql, NULL, $values ) as $log ) foreach ( dbFetchAll( $sql, NULL, $values ) as $log ) {
{
$log['DateTime'] = preg_replace( '/^\d+/', strftime( "%Y-%m-%d %H:%M:%S", intval($log['TimeKey']) ), $log['TimeKey'] ); $log['DateTime'] = preg_replace( '/^\d+/', strftime( "%Y-%m-%d %H:%M:%S", intval($log['TimeKey']) ), $log['TimeKey'] );
$logs[] = $log; $logs[] = $log;
} }
@ -83,15 +81,15 @@ switch ( $_REQUEST['task'] )
} }
foreach( $filterFields as $field ) foreach( $filterFields as $field )
{ {
$sql = "select distinct $field from Logs where not isnull($field)"; $sql = "SELECT DISTINCT $field FROM Logs WHERE NOT isnull($field)";
$fieldWhere = array_diff_key( $where, array( $field=>true ) ); $fieldWhere = array_diff_key( $where, array( $field=>true ) );
$fieldValues = array_diff_key( $values, array( $field=>true ) ); $fieldValues = array_diff_key( $values, array( $field=>true ) );
if ( count($fieldWhere) ) if ( count($fieldWhere) )
$sql.= " and ".join( " and ", $fieldWhere ); $sql.= " AND ".join( ' AND ', $fieldWhere );
$sql.= " order by $field asc"; $sql.= " ORDER BY $field ASC";
if ( $field == 'Level' ) if ( $field == 'Level' )
{ {
foreach( dbFetchAll( $sql, $field, $fieldValues ) as $value ) foreach( dbFetchAll( $sql, $field, array_values($fieldValues) ) as $value )
if ( $value <= Logger::INFO ) if ( $value <= Logger::INFO )
$options[$field][$value] = Logger::$codes[$value]; $options[$field][$value] = Logger::$codes[$value];
else else
@ -99,15 +97,15 @@ switch ( $_REQUEST['task'] )
} }
else else
{ {
foreach( dbFetchAll( $sql, $field ) as $value ) foreach( dbFetchAll( $sql, $field, array_values( $fieldValues ) ) as $value )
if ( $value != '' ) if ( $value != '' )
$options[$field][] = $value; $options[$field][] = $value;
} }
} }
if ( count($filter) ) if ( count($filter) )
{ {
$sql = "select count(*) as Available from Logs where ".join( " and ", $where ); $sql = "SELECT count(*) AS Available FROM Logs WHERE ".join( ' AND ', $where );
$available = dbFetchOne( $sql, 'Available', $values ); $available = dbFetchOne( $sql, 'Available', array_values($values) );
} }
ajaxResponse( array( ajaxResponse( array(
'updated' => preg_match( '/%/', DATE_FMT_CONSOLE_LONG )?strftime( DATE_FMT_CONSOLE_LONG ):date( DATE_FMT_CONSOLE_LONG ), 'updated' => preg_match( '/%/', DATE_FMT_CONSOLE_LONG )?strftime( DATE_FMT_CONSOLE_LONG ):date( DATE_FMT_CONSOLE_LONG ),

View File

@ -248,14 +248,13 @@ function collectData()
$index = 0; $index = 0;
$where = array(); $where = array();
$values = array(); $values = array();
foreach( $entitySpec['selector'] as $selector ) foreach( $entitySpec['selector'] as $selector ) {
{
if ( is_array( $selector ) ) { if ( is_array( $selector ) ) {
$where[] = $selector['selector'].' = ?'; $where[] = $selector['selector'].' = ?';
$values[] = $id[$index]; $values[] = validInt($id[$index]);
} else { } else {
$where[] = $selector.' = ?'; $where[] = $selector.' = ?';
$values[] = $id[$index]; $values[] = validInt($id[$index]);
} }
$index++; $index++;
} }
@ -268,9 +267,12 @@ function collectData()
if ( !empty($entitySpec['limit']) ) if ( !empty($entitySpec['limit']) )
$limit = $entitySpec['limit']; $limit = $entitySpec['limit'];
elseif ( !empty($_REQUEST['count']) ) elseif ( !empty($_REQUEST['count']) )
$limit = $_REQUEST['count']; $limit = validInt($_REQUEST['count']);
if ( !empty( $limit ) ) $limit_offset="";
$sql .= " limit ".$limit; if ( !empty($_REQUEST['offset']) )
$limit_offset = validInt($_REQUEST['offset']) . ", ";
if ( !empty( $limit ) )
$sql .= " limit ".$limit_offset.$limit;
if ( isset($limit) && $limit == 1 ) { if ( isset($limit) && $limit == 1 ) {
if ( $sqlData = dbFetchOne( $sql, NULL, $values ) ) { if ( $sqlData = dbFetchOne( $sql, NULL, $values ) ) {
foreach ( $postFuncs as $element=>$func ) foreach ( $postFuncs as $element=>$func )

View File

@ -98,8 +98,7 @@ function dbEscape( $string )
return( $dbConn->quote( $string ) ); return( $dbConn->quote( $string ) );
} }
function dbQuery( $sql, $params=NULL ) function dbQuery( $sql, $params=NULL ) {
{
global $dbConn; global $dbConn;
if ( dbLog( $sql, true ) ) if ( dbLog( $sql, true ) )
return; return;

View File

@ -1381,7 +1381,7 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&amp;' )
switch ( $filter['terms'][$i]['attr'] ) switch ( $filter['terms'][$i]['attr'] )
{ {
case 'MonitorName': case 'MonitorName':
$filter['sql'] .= dbEscape('M.'.preg_replace( '/^Monitor/', '', $filter['terms'][$i]['attr'] )); $filter['sql'] .= 'M.'.preg_replace( '/^Monitor/', '', $filter['terms'][$i]['attr'] );
break; break;
case 'DateTime': case 'DateTime':
$filter['sql'] .= "E.StartTime"; $filter['sql'] .= "E.StartTime";
@ -1407,7 +1407,7 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&amp;' )
case 'Cause': case 'Cause':
case 'Notes': case 'Notes':
case 'Archived': case 'Archived':
$filter['sql'] .= "E.".$filter['terms'][$i]['attr']; $filter['sql'] .= 'E.'.$filter['terms'][$i]['attr'];
break; break;
case 'DiskPercent': case 'DiskPercent':
$filter['sql'] .= getDiskPercent(); $filter['sql'] .= getDiskPercent();