Code Duplication    Length = 23-23 lines in 2 locations

opcua/server/history_sql.py 2 locations

@@ 143-165 (lines=23) @@
140
141
            return results, cont
142
143
    def new_historized_event(self, source_id, ev_fields, period):
144
        with self._lock:
145
            _c_new = self._conn.cursor()
146
147
            self._datachanges_period[source_id] = period
148
            self._event_fields[source_id] = ev_fields
149
150
            table = self._get_table_name(source_id)
151
            columns = self._get_event_columns(ev_fields)
152
153
            # create a table for the event which will store fields generated by the source object's events
154
            # note that _Timestamp is for SQL query, _EventTypeName is for debugging, be careful not to create event
155
            # properties with these names
156
            try:
157
                _c_new.execute('CREATE TABLE "{tn}" (_Id INTEGER PRIMARY KEY NOT NULL, '
158
                               '_Timestamp TIMESTAMP, '
159
                               '_EventTypeName TEXT, '
160
                               '{co})'.format(tn=table, co=columns))
161
162
            except sqlite3.Error as e:
163
                self.logger.info('Historizing SQL Table Creation Error for events from %s: %s', source_id, e)
164
165
            self._conn.commit()
166
167
    def save_event(self, event):
168
        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: