439 finally: |
439 finally: |
440 if self.repo.config.init_cnxset_pool: |
440 if self.repo.config.init_cnxset_pool: |
441 self.open_source_connections() |
441 self.open_source_connections() |
442 |
442 |
443 def init(self, activated, source_entity): |
443 def init(self, activated, source_entity): |
444 try: |
|
445 # test if 'asource' column exists |
|
446 query = self.dbhelper.sql_add_limit_offset('SELECT asource FROM entities', 1) |
|
447 source_entity._cw.system_sql(query) |
|
448 except Exception: |
|
449 self.eid_type_source = self.eid_type_source_pre_131 |
|
450 super(NativeSQLSource, self).init(activated, source_entity) |
444 super(NativeSQLSource, self).init(activated, source_entity) |
451 self.init_creating(source_entity._cw.cnxset) |
445 self.init_creating(source_entity._cw.cnxset) |
452 |
446 |
453 def shutdown(self): |
447 def shutdown(self): |
454 self.eid_generator.close() |
448 self.eid_generator.close() |
821 cursor = LogCursor(cnx.cnxset.cu) |
815 cursor = LogCursor(cnx.cnxset.cu) |
822 self.dbhelper.drop_index(cursor, table, column, unique) |
816 self.dbhelper.drop_index(cursor, table, column, unique) |
823 |
817 |
824 # system source interface ################################################# |
818 # system source interface ################################################# |
825 |
819 |
826 def _eid_type_source(self, cnx, eid, sql): |
820 def eid_type_extid(self, cnx, eid): # pylint: disable=E0202 |
|
821 """return a tuple (type, extid) for the entity with id <eid>""" |
|
822 sql = 'SELECT type, extid FROM entities WHERE eid=%s' % eid |
827 try: |
823 try: |
828 res = self.doexec(cnx, sql).fetchone() |
824 res = self.doexec(cnx, sql).fetchone() |
829 if res is not None: |
825 if res is not None: |
|
826 if not isinstance(res, list): |
|
827 res = list(res) |
|
828 res[-1] = self.decode_extid(res[-1]) |
830 return res |
829 return res |
831 except Exception: |
830 except Exception: |
832 self.exception('failed to query entities table for eid %s', eid) |
831 self.exception('failed to query entities table for eid %s', eid) |
833 raise UnknownEid(eid) |
832 raise UnknownEid(eid) |
834 |
|
835 def eid_type_source(self, cnx, eid): # pylint: disable=E0202 |
|
836 """return a tuple (type, extid, source) for the entity with id <eid>""" |
|
837 sql = 'SELECT type, extid, asource FROM entities WHERE eid=%s' % eid |
|
838 res = self._eid_type_source(cnx, eid, sql) |
|
839 if not isinstance(res, list): |
|
840 res = list(res) |
|
841 res[-2] = self.decode_extid(res[-2]) |
|
842 return res |
|
843 |
|
844 def eid_type_source_pre_131(self, cnx, eid): |
|
845 """return a tuple (type, extid, source) for the entity with id <eid>""" |
|
846 sql = 'SELECT type, extid FROM entities WHERE eid=%s' % eid |
|
847 res = self._eid_type_source(cnx, eid, sql) |
|
848 if not isinstance(res, list): |
|
849 res = list(res) |
|
850 res[-1] = self.decode_extid(res[-1]) |
|
851 res.append("system") |
|
852 return res |
|
853 |
833 |
854 def _handle_is_relation_sql(self, cnx, sql, attrs): |
834 def _handle_is_relation_sql(self, cnx, sql, attrs): |
855 """ Handler for specific is_relation sql that may be |
835 """ Handler for specific is_relation sql that may be |
856 overwritten in some stores""" |
836 overwritten in some stores""" |
857 self.doexec(cnx, sql % attrs) |
837 self.doexec(cnx, sql % attrs) |