Code Duplication    Length = 23-23 lines in 2 locations

opcua/server/history_sql.py 2 locations

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