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


Python pymysql.ProgrammingError方法代碼示例

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


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

示例1: current_role

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def current_role(conn, info):
    """return current role of database needs to be improved, I have no standby
       config"""

    _c = conn.cursor()
    _c_role = ""
    try:
        _c.execute(
            "select count(*) from performance_schema.replication_applier_status")
        _data = _c.fetchone()

        if _data[0] > 0:
            _c_role = "slave"
    except pymysql.ProgrammingError:
        # a bit dirty ... assume primary replication_applier_status is pretty new
        pass
    _c.close()
    _c_role = "primary"
    return _c_role 
開發者ID:ikzelf,項目名稱:zbxdb,代碼行數:21,代碼來源:mysql.py

示例2: setup_class

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def setup_class(cls):
        pymysql = pytest.importorskip('pymysql')
        pymysql.connect(host='localhost', user='root', passwd='',
                        db='pandas_nosetest')
        try:
            pymysql.connect(read_default_group='pandas')
        except pymysql.ProgrammingError:
            raise RuntimeError(
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf.")
        except pymysql.Error:
            raise RuntimeError(
                "Cannot connect to database. "
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf.") 
開發者ID:awslabs,項目名稱:predictive-maintenance-using-machine-learning,代碼行數:19,代碼來源:test_sql.py

示例3: setup_method

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def setup_method(self, request, datapath):
        pymysql = pytest.importorskip('pymysql')
        pymysql.connect(host='localhost', user='root', passwd='',
                        db='pandas_nosetest')
        try:
            pymysql.connect(read_default_group='pandas')
        except pymysql.ProgrammingError:
            raise RuntimeError(
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf.")
        except pymysql.Error:
            raise RuntimeError(
                "Cannot connect to database. "
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf.")

        self.method = request.function 
開發者ID:awslabs,項目名稱:predictive-maintenance-using-machine-learning,代碼行數:21,代碼來源:test_sql.py

示例4: process_item

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def process_item(self, item, spider):
        if spider.name in ['RssCrawler', 'GdeltCrawler']:
            # Search the CurrentVersion table for a version of the article
            try:
                self.cursor.execute(self.compare_versions, (item['url'],))
            except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                    pymysql.IntegrityError, TypeError) as error:
                self.log.error("Something went wrong in rss query: %s", error)

            # Save the result of the query. Must be done before the add,
            #   otherwise the result will be overwritten in the buffer
            old_version = self.cursor.fetchone()

            if old_version is not None and (datetime.datetime.strptime(
                    item['download_date'], "%y-%m-%d %H:%M:%S") -
                                            old_version[3]) \
                    < datetime.timedelta(hours=self.delta_time):
                # Compare the two download dates. index 3 of old_version
                # corresponds to the download_date attribute in the DB
                raise DropItem("Article in DB too recent. Not saving.")

        return item 
開發者ID:fhamborg,項目名稱:news-please,代碼行數:24,代碼來源:pipelines.py

示例5: query_messages_mariadb

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def query_messages_mariadb(cursor, sql_str):
    try:
        logger.info('Starting execute SQL')
        logger.info(sql_str)

        # execute sql string
        cursor.execute(sql_str)

        parse_messages_mariadb(cursor)
    except ProgrammingError as e:
        logger.error(e)
        logger.error('SQL execute error: '.format(sql_str)) 
開發者ID:insightfinder,項目名稱:InsightAgent,代碼行數:14,代碼來源:getmessages_mariadb.py

示例6: setup_class

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def setup_class(cls):
        _skip_if_no_pymysql()

        # test connection
        import pymysql
        try:
            # Try Travis defaults.
            # No real user should allow root access with a blank password.
            pymysql.connect(host='localhost', user='root', passwd='',
                            db='pandas_nosetest')
        except:
            pass
        else:
            return
        try:
            pymysql.connect(read_default_group='pandas')
        except pymysql.ProgrammingError:
            pytest.skip(
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf. ")
        except pymysql.Error:
            pytest.skip(
                "Cannot connect to database. "
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf. ") 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:29,代碼來源:test_sql.py

示例7: setup_method

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def setup_method(self, request, datapath):
        _skip_if_no_pymysql()
        import pymysql
        try:
            # Try Travis defaults.
            # No real user should allow root access with a blank password.
            self.conn = pymysql.connect(host='localhost', user='root',
                                        passwd='', db='pandas_nosetest')
        except:
            pass
        else:
            return
        try:
            self.conn = pymysql.connect(read_default_group='pandas')
        except pymysql.ProgrammingError:
            pytest.skip(
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf. ")
        except pymysql.Error:
            pytest.skip(
                "Cannot connect to database. "
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf. ")

        self.method = request.function 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:29,代碼來源:test_sql.py

示例8: fetchall

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pymysql.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
            return None 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:8,代碼來源:connector.py

示例9: execute

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def execute(self, query):
        retVal = False

        try:
            self.cursor.execute(query)
            retVal = True
        except (pymysql.OperationalError, pymysql.ProgrammingError), msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1]) 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:10,代碼來源:connector.py

示例10: test_nextset_error

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def test_nextset_error(self):
        con = self.connect(client_flag=CLIENT.MULTI_STATEMENTS)
        cur = con.cursor()

        for i in range(3):
            cur.execute("SELECT %s; xyzzy;", (i,))
            self.assertEqual([(i,)], list(cur))
            with self.assertRaises(pymysql.ProgrammingError):
                cur.nextset()
            self.assertEqual((), cur.fetchall()) 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:12,代碼來源:test_nextset.py

示例11: setup_method

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def setup_method(self, method):
        _skip_if_no_pymysql()
        import pymysql
        try:
            # Try Travis defaults.
            # No real user should allow root access with a blank password.
            self.conn = pymysql.connect(host='localhost', user='root',
                                        passwd='', db='pandas_nosetest')
        except:
            pass
        else:
            return
        try:
            self.conn = pymysql.connect(read_default_group='pandas')
        except pymysql.ProgrammingError:
            pytest.skip(
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf. ")
        except pymysql.Error:
            pytest.skip(
                "Cannot connect to database. "
                "Create a group of connection parameters under the heading "
                "[pandas] in your system's mysql default file, "
                "typically located at ~/.my.cnf or /etc/.my.cnf. ")

        self.method = method 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:29,代碼來源:test_sql.py

示例12: convert_exceptions

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def convert_exceptions(msg: str) -> Iterator:
    """Convert internal mysql exceptions to our InvalidDatabaseError"""
    from pymysql import OperationalError, InternalError, ProgrammingError
    try:
        yield
    except (OperationalError, InternalError, ProgrammingError) as exc:
        raise exceptions.InvalidDatabaseError(msg) from exc 
開發者ID:DHI-GRAS,項目名稱:terracotta,代碼行數:9,代碼來源:mysql.py

示例13: reset_mysql

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def reset_mysql(self):
        """
        Resets the MySQL database.
        """

        confirm = self.no_confirm

        print("""
Cleanup MySQL database:
    This will truncate all tables and reset the whole database.
""")

        if not confirm:
            confirm = 'yes' in builtins.input(
                """
    Do you really want to do this? Write 'yes' to confirm: {yes}"""
                    .format(yes='yes' if confirm else ''))

        if not confirm:
            print("Did not type yes. Thus aborting.")
            return

        print("Resetting database...")

        try:
            # initialize DB connection
            self.conn = pymysql.connect(host=self.mysql["host"],
                                        port=self.mysql["port"],
                                        db=self.mysql["db"],
                                        user=self.mysql["username"],
                                        passwd=self.mysql["password"])
            self.cursor = self.conn.cursor()

            self.cursor.execute("TRUNCATE TABLE CurrentVersions")
            self.cursor.execute("TRUNCATE TABLE ArchiveVersions")
            self.conn.close()
        except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                pymysql.IntegrityError, TypeError) as error:
            self.log.error("Database reset error: %s", error) 
開發者ID:fhamborg,項目名稱:news-please,代碼行數:41,代碼來源:__main__.py

示例14: connect

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def connect(self):
        self.initConnection()

        try:
            self.connector = pymysql.connect(host=self.hostname, user=self.user, passwd=self.password, db=self.db, port=self.port, connect_timeout=conf.timeout, use_unicode=True)
        except (pymysql.OperationalError, pymysql.InternalError, pymysql.ProgrammingError, struct.error), msg:
            raise SqlmapConnectionException(getSafeExString(msg)) 
開發者ID:sabri-zaki,項目名稱:EasY_HaCk,代碼行數:9,代碼來源:connector.py

示例15: fetchall

# 需要導入模塊: import pymysql [as 別名]
# 或者: from pymysql import ProgrammingError [as 別名]
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pymysql.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
            return None 
開發者ID:sabri-zaki,項目名稱:EasY_HaCk,代碼行數:8,代碼來源:connector.py


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