server/sources/native.py
changeset 9821 2077c8da1893
parent 9724 e45bf9baa7b7
parent 9802 9f815b1f2516
child 9892 928732ec00dd
equal deleted inserted replaced
9819:95902c0b991b 9821:2077c8da1893
   713             cnx = cnx.cnxset.cnx
   713             cnx = cnx.cnxset.cnx
   714             # getattr to get the actual connection if cnx is a CnxLoggingWrapper
   714             # getattr to get the actual connection if cnx is a CnxLoggingWrapper
   715             # instance
   715             # instance
   716             print 'exec', query, args, getattr(cnx, '_cnx', cnx)
   716             print 'exec', query, args, getattr(cnx, '_cnx', cnx)
   717         try:
   717         try:
   718             # str(query) to avoid error if it's an unicode string
   718             # str(query) to avoid error if it's a unicode string
   719             cursor.execute(str(query), args)
   719             cursor.execute(str(query), args)
   720         except Exception as ex:
   720         except Exception as ex:
   721             if self.repo.config.mode != 'test':
   721             if self.repo.config.mode != 'test':
   722                 # during test we get those message when trying to alter sqlite
   722                 # during test we get those message when trying to alter sqlite
   723                 # db schema
   723                 # db schema
   760         """
   760         """
   761         if server.DEBUG & server.DBG_SQL:
   761         if server.DEBUG & server.DBG_SQL:
   762             print 'execmany', query, 'with', len(args), 'arguments'
   762             print 'execmany', query, 'with', len(args), 'arguments'
   763         cursor = cnx.cnxset.cu
   763         cursor = cnx.cnxset.cu
   764         try:
   764         try:
   765             # str(query) to avoid error if it's an unicode string
   765             # str(query) to avoid error if it's a unicode string
   766             cursor.executemany(str(query), args)
   766             cursor.executemany(str(query), args)
   767         except Exception as ex:
   767         except Exception as ex:
   768             if self.repo.config.mode != 'test':
   768             if self.repo.config.mode != 'test':
   769                 # during test we get those message when trying to alter sqlite
   769                 # during test we get those message when trying to alter sqlite
   770                 # db schema
   770                 # db schema
   892     _handle_insert_entity_sql = doexec
   892     _handle_insert_entity_sql = doexec
   893     _handle_is_instance_of_sql = _handle_source_relation_sql = _handle_is_relation_sql
   893     _handle_is_instance_of_sql = _handle_source_relation_sql = _handle_is_relation_sql
   894 
   894 
   895     def add_info(self, cnx, entity, source, extid):
   895     def add_info(self, cnx, entity, source, extid):
   896         """add type and source info for an eid into the system table"""
   896         """add type and source info for an eid into the system table"""
   897         with cnx.ensure_cnx_set:
   897         assert cnx.cnxset is not None
   898             # begin by inserting eid/type/source/extid into the entities table
   898         # begin by inserting eid/type/source/extid into the entities table
   899             if extid is not None:
   899         if extid is not None:
   900                 assert isinstance(extid, str)
   900             assert isinstance(extid, str)
   901                 extid = b64encode(extid)
   901             extid = b64encode(extid)
   902             attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
   902         attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
   903                      'asource': source.uri}
   903                  'asource': source.uri}
   904             self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs)
   904         self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs)
   905             # insert core relations: is, is_instance_of and cw_source
   905         # insert core relations: is, is_instance_of and cw_source
   906             try:
   906         try:
   907                 self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
   907             self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
   908                                              (entity.eid, eschema_eid(cnx, entity.e_schema)))
   908                                          (entity.eid, eschema_eid(cnx, entity.e_schema)))
   909             except IndexError:
   909         except IndexError:
   910                 # during schema serialization, skip
   910             # during schema serialization, skip
   911                 pass
   911             pass
   912             else:
   912         else:
   913                 for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   913             for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   914                     self._handle_is_relation_sql(cnx,
   914                 self._handle_is_relation_sql(cnx,
   915                                                  'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
   915                                              'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
   916                                                  (entity.eid, eschema_eid(cnx, eschema)))
   916                                              (entity.eid, eschema_eid(cnx, eschema)))
   917             if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
   917         if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
   918                 self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
   918             self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
   919                                              (entity.eid, source.eid))
   919                                          (entity.eid, source.eid))
   920             # now we can update the full text index
   920         # now we can update the full text index
   921             if self.do_fti and self.need_fti_indexation(entity.cw_etype):
   921         if self.do_fti and self.need_fti_indexation(entity.cw_etype):
   922                 self.index_entity(cnx, entity=entity)
   922             self.index_entity(cnx, entity=entity)
   923 
   923 
   924     def update_info(self, cnx, entity, need_fti_update):
   924     def update_info(self, cnx, entity, need_fti_update):
   925         """mark entity as being modified, fulltext reindex if needed"""
   925         """mark entity as being modified, fulltext reindex if needed"""
   926         if self.do_fti and need_fti_update:
   926         if self.do_fti and need_fti_update:
   927             # reindex the entity only if this query is updating at least
   927             # reindex the entity only if this query is updating at least