当前位置: 首页>>代码示例>>Python>>正文


Python base.BaseDatabaseWrapper类代码示例

本文整理汇总了Python中django.db.backends.base.base.BaseDatabaseWrapper的典型用法代码示例。如果您正苦于以下问题:Python BaseDatabaseWrapper类的具体用法?Python BaseDatabaseWrapper怎么用?Python BaseDatabaseWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BaseDatabaseWrapper类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: close

 def close(self):
     self.validate_thread_sharing()
     # If database is in memory, closing the connection destroys the
     # database. To prevent accidental data loss, ignore close requests on
     # an in-memory db.
     if not self.is_in_memory_db():
         BaseDatabaseWrapper.close(self)
开发者ID:GeyseR,项目名称:django,代码行数:7,代码来源:base.py

示例2: __init__

    def __init__(self, *args, **kwargs):
        BaseDatabaseWrapper.__init__(self, *args, **kwargs)

        self.server_version = None
        self.features = DatabaseFeatures(self)
        self.ops = DatabaseOperations(self)
        self.client = DatabaseClient(self)
        self.creation = DatabaseCreation(self)
        self.introspection = DatabaseIntrospection(self)
        self.validation = DatabaseValidation(self)
开发者ID:qz267,项目名称:django-mysqlndb-backend,代码行数:10,代码来源:base.py

示例3: create_cloned_sqlite_db

def create_cloned_sqlite_db(queries):
    """
    Magic. Inspired by:
    http://stackoverflow.com/questions/8045602/how-can-i-copy-an-in-memory-sqlite-database-to-another-in-memory-sqlite-database
    http://stackoverflow.com/questions/8242837/django-multiprocessing-and-database-connections
    """
    for query_list, database_wrapper in zip(queries, connections.all()):
        # Work around :memory: in django/db/backends/sqlite3/base.py
        BaseDatabaseWrapper.close(database_wrapper)

        cursor = database_wrapper.cursor()
        for sql in query_list.split(';'):
            sql += ';'
            cursor.execute(sql)
        database_wrapper.connection.commit()
开发者ID:mathspace,项目名称:discover-road-runner,代码行数:15,代码来源:runners.py

示例4: _rollback

 def _rollback(self):
     try:
         BaseDatabaseWrapper._rollback(self)
     except NotSupportedError:
         pass
开发者ID:mysql,项目名称:mysql-connector-python,代码行数:5,代码来源:base.py

示例5: run_tests

    def run_tests(self, test_labels, extra_tests=None, **kwargs):
        extra = 1 if extra_tests else 0
        start = time.time()
        if not test_labels:
            # If no test labels were provided, provide them
            # and remove our custom exclusions
            test_labels = [
                # Don't double-discover tests?
                app.__name__.replace('.models', '')
                for app in self.get_apps_after_exclusions()
            ]
            # Hide most of the test output so we can focus on failures,
            # unless the user wanted to see the full output per app.
            if self.verbosity == 1:
                self.verbosity = 0

        self.setup_test_environment()

        # Prepare (often many) test suites to be run across multiple processes
        # suite = self.build_suite(test_labels, extra_tests)
        processes = []
        source_queue = Queue(maxsize=len(test_labels) + extra)

        for label in test_labels:
            suite = self.build_suite([label])
            source_queue.put((label, suite))
        if extra_tests:
            source_queue.put(
                ('extra_tests', self.build_suite(None, extra_tests))
            )

        if self.ramdb and self.db_files_exist():
            # Have run before, reuse the RAM DB.
            in_files = self.db_file_paths()
            print('Reusing database files: \n{}'.format('\n'.join(in_files)))
            queries = []
            for in_file_name in in_files:
                with open(in_file_name) as infile:
                    queries.append('\n'.join(infile.readlines()))
            if DJANGO_VERSION[1] >= 7:
                hijack_setup_databases(self.verbosity, self.interactive)
            else:
                self.setup_databases()
        else:
            start = time.time()
            tag_hash = self.get_source_control_tag_hash()
            if tag_hash == self.DEFAULT_TAG_HASH:
                print('git or hg source control not found, '
                      'only most recent migration saved')
            print('Running (often slow) migrations... \n'
                  'Hint: Use --ramdb={} to reuse the final stored SQL later.'
                  .format(tag_hash))
            tag_hash = os.path.join(self.ramdb_saves, tag_hash)
            if not os.path.exists(tag_hash):
                os.makedirs(tag_hash)
            # Only run the slow migrations if --ramdb is not specified,
            # or running for first time
            old_config = self.setup_databases()
            queries = []
            for database_wrapper in connections.all():
                connection = database_wrapper.connection
                sql = '\n'.join(line for line in connection.iterdump())
                queries.append(sql)
                # Work around :memory: in django/db/backends/sqlite3/base.py
                BaseDatabaseWrapper.close(database_wrapper)
                mem, db_name = database_wrapper.creation.test_db_signature()
                with open(self.get_db_path(db_name, tag_hash), 'w') as outfile:
                    outfile.write(sql)
            self.teardown_databases(old_config)
            msg = 'Setup, migrations, ... completed in {:.3f} seconds'.format(
                time.time() - start
            )
            print(msg)

        result_queue = Queue(maxsize=len(test_labels) + extra)
        process_args = (self, source_queue, result_queue, queries)
        for _ in range(min(self.concurrency, len(test_labels) + extra)):
            p = Process(target=multi_proc_run_tests, args=process_args)
            p.start()
            processes.append(p)
        else:
            # Concurrency == 0 - run in same process
            multi_proc_run_tests(*process_args)

        for p in processes:
            p.join()

        results = []
        retrieved_labels = []
        while not result_queue.empty():
            retrieved_label, result = result_queue.get()
            results.append(result)
            retrieved_labels.append(retrieved_label)
        not_covered = set(test_labels) - set(retrieved_labels)
        if not_covered:
            msg = (
                'Tests that did not return results under --concurrency={} '
                '(try running separately, or with --concurrency=0): {}'.format(
                    self.concurrency,
                    ' '.join(sorted(not_covered)),
#.........这里部分代码省略.........
开发者ID:mathspace,项目名称:discover-road-runner,代码行数:101,代码来源:runners.py

示例6:

"""
开发者ID:letouriste001,项目名称:SmartForest_2.0,代码行数:1,代码来源:base.py


注:本文中的django.db.backends.base.base.BaseDatabaseWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。