870 res.append("system") |
870 res.append("system") |
871 return res |
871 return res |
872 |
872 |
873 def extid2eid(self, cnx, extid): |
873 def extid2eid(self, cnx, extid): |
874 """get eid from an external id. Return None if no record found.""" |
874 """get eid from an external id. Return None if no record found.""" |
875 assert isinstance(extid, str) |
875 assert isinstance(extid, binary_type) |
876 args = {'x': b64encode(extid)} |
876 args = {'x': b64encode(extid).decode('ascii')} |
877 cursor = self.doexec(cnx, |
877 cursor = self.doexec(cnx, |
878 'SELECT eid FROM entities WHERE extid=%(x)s', |
878 'SELECT eid FROM entities WHERE extid=%(x)s', |
879 args) |
879 args) |
880 # XXX testing rowcount cause strange bug with sqlite, results are there |
880 # XXX testing rowcount cause strange bug with sqlite, results are there |
881 # but rowcount is 0 |
881 # but rowcount is 0 |
911 """add type and source info for an eid into the system table""" |
911 """add type and source info for an eid into the system table""" |
912 assert cnx.cnxset is not None |
912 assert cnx.cnxset is not None |
913 # begin by inserting eid/type/source/extid into the entities table |
913 # begin by inserting eid/type/source/extid into the entities table |
914 if extid is not None: |
914 if extid is not None: |
915 assert isinstance(extid, binary_type) |
915 assert isinstance(extid, binary_type) |
916 extid = b64encode(extid) |
916 extid = b64encode(extid).decode('ascii') |
917 attrs = {'type': text_type(entity.cw_etype), 'eid': entity.eid, 'extid': extid and text_type(extid), |
917 attrs = {'type': text_type(entity.cw_etype), 'eid': entity.eid, 'extid': extid, |
918 'asource': text_type(source.uri)} |
918 'asource': text_type(source.uri)} |
919 self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs) |
919 self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs) |
920 # insert core relations: is, is_instance_of and cw_source |
920 # insert core relations: is, is_instance_of and cw_source |
921 try: |
921 try: |
922 self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)', |
922 self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)', |