2 # Functions for interacting with the events table in the database
4 # Tony Mack <tmack@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Debug import profile
11 from PLC.Table import Row, Table
15 Representation of a row in the events table.
19 primary_key = 'event_id'
21 'event_id': Parameter(int, "Event identifier"),
22 'person_id': Parameter(int, "Identifier of person responsible for event"),
23 'event_type': Parameter(str, "Type of event"),
24 'object_type': Parameter(str, "Type of object affected by this event"),
25 'fault_code': Parameter(int, "Event fault code"),
26 'call': Parameter(str, "Call responsible for this event"),
27 'time': Parameter(str, "Date/Time the event took place"),
28 'object_ids': Parameter([int], "Ids of objects affected by this event")
33 Representation of row(s) from the events table in the database.
36 def __init__(self, api, event_ids = None, person_ids = None, event_types = None, \
37 object_types = None, object_ids = None, fault_codes = None):
41 sql = "SELECT %s from view_events WHERE True" % ", ".join(Event.fields)
44 sql += " AND event_id IN (%s)" % ", ".join(map(str, event_ids))
47 sql += " AND person_id IN (%s)" % ", ".join(map(str, person_ids))
50 sql += " AND object_ids in (%s)" % ", ".join(map(str, object_ids))
53 sql += " AND event_type in (%s)" % ", ".join(api.db.quote(event_types))
56 sql += " AND object_type in (%s)" % ", ".join(api.db.quote(object_types))
59 sql += " And fault_code in (%s)" % ", ".join(map(str, fault_codes))
61 rows = self.api.db.selectall(sql)
64 self[row['event_id']] = event = Event(api, row)
65 for aggregate in ['object_ids']:
66 if not event.has_key(aggregate) or event[aggregate] is None:
69 elements = event[aggregate].split(',')
71 event[aggregate] = map(int, elements)
73 event[aggregate] = elements