本文整理汇总了Python中psycopg2.errorcodes.DUPLICATE_DATABASE属性的典型用法代码示例。如果您正苦于以下问题:Python errorcodes.DUPLICATE_DATABASE属性的具体用法?Python errorcodes.DUPLICATE_DATABASE怎么用?Python errorcodes.DUPLICATE_DATABASE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类psycopg2.errorcodes
的用法示例。
在下文中一共展示了errorcodes.DUPLICATE_DATABASE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _execute_create_test_db
# 需要导入模块: from psycopg2 import errorcodes [as 别名]
# 或者: from psycopg2.errorcodes import DUPLICATE_DATABASE [as 别名]
def _execute_create_test_db(self, cursor, parameters, keepdb=False):
try:
if keepdb and self._database_exists(cursor, parameters['dbname']):
# If the database should be kept and it already exists, don't
# try to create a new one.
return
super()._execute_create_test_db(cursor, parameters, keepdb)
except Exception as e:
if getattr(e.__cause__, 'pgcode', '') != errorcodes.DUPLICATE_DATABASE:
# All errors except "database already exists" cancel tests.
sys.stderr.write('Got an error creating the test database: %s\n' % e)
sys.exit(2)
elif not keepdb:
# If the database should be kept, ignore "database already
# exists".
raise e
示例2: _execute_create_test_db
# 需要导入模块: from psycopg2 import errorcodes [as 别名]
# 或者: from psycopg2.errorcodes import DUPLICATE_DATABASE [as 别名]
def _execute_create_test_db(self, cursor, parameters, keepdb=False):
try:
super()._execute_create_test_db(cursor, parameters, keepdb)
except Exception as e:
if getattr(e.__cause__, 'pgcode', '') != errorcodes.DUPLICATE_DATABASE:
# All errors except "database already exists" cancel tests.
sys.stderr.write('Got an error creating the test database: %s\n' % e)
sys.exit(2)
elif not keepdb:
# If the database should be kept, ignore "database already
# exists".
raise e
示例3: _execute_raise_database_already_exists
# 需要导入模块: from psycopg2 import errorcodes [as 别名]
# 或者: from psycopg2.errorcodes import DUPLICATE_DATABASE [as 别名]
def _execute_raise_database_already_exists(self, cursor, parameters, keepdb=False):
error = DatabaseError('database %s already exists' % parameters['dbname'])
error.pgcode = errorcodes.DUPLICATE_DATABASE
raise DatabaseError() from error