# Tony Mack <tmack@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: Events.py,v 1.11 2007/01/19 17:50:46 tmack Exp $
+# $Id: EventObjects.py,v 1.3 2007/05/16 18:07:02 tmack Exp $
#
from PLC.Faults import *
table_name = 'event_object'
primary_key = 'event_id'
fields = {
- 'event_object.event_id': Parameter(int, "Event identifier"),
+ 'event_id': Parameter(int, "Event identifier"),
'person_id': Parameter(int, "Identifier of person responsible for event, if any"),
'node_id': Parameter(int, "Identifier of node responsible for event, if any"),
'fault_code': Parameter(int, "Event fault code"),
def __init__(self, api, event_filter = None, columns = None):
Table.__init__(self, api, EventObject, columns)
+
+ all_fields = EventObject.fields.keys()
+ if not columns:
+ columns = all_fields
+ else:
+ columns = filter(lambda column: column in all_fields, columns)
+
+ # Since we are querying a table (not a view) ensure that timestamps
+ # are converted to ints in the db before being returned
+ timestamps = ['time']
+ for col in columns:
+ if col in timestamps:
+ index = columns.index(col)
+ columns[index] = "CAST(date_part('epoch', events.time) AS bigint) AS time"
+ elif col in [EventObject.primary_key]:
+ index = columns.index(col)
+ columns[index] = EventObject.table_name+"."+EventObject.primary_key
+
sql = "SELECT %s FROM event_object, events WHERE True" % \
- ", ".join(self.columns)
- if event_filter is not None:
+ ", ".join(columns)
+
+ if event_filter is not None:
if isinstance(event_filter, (list, tuple, set)):
event_filter = Filter(EventObject.fields, {'event_id': event_filter})
elif isinstance(event_filter, dict):
event_filter = Filter(EventObject.fields, event_filter)
sql += " AND (%s) " % event_filter.sql(api)
sql += " AND events.event_id = event_object.event_id "
- sql += " ORDER BY %s" % EventObject.primary_key
- self.selectall(sql)
+ sql += " ORDER BY %s" % EventObject.table_name+"."+EventObject.primary_key
+
+ self.selectall(sql)