|
@@ 143-175 (lines=33) @@
|
| 140 |
|
|
| 141 |
|
return results, cont |
| 142 |
|
|
| 143 |
|
def new_historized_event(self, source_id, etype, period): |
| 144 |
|
with self._lock: |
| 145 |
|
_c_new = self._conn.cursor() |
| 146 |
|
|
| 147 |
|
table = self._get_table_name(source_id) |
| 148 |
|
|
| 149 |
|
# FIXME need to call vars(etype) to get all attributes as strings so proper table columns can be created |
| 150 |
|
# FIXME should a table already exist, but a new etype is supplied, table needs to be ALTERED |
| 151 |
|
|
| 152 |
|
self._datachanges_period[source_id] = period |
| 153 |
|
|
| 154 |
|
self._event_attributes[source_id] = etype.__dict__.keys() # get fields (find a better way?) |
| 155 |
|
|
| 156 |
|
# create a table for the event which will store attributes of the Event object |
| 157 |
|
# note: Value/VariantType TEXT is only for human reading, the actual data is stored in VariantBinary column |
| 158 |
|
try: |
| 159 |
|
_c_new.execute('CREATE TABLE "{tn}" (Id INTEGER PRIMARY KEY NOT NULL,' |
| 160 |
|
' Timestamp TIMESTAMP,' |
| 161 |
|
' Time BLOB,' |
| 162 |
|
' ReceiveTime BLOB,' |
| 163 |
|
' LocalTime BLOB,' |
| 164 |
|
' EventId BLOB,' |
| 165 |
|
' EventType BLOB,' |
| 166 |
|
' Severity BLOB,' |
| 167 |
|
' Message BLOB,' |
| 168 |
|
' SourceName BLOB,' |
| 169 |
|
' SourceNode BLOB,' |
| 170 |
|
' ServerHandle BLOB)'.format(tn=table)) |
| 171 |
|
|
| 172 |
|
except sqlite3.Error as e: |
| 173 |
|
self.logger.info('Historizing SQL Table Creation Error for events from %s: %s', source_id, e) |
| 174 |
|
|
| 175 |
|
self._conn.commit() |
| 176 |
|
|
| 177 |
|
def save_event(self, event): |
| 178 |
|
with self._lock: |
|
@@ 26-48 (lines=23) @@
|
| 23 |
|
|
| 24 |
|
self._conn = sqlite3.connect(self._db_file, detect_types=sqlite3.PARSE_DECLTYPES, check_same_thread=False) |
| 25 |
|
|
| 26 |
|
def new_historized_node(self, node_id, period, count=0): |
| 27 |
|
with self._lock: |
| 28 |
|
_c_new = self._conn.cursor() |
| 29 |
|
|
| 30 |
|
table = self._get_table_name(node_id) |
| 31 |
|
|
| 32 |
|
self._datachanges_period[node_id] = period, count |
| 33 |
|
|
| 34 |
|
# create a table for the node which will store attributes of the DataValue object |
| 35 |
|
# note: Value/VariantType TEXT is only for human reading, the actual data is stored in VariantBinary column |
| 36 |
|
try: |
| 37 |
|
_c_new.execute('CREATE TABLE "{tn}" (Id INTEGER PRIMARY KEY NOT NULL,' |
| 38 |
|
' ServerTimestamp TIMESTAMP,' |
| 39 |
|
' SourceTimestamp TIMESTAMP,' |
| 40 |
|
' StatusCode INTEGER,' |
| 41 |
|
' Value TEXT,' |
| 42 |
|
' VariantType TEXT,' |
| 43 |
|
' VariantBinary BLOB)'.format(tn=table)) |
| 44 |
|
|
| 45 |
|
except sqlite3.Error as e: |
| 46 |
|
self.logger.info('Historizing SQL Table Creation Error for %s: %s', node_id, e) |
| 47 |
|
|
| 48 |
|
self._conn.commit() |
| 49 |
|
|
| 50 |
|
def save_node_value(self, node_id, datavalue): |
| 51 |
|
with self._lock: |