@@ -37,7 +37,7 @@ class MonitoredNode(object):
3737
3838 def __init__ (self , aspace , ndata ):
3939 self ._aspace = aspace
40- self ._nodeid = AddressSpaceSQLite ._nodeid_to_numeric (ndata .nodeid )
40+ self ._nodeid = AddressSpaceSQLite ._nodeid_surjection (ndata .nodeid )
4141
4242 @property
4343 def aspace (self ):
@@ -174,15 +174,17 @@ def _setitem_backend(self, nodeid, ndata):
174174 self .backend .commit ()
175175
176176 @staticmethod
177- def _nodeid_to_numeric (nodeid ):
177+ def _nodeid_surjection (nodeid ):
178178 assert (isinstance (nodeid , ua .uatypes .NodeId ))
179179 # For database lookups, map TwoByte and FourByte onto NumericNodeId.
180180 if nodeid .NodeIdType == NodeIdType .Numeric :
181181 return nodeid
182- if nodeid .NodeIdType in (NodeIdType .TwoByte , NodeIdType .FourByte ):
182+ elif nodeid .NodeIdType in (NodeIdType .TwoByte , NodeIdType .FourByte ):
183183 return NumericNodeId (nodeid .Identifier , nodeid .NamespaceIndex )
184+ elif nodeid .NodeIdType in (NodeIdType .String , NodeIdType .Guid , NodeIdType .ByteString ):
185+ return nodeid
184186 else :
185- raise Exception ('NodeIdType {:d} is not supported for backend lookups .' .format (nodeid .NodeIdType ))
187+ raise Exception ('NodeIdType {:d} is not supported.' .format (nodeid .NodeIdType ))
186188
187189 def keys (self ):
188190 raise Exception ("dict.keys() is not supported for performance. Use iterator." )
@@ -227,8 +229,8 @@ def _dump(self, namespaceidx=AddressSpace.DEFAULT_USER_NAMESPACE_INDEX):
227229 for ref in ndata .references :
228230 if ref .NodeId .NamespaceIndex != namespaceidx :
229231 continue
230- numNodeId = AddressSpaceSQLite ._nodeid_to_numeric (ndata .nodeid )
231- self ._insert_reference (numNodeId , ref )
232+ mapNodeId = AddressSpaceSQLite ._nodeid_surjection (ndata .nodeid )
233+ self ._insert_reference (mapNodeId , ref )
232234
233235 # 3. Integrity checks.
234236 for nodeid , ndata in self ._cache .items ():
@@ -240,9 +242,9 @@ def _dump(self, namespaceidx=AddressSpace.DEFAULT_USER_NAMESPACE_INDEX):
240242
241243 # Write NodeData to database
242244 def _write_nodedata (self , ndata ):
243- numNodeId = AddressSpaceSQLite ._nodeid_to_numeric (ndata .nodeid )
244- self ._write_attributes (numNodeId , ndata )
245- self ._write_references (numNodeId , ndata )
245+ mapNodeId = AddressSpaceSQLite ._nodeid_surjection (ndata .nodeid )
246+ self ._write_attributes (mapNodeId , ndata )
247+ self ._write_references (mapNodeId , ndata )
246248
247249 def _write_attributes (self , nodeid , ndata ):
248250 assert (nodeid .NodeIdType == NodeIdType .Numeric )
@@ -259,9 +261,9 @@ def _write_references(self, nodeid, ndata):
259261 # Read NodeData from database
260262 @staticmethod
261263 def _read_nodedata (backend , nodeid , ndata ):
262- # Search key = numeric nodeid in opc-ua binary format
263- numNodeId = AddressSpaceSQLite ._nodeid_to_numeric (nodeid )
264- hexNodeId = AddressSpaceSQLite ._to_hex (ua .ua_binary .nodeid_to_binary (numNodeId ))
264+ # Search key = nodeid in opc-ua binary format
265+ mapNodeId = AddressSpaceSQLite ._nodeid_surjection (nodeid )
266+ hexNodeId = AddressSpaceSQLite ._to_hex (ua .ua_binary .nodeid_to_binary (mapNodeId ))
265267
266268 AddressSpaceSQLite ._read_attributes (backend , hexNodeId , ndata )
267269 AddressSpaceSQLite ._read_references (backend , hexNodeId , ndata )
0 commit comments