本文整理匯總了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