MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / save_event

Method save_event

opcua/server/history_sql.py:162–195  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

160 self._conn.commit()
161
162 def save_event(self, event):
163 with self._lock:
164 _c_sub = self._conn.cursor()
165
166 table = self._get_table_name(event.SourceNode) #Emitting node is not always the Source (event.SourceNode)
167 columns, placeholders, evtup = self._format_event(event) #from event_prop_dict
168 event_type = event.EventType # useful for troubleshooting database
169
170 # insert the event into the database
171 try:
172 _c_sub.execute(
173 'INSERT INTO "{tn}" ("_Id", "_Timestamp", "_EventTypeName", {co}) VALUES (NULL, "{ts}", "{et}", {pl})'
174 .format(tn=table, co=columns, ts=event.Time, et=event_type, pl=placeholders), evtup)
175
176 except sqlite3.Error as e:
177 self.logger.error('Historizing SQL Insert Error for events from %s: %s', event.SourceNode, e)
178
179 self._conn.commit()
180
181 # get this node's period from the period dict and calculate the limit
182 period = self._datachanges_period[event.SourceNode]
183
184 if period:
185 # after the insert, if a period was specified delete all records older than period
186 date_limit = datetime.utcnow() - period
187
188 try:
189 _c_sub.execute('DELETE FROM "{tn}" WHERE Time < ?'.format(tn=table),
190 (date_limit.isoformat(' '),))
191 except sqlite3.Error as e:
192 self.logger.error('Historizing SQL Delete Old Data Error for events from %s: %s',
193 event.SourceNode, e)
194
195 self._conn.commit()
196
197 def read_event_history(self, source_id, start, end, nb_values, evfilter):
198 with self._lock:

Callers

nothing calls this directly

Calls 2

_get_table_nameMethod · 0.95
_format_eventMethod · 0.95

Tested by

no test coverage detected