334 if cnxset is None: |
334 if cnxset is None: |
335 _cnxset = self.repo._get_cnxset() |
335 _cnxset = self.repo._get_cnxset() |
336 _cnxset.cnxset_set() |
336 _cnxset.cnxset_set() |
337 else: |
337 else: |
338 _cnxset = cnxset |
338 _cnxset = cnxset |
339 if not self.dbhelper.has_fti_table(_cnxset['system']): |
339 if not self.dbhelper.has_fti_table(_cnxset.cu): |
340 if not self.repo.config.creating: |
340 if not self.repo.config.creating: |
341 self.critical('no text index table') |
341 self.critical('no text index table') |
342 self.do_fti = False |
342 self.do_fti = False |
343 if cnxset is None: |
343 if cnxset is None: |
344 _cnxset.cnxset_freed() |
344 _cnxset.cnxset_freed() |
704 |
704 |
705 def doexec(self, session, query, args=None, rollback=True): |
705 def doexec(self, session, query, args=None, rollback=True): |
706 """Execute a query. |
706 """Execute a query. |
707 it's a function just so that it shows up in profiling |
707 it's a function just so that it shows up in profiling |
708 """ |
708 """ |
709 cursor = session.cnxset[self.uri] |
709 cursor = session.cnxset.cu |
710 if server.DEBUG & server.DBG_SQL: |
710 if server.DEBUG & server.DBG_SQL: |
711 cnx = session.cnxset.connection(self.uri) |
711 cnx = session.cnxset.cnx |
712 # getattr to get the actual connection if cnx is a CnxLoggingWrapper |
712 # getattr to get the actual connection if cnx is a CnxLoggingWrapper |
713 # instance |
713 # instance |
714 print 'exec', query, args, getattr(cnx, '_cnx', cnx) |
714 print 'exec', query, args, getattr(cnx, '_cnx', cnx) |
715 try: |
715 try: |
716 # str(query) to avoid error if it's an unicode string |
716 # str(query) to avoid error if it's an unicode string |
721 # db schema |
721 # db schema |
722 self.critical("sql: %r\n args: %s\ndbms message: %r", |
722 self.critical("sql: %r\n args: %s\ndbms message: %r", |
723 query, args, ex.args[0]) |
723 query, args, ex.args[0]) |
724 if rollback: |
724 if rollback: |
725 try: |
725 try: |
726 session.cnxset.connection(self.uri).rollback() |
726 session.cnxset.rollback() |
727 if self.repo.config.mode != 'test': |
727 if self.repo.config.mode != 'test': |
728 self.critical('transaction has been rolled back') |
728 self.critical('transaction has been rolled back') |
729 except Exception as ex: |
729 except Exception as ex: |
730 pass |
730 pass |
731 if ex.__class__.__name__ == 'IntegrityError': |
731 if ex.__class__.__name__ == 'IntegrityError': |
749 """Execute a query. |
749 """Execute a query. |
750 it's a function just so that it shows up in profiling |
750 it's a function just so that it shows up in profiling |
751 """ |
751 """ |
752 if server.DEBUG & server.DBG_SQL: |
752 if server.DEBUG & server.DBG_SQL: |
753 print 'execmany', query, 'with', len(args), 'arguments' |
753 print 'execmany', query, 'with', len(args), 'arguments' |
754 cursor = session.cnxset[self.uri] |
754 cursor = session.cnxset.cu |
755 try: |
755 try: |
756 # str(query) to avoid error if it's an unicode string |
756 # str(query) to avoid error if it's an unicode string |
757 cursor.executemany(str(query), args) |
757 cursor.executemany(str(query), args) |
758 except Exception as ex: |
758 except Exception as ex: |
759 if self.repo.config.mode != 'test': |
759 if self.repo.config.mode != 'test': |
760 # during test we get those message when trying to alter sqlite |
760 # during test we get those message when trying to alter sqlite |
761 # db schema |
761 # db schema |
762 self.critical("sql many: %r\n args: %s\ndbms message: %r", |
762 self.critical("sql many: %r\n args: %s\ndbms message: %r", |
763 query, args, ex.args[0]) |
763 query, args, ex.args[0]) |
764 try: |
764 try: |
765 session.cnxset.connection(self.uri).rollback() |
765 session.cnxset.rollback() |
766 if self.repo.config.mode != 'test': |
766 if self.repo.config.mode != 'test': |
767 self.critical('transaction has been rolled back') |
767 self.critical('transaction has been rolled back') |
768 except Exception: |
768 except Exception: |
769 pass |
769 pass |
770 raise |
770 raise |
778 coltype, allownull = rdef_physical_info(self.dbhelper, rdef) |
778 coltype, allownull = rdef_physical_info(self.dbhelper, rdef) |
779 if not self.dbhelper.alter_column_support: |
779 if not self.dbhelper.alter_column_support: |
780 self.error("backend can't alter %s.%s to %s%s", table, column, coltype, |
780 self.error("backend can't alter %s.%s to %s%s", table, column, coltype, |
781 not allownull and 'NOT NULL' or '') |
781 not allownull and 'NOT NULL' or '') |
782 return |
782 return |
783 self.dbhelper.change_col_type(LogCursor(session.cnxset[self.uri]), |
783 self.dbhelper.change_col_type(LogCursor(session.cnxset.cu), |
784 table, column, coltype, allownull) |
784 table, column, coltype, allownull) |
785 self.info('altered %s.%s: now %s%s', table, column, coltype, |
785 self.info('altered %s.%s: now %s%s', table, column, coltype, |
786 not allownull and 'NOT NULL' or '') |
786 not allownull and 'NOT NULL' or '') |
787 |
787 |
788 def update_rdef_null_allowed(self, session, rdef): |
788 def update_rdef_null_allowed(self, session, rdef): |
793 # not supported (and NOT NULL not set by yams in that case, so no |
793 # not supported (and NOT NULL not set by yams in that case, so no |
794 # worry) |
794 # worry) |
795 return |
795 return |
796 table, column = rdef_table_column(rdef) |
796 table, column = rdef_table_column(rdef) |
797 coltype, allownull = rdef_physical_info(self.dbhelper, rdef) |
797 coltype, allownull = rdef_physical_info(self.dbhelper, rdef) |
798 self.dbhelper.set_null_allowed(LogCursor(session.cnxset[self.uri]), |
798 self.dbhelper.set_null_allowed(LogCursor(session.cnxset.cu), |
799 table, column, coltype, allownull) |
799 table, column, coltype, allownull) |
800 |
800 |
801 def update_rdef_indexed(self, session, rdef): |
801 def update_rdef_indexed(self, session, rdef): |
802 table, column = rdef_table_column(rdef) |
802 table, column = rdef_table_column(rdef) |
803 if rdef.indexed: |
803 if rdef.indexed: |
811 self.create_index(session, table, column, unique=True) |
811 self.create_index(session, table, column, unique=True) |
812 else: |
812 else: |
813 self.drop_index(session, table, column, unique=True) |
813 self.drop_index(session, table, column, unique=True) |
814 |
814 |
815 def create_index(self, session, table, column, unique=False): |
815 def create_index(self, session, table, column, unique=False): |
816 cursor = LogCursor(session.cnxset[self.uri]) |
816 cursor = LogCursor(session.cnxset.cu) |
817 self.dbhelper.create_index(cursor, table, column, unique) |
817 self.dbhelper.create_index(cursor, table, column, unique) |
818 |
818 |
819 def drop_index(self, session, table, column, unique=False): |
819 def drop_index(self, session, table, column, unique=False): |
820 cursor = LogCursor(session.cnxset[self.uri]) |
820 cursor = LogCursor(session.cnxset.cu) |
821 self.dbhelper.drop_index(cursor, table, column, unique) |
821 self.dbhelper.drop_index(cursor, table, column, unique) |
822 |
822 |
823 # system source interface ################################################# |
823 # system source interface ################################################# |
824 |
824 |
825 def _eid_type_source(self, session, eid, sql, _retry=True): |
825 def _eid_type_source(self, session, eid, sql, _retry=True): |
1375 FTIndexEntityOp.get_instance(session).add_data(entity.eid) |
1375 FTIndexEntityOp.get_instance(session).add_data(entity.eid) |
1376 |
1376 |
1377 def fti_unindex_entities(self, session, entities): |
1377 def fti_unindex_entities(self, session, entities): |
1378 """remove text content for entities from the full text index |
1378 """remove text content for entities from the full text index |
1379 """ |
1379 """ |
1380 cursor = session.cnxset['system'] |
1380 cursor = session.cnxset.cu |
1381 cursor_unindex_object = self.dbhelper.cursor_unindex_object |
1381 cursor_unindex_object = self.dbhelper.cursor_unindex_object |
1382 try: |
1382 try: |
1383 for entity in entities: |
1383 for entity in entities: |
1384 cursor_unindex_object(entity.eid, cursor) |
1384 cursor_unindex_object(entity.eid, cursor) |
1385 except Exception: # let KeyboardInterrupt / SystemExit propagate |
1385 except Exception: # let KeyboardInterrupt / SystemExit propagate |
1388 |
1388 |
1389 def fti_index_entities(self, session, entities): |
1389 def fti_index_entities(self, session, entities): |
1390 """add text content of created/modified entities to the full text index |
1390 """add text content of created/modified entities to the full text index |
1391 """ |
1391 """ |
1392 cursor_index_object = self.dbhelper.cursor_index_object |
1392 cursor_index_object = self.dbhelper.cursor_index_object |
1393 cursor = session.cnxset['system'] |
1393 cursor = session.cnxset.cu |
1394 try: |
1394 try: |
1395 # use cursor_index_object, not cursor_reindex_object since |
1395 # use cursor_index_object, not cursor_reindex_object since |
1396 # unindexing done in the FTIndexEntityOp |
1396 # unindexing done in the FTIndexEntityOp |
1397 for entity in entities: |
1397 for entity in entities: |
1398 cursor_index_object(entity.eid, |
1398 cursor_index_object(entity.eid, |