|
@@ 142-164 (lines=23) @@
|
| 139 |
|
|
| 140 |
|
results.append(dv) |
| 141 |
|
|
| 142 |
|
except sqlite3.Error as e: |
| 143 |
|
self.logger.error('Historizing SQL Read Error for %s: %s', node_id, e) |
| 144 |
|
|
| 145 |
|
if nb_values: |
| 146 |
|
if len(results) > nb_values: |
| 147 |
|
cont = results[nb_values].ServerTimestamp |
| 148 |
|
|
| 149 |
|
results = results[:nb_values] |
| 150 |
|
|
| 151 |
|
return results, cont |
| 152 |
|
|
| 153 |
|
def new_historized_event(self, source_id, ev_fields, period): |
| 154 |
|
with self._lock: |
| 155 |
|
_c_new = self._conn.cursor() |
| 156 |
|
|
| 157 |
|
self._datachanges_period[source_id] = period |
| 158 |
|
self._event_fields[source_id] = ev_fields |
| 159 |
|
|
| 160 |
|
table = self._get_table_name(source_id) |
| 161 |
|
columns = self._get_event_columns(ev_fields) |
| 162 |
|
|
| 163 |
|
# create a table for the event which will store fields generated by the source object's events |
| 164 |
|
# note that _Timestamp is for SQL query, _EventTypeName is for debugging, be careful not to create event |
| 165 |
|
# properties with these names |
| 166 |
|
try: |
| 167 |
|
_c_new.execute('CREATE TABLE "{tn}" (_Id INTEGER PRIMARY KEY NOT NULL, ' |
|
@@ 25-47 (lines=23) @@
|
| 22 |
|
self._db_file = path |
| 23 |
|
self._lock = Lock() |
| 24 |
|
self._event_fields = {} |
| 25 |
|
|
| 26 |
|
self._conn = sqlite3.connect(self._db_file, detect_types=sqlite3.PARSE_DECLTYPES, check_same_thread=False) |
| 27 |
|
|
| 28 |
|
def new_historized_node(self, node_id, period, count=0): |
| 29 |
|
with self._lock: |
| 30 |
|
_c_new = self._conn.cursor() |
| 31 |
|
|
| 32 |
|
table = self._get_table_name(node_id) |
| 33 |
|
|
| 34 |
|
self._datachanges_period[node_id] = period, count |
| 35 |
|
|
| 36 |
|
# create a table for the node which will store attributes of the DataValue object |
| 37 |
|
# note: Value/VariantType TEXT is only for human reading, the actual data is stored in VariantBinary column |
| 38 |
|
try: |
| 39 |
|
_c_new.execute('CREATE TABLE "{tn}" (_Id INTEGER PRIMARY KEY NOT NULL,' |
| 40 |
|
' ServerTimestamp TIMESTAMP,' |
| 41 |
|
' SourceTimestamp TIMESTAMP,' |
| 42 |
|
' StatusCode INTEGER,' |
| 43 |
|
' Value TEXT,' |
| 44 |
|
' VariantType TEXT,' |
| 45 |
|
' VariantBinary BLOB)'.format(tn=table)) |
| 46 |
|
|
| 47 |
|
except sqlite3.Error as e: |
| 48 |
|
self.logger.info('Historizing SQL Table Creation Error for %s: %s', node_id, e) |
| 49 |
|
|
| 50 |
|
self._conn.commit() |