Code Duplication    Length = 23-23 lines in 2 locations

opcua/server/history_sql.py 2 locations

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