Code Duplication    Length = 23-23 lines in 2 locations

opcua/server/history_sql.py 2 locations

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