1112 self._sql.entities[sql].append(attrs) |
1112 self._sql.entities[sql].append(attrs) |
1113 |
1113 |
1114 def _handle_insert_entity_sql(self, session, sql, attrs): |
1114 def _handle_insert_entity_sql(self, session, sql, attrs): |
1115 # We have to overwrite the source given in parameters |
1115 # We have to overwrite the source given in parameters |
1116 # as here, we directly use the system source |
1116 # as here, we directly use the system source |
1117 attrs['source'] = 'system' |
|
1118 attrs['asource'] = self.system_source.uri |
1117 attrs['asource'] = self.system_source.uri |
1119 self._append_to_entities(sql, attrs) |
1118 self._append_to_entities(sql, attrs) |
1120 |
1119 |
1121 def _handle_is_relation_sql(self, session, sql, attrs): |
1120 def _handle_is_relation_sql(self, session, sql, attrs): |
1122 self._append_to_entities(sql, attrs) |
1121 self._append_to_entities(sql, attrs) |
1135 # begin by inserting eid/type/source/extid into the entities table |
1134 # begin by inserting eid/type/source/extid into the entities table |
1136 if extid is not None: |
1135 if extid is not None: |
1137 assert isinstance(extid, str) |
1136 assert isinstance(extid, str) |
1138 extid = b64encode(extid) |
1137 extid = b64encode(extid) |
1139 attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid, |
1138 attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid, |
1140 'source': 'system', 'asource': source.uri} |
1139 'asource': source.uri} |
1141 self._handle_insert_entity_sql(session, self.sqlgen.insert('entities', attrs), attrs) |
1140 self._handle_insert_entity_sql(session, self.sqlgen.insert('entities', attrs), attrs) |
1142 # insert core relations: is, is_instance_of and cw_source |
1141 # insert core relations: is, is_instance_of and cw_source |
1143 try: |
1142 try: |
1144 self._handle_is_relation_sql(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)', |
1143 self._handle_is_relation_sql(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)', |
1145 (entity.eid, eschema_eid(session, entity.e_schema))) |
1144 (entity.eid, eschema_eid(session, entity.e_schema))) |