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

Method read_event_history

opcua/server/history_sql.py:197–234  ·  view source on GitHub ↗
(self, source_id, start, end, nb_values, evfilter)

Source from the content-addressed store, hash-verified

195 self._conn.commit()
196
197 def read_event_history(self, source_id, start, end, nb_values, evfilter):
198 with self._lock:
199 _c_read = self._conn.cursor()
200
201 table = self._get_table_name(source_id)
202 start_time, end_time, order, limit = self._get_bounds(start, end, nb_values)
203 clauses, clauses_str = self._get_select_clauses(source_id, evfilter)
204
205 cont = None
206 cont_timestamps = []
207 results = []
208
209 # select events from the database; SQL select clause is built from EventFilter and available fields
210 try:
211 for row in _c_read.execute(
212 'SELECT "_Timestamp", {cl} FROM "{tn}" WHERE "_Timestamp" BETWEEN ? AND ? ORDER BY "_Id" {dir} LIMIT ?'
213 .format(cl=clauses_str, tn=table, dir=order), (start_time, end_time, limit)):
214
215 fdict = {}
216 cont_timestamps.append(row[0])
217 for i, field in enumerate(row[1:]):
218 if field is not None:
219 fdict[clauses[i]] = variant_from_binary(Buffer(field))
220 else:
221 fdict[clauses[i]] = ua.Variant(None)
222
223 results.append(events.Event.from_field_dict(fdict))
224
225 except sqlite3.Error as e:
226 self.logger.error('Historizing SQL Read Error events for node %s: %s', source_id, e)
227
228 if nb_values:
229 if len(results) > nb_values: # start > ua.get_win_epoch() and
230 cont = cont_timestamps[nb_values]
231
232 results = results[:nb_values]
233
234 return results, cont
235
236 def _get_table_name(self, node_id):
237 return str(node_id.NamespaceIndex) + '_' + str(node_id.Identifier)

Callers

nothing calls this directly

Calls 6

_get_table_nameMethod · 0.95
_get_boundsMethod · 0.95
_get_select_clausesMethod · 0.95
variant_from_binaryFunction · 0.90
BufferClass · 0.90
from_field_dictMethod · 0.80

Tested by

no test coverage detected