From 9e435bc2c372e220106f50cd639a9fb40c2d6d8f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 2 Jan 2017 11:04:55 -0500 Subject: [PATCH 1/2] Use sub queries instead of joins to fix errors when using new mysql defaults. --- web/ajax/status.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/web/ajax/status.php b/web/ajax/status.php index d12e3c9f6..638c5ca85 100644 --- a/web/ajax/status.php +++ b/web/ajax/status.php @@ -71,9 +71,9 @@ $statusData = array( "DefaultScale" => true, "WebColour" => true, "Sequence" => true, - "MinEventId" => array( "sql" => "min(Events.Id)", "table" => "Events", "join" => "Events.MonitorId = Monitors.Id", "group" => "Events.MonitorId" ), - "MaxEventId" => array( "sql" => "max(Events.Id)", "table" => "Events", "join" => "Events.MonitorId = Monitors.Id", "group" => "Events.MonitorId" ), - "TotalEvents" => array( "sql" => "count(Events.Id)", "table" => "Events", "join" => "Events.MonitorId = Monitors.Id", "group" => "Events.MonitorId" ), + "MinEventId" => array( "sql" => "(SELECT min(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id" ), + "MaxEventId" => array( "sql" => "(SELECT max(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id" ), + "TotalEvents" => array( "sql" => "(SELECT count(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id" ), "Status" => array( "zmu" => "-m ".escapeshellarg($_REQUEST['id'][0])." -s" ), "FrameRate" => array( "zmu" => "-m ".escapeshellarg($_REQUEST['id'][0])." -f" ), ), @@ -129,10 +129,10 @@ $statusData = array( "Messaged" => true, "Executed" => true, "Notes" => true, - "MinFrameId" => array( "sql" => "min(Frames.FrameId)", "table" => "Frames", "join" => "Events.Id = Frames.EventId", "group" => "Frames.EventId" ), - "MaxFrameId" => array( "sql" => "max(Frames.FrameId)", "table" => "Frames", "join" => "Events.Id = Frames.EventId", "group" => "Frames.EventId" ), - "MinFrameDelta" => array( "sql" => "min(Frames.Delta)", "table" => "Frames", "join" => "Events.Id = Frames.EventId", "group" => "Frames.EventId" ), - "MaxFrameDelta" => array( "sql" => "max(Frames.Delta)", "table" => "Frames", "join" => "Events.Id = Frames.EventId", "group" => "Frames.EventId" ), + "MinFrameId" => array( "sql" => "(SELECT min(Frames.FrameId) FROM Frames WHERE EventId=Events.Id)" ), + "MaxFrameId" => array( "sql" => "(SELECT max(Frames.FrameId) FROM Frames WHERE Events.Id = Frames.EventId)" ), + "MinFrameDelta" => array( "sql" => "(SELECT min(Frames.Delta) FROM Frames WHERE Events.Id = Frames.EventId)" ), + "MaxFrameDelta" => array( "sql" => "(SELECT max(Frames.Delta) FROM Frames WHERE Events.Id = Frames.EventId)" ), //"Path" => array( "postFunc" => "getEventPath" ), ), ), @@ -386,7 +386,7 @@ function getNearEvents() else $midSql = ''; - $sql = "select E.* as Id from Events as E inner join Monitors as M on E.MonitorId = M.Id where ".dbEscape($sortColumn)." ".($sortOrder=='asc'?'<=':'>=')." '".$event[$_REQUEST['sort_field']]."'".$_REQUEST['filter']['sql'].$midSql." order by $sortColumn ".($sortOrder=='asc'?'desc':'asc'); + $sql = "select E.Id as Id from Events as E inner join Monitors as M on E.MonitorId = M.Id where ".dbEscape($sortColumn)." ".($sortOrder=='asc'?'<=':'>=')." '".$event[$_REQUEST['sort_field']]."'".$_REQUEST['filter']['sql'].$midSql." order by $sortColumn ".($sortOrder=='asc'?'desc':'asc'); $result = dbQuery( $sql ); while ( $id = dbFetchNext( $result, 'Id' ) ) { @@ -397,7 +397,7 @@ function getNearEvents() } } - $sql = "select E.* as Id from Events as E inner join Monitors as M on E.MonitorId = M.Id where $sortColumn ".($sortOrder=='asc'?'>=':'<=')." '".$event[$_REQUEST['sort_field']]."'".$_REQUEST['filter']['sql'].$midSql." order by $sortColumn $sortOrder"; + $sql = "select E.Id as Id from Events as E inner join Monitors as M on E.MonitorId = M.Id where $sortColumn ".($sortOrder=='asc'?'>=':'<=')." '".$event[$_REQUEST['sort_field']]."'".$_REQUEST['filter']['sql'].$midSql." order by $sortColumn $sortOrder"; $result = dbQuery( $sql ); while ( $id = dbFetchNext( $result, 'Id' ) ) { From 40408bf6dd4a06f9c5c29bcbc60efd74e3754da3 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 2 Jan 2017 11:05:08 -0500 Subject: [PATCH 2/2] fix sql queries --- web/skins/classic/views/timeline.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/skins/classic/views/timeline.php b/web/skins/classic/views/timeline.php index 6f0da98aa..0f3d52d40 100644 --- a/web/skins/classic/views/timeline.php +++ b/web/skins/classic/views/timeline.php @@ -143,11 +143,11 @@ foreach( dbFetchAll( $monitorsSql ) as $row ) } $rangeSql = "select min(E.StartTime) as MinTime, max(E.EndTime) as MaxTime from Events as E inner join Monitors as M on (E.MonitorId = M.Id) where not isnull(E.StartTime) and not isnull(E.EndTime)"; -$eventsSql = "SELECT * FROM Events WHERE NOT isnull(StartTime)"; +$eventsSql = "SELECT * FROM Events AS E WHERE NOT isnull(StartTime)"; if ( !empty($user['MonitorIds']) ) { - $monFilterSql = ' AND MonitorId IN ('.$user['MonitorIds'].')'; + $monFilterSql = ' AND E.MonitorId IN ('.$user['MonitorIds'].')'; $rangeSql .= $monFilterSql; $eventsSql .= $monFilterSql;