當前位置: 首頁>>代碼示例>>Python>>正文


Python errorcode.ER_BAD_DB_ERROR屬性代碼示例

本文整理匯總了Python中mysql.connector.errorcode.ER_BAD_DB_ERROR屬性的典型用法代碼示例。如果您正苦於以下問題:Python errorcode.ER_BAD_DB_ERROR屬性的具體用法?Python errorcode.ER_BAD_DB_ERROR怎麽用?Python errorcode.ER_BAD_DB_ERROR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在mysql.connector.errorcode的用法示例。


在下文中一共展示了errorcode.ER_BAD_DB_ERROR屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def __init__(self, user, password, database=None, verbose=LOG_OFF):
        # passwd = input("Password > ")
        # passwd = password
        self._v = verbose

        if database is not None:
            self.database = database
            try:
                self.conn = maria.connect(user=user, password=password, database=self.database)
            except maria.Error as err:
                if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
                    print("Something is wrong with your user name or password")
                elif err.errno == errorcode.ER_BAD_DB_ERROR:
                    print("Database does not exist")
                else:
                    print(err)
        else:
            try:
                self.conn = maria.connect(user=user, password=password)
            except maria.Error as err:
                if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
                    print("Something is wrong with your user name or password")
                else:
                    print(err) 
開發者ID:dfrc-korea,項目名稱:carpe,代碼行數:26,代碼來源:mariadb.py

示例2: create_connection

# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def create_connection(database=None, user=None, password=None, port=None):
    args = {}

    option_files = list(filter(os.path.exists, map(os.path.abspath, map(os.path.expanduser, [
        '/etc/my.cnf',
        '~/.my.cnf',
    ]))))

    if option_files:
        args['option_files'] = option_files
    if database:
        args['database'] = database
    if user:
        args['user'] = user
    if password:
        args['password'] = password
    if port:
        args['port'] = port

    cnx = None
    try:
        cnx = mysql.connector.connect(**args)
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            print("Something is wrong with your user name or password")
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
            print("Database does not exist")
        else:
            print(err)

    return cnx 
開發者ID:ithemal,項目名稱:Ithemal,代碼行數:33,代碼來源:utilities.py

示例3: ConnectToDatabase

# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def ConnectToDatabase(self):
		try:
			self.cnx.database = self.db
		except mysql.connector.Error as err:
			if err.errno == errorcode.ER_BAD_DB_ERROR:
				self.CreateDatabase()
				self.cnx.database = self.db
			else:
				print(err.msg) 
開發者ID:TPayneExperience,項目名稱:LLP_026_MySQL_PyQt_Example,代碼行數:11,代碼來源:DB_manager.py

示例4: connect

# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def connect(self):
        """
        Creates connection to database, sets connection and cursor
        Connection to database can be loosed,
          if that happens you can use this function to reconnect to database
        """
        if self.engine == "mysql":
            found_connector = False
            try:
                # Import official mysql connector if exists
                import mysql.connector as mysql_module
                from mysql.connector import errorcode
                found_connector = True
            except ImportError:
                pass
            if not found_connector:
                # Check MySQLdb as secondary option
                try:
                    import MySQLdb as mysql_module
                except ImportError:
                    raise ValueError(
                        'Please, install mysql-connector or mysqlclient module before using this library.'
                    )
            # Connect to db
            try:
                self.connection = mysql_module.connect(**self.settings)
            except mysql_module.Error as err:
                if found_connector:
                    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
                        raise ValueError("Wrong credentials, ACCESS DENIED")
                    elif err.errno == errorcode.ER_BAD_DB_ERROR:
                        raise ValueError(
                            "Database %s does not exists" % (self.settings['database'])
                        )
                    else:
                        raise ValueError(err)
                # @TODO Add detailed errors for MySQLdb
                raise err
        elif self.engine == "postgres":
            try:
                import psycopg2
            except ImportError:
                raise ValueError(
                    'Please, install psycopg2 module before using plugin.'
                )
            self.connection = psycopg2.connect(**self.settings)
        else:
            raise NotImplementedError(
                "Database engine %s not implemented!" % self.engine
            )

        self.cursor = self.connection.cursor() 
開發者ID:mastizada,項目名稱:dbConnect,代碼行數:54,代碼來源:dbConnect.py


注:本文中的mysql.connector.errorcode.ER_BAD_DB_ERROR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。