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


Python _mysql_connector.MySQL类代码示例

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


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

示例1: test_character_set_name

    def test_character_set_name(self):
        cmy1 = MySQL(buffered=True)
        self.assertRaises(MySQLInterfaceError, cmy1.character_set_name)

        cmy1.connect(**self.connect_kwargs)

        self.assertEqual('latin1', cmy1.character_set_name())
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:7,代码来源:test_cext_api.py

示例2: test_get_server_info

    def test_get_server_info(self):
        cmy = MySQL()
        self.assertRaises(MySQLInterfaceError, cmy.get_server_info)

        cmy.connect(**self.connect_kwargs)
        version = cmy.get_server_version()
        info = cmy.get_server_info()
        self.assertIsInstance(info, str)
        self.assertTrue(info.startswith('.'.join([str(v) for v in version])))
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:9,代码来源:test_cext_api.py

示例3: test_get_server_version

    def test_get_server_version(self):
        cmy = MySQL()
        self.assertRaises(MySQLInterfaceError, cmy.get_server_version)

        cmy.connect(**self.connect_kwargs)
        version = cmy.get_server_version()
        self.assertIsInstance(version, tuple)
        self.assertEqual(3, len(version))
        self.assertTrue(all([isinstance(v, int) and v > 0 for v in version]))

        self.assertTrue(3 < version[0] < 7)
        self.assertTrue(0 < version[1] < 20)
        self.assertTrue(0 < version[2] < 99)
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:13,代码来源:test_cext_api.py

示例4: test___init__

    def test___init__(self):
        cmy = MySQL()
        self.assertEqual(False, cmy.buffered())
        self.assertEqual(False, cmy.raw())

        cmy = MySQL(buffered=True, raw=True)
        self.assertEqual(True, cmy.buffered())
        self.assertEqual(True, cmy.raw())

        exp = 'gbk'
        cmy = MySQL(charset_name=exp)
        cmy.connect(**self.connect_kwargs)
        self.assertEqual(exp, cmy.character_set_name())
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:13,代码来源:test_cext_api.py

示例5: test_warning_count

    def test_warning_count(self):
        cmy = MySQL()
        cmy.connect(**self.connect_kwargs)

        cmy.query("SELECT 'a' + 'b'", buffered=False)
        fetch_rows(cmy)
        self.assertEqual(2, cmy.warning_count())

        cmy.query("SELECT 1 + 1", buffered=True)
        self.assertEqual(0, cmy.warning_count())
        fetch_rows(cmy)
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:11,代码来源:test_cext_api.py

示例6: test_connected

 def test_connected(self):
     config = self.connect_kwargs.copy()
     cmy = MySQL()
     self.assertFalse(cmy.connected())
     cmy.connect(**config)
     self.assertTrue(cmy.connected())
     cmy.close()
     self.assertFalse(cmy.connected())
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:8,代码来源:test_cext_api.py

示例7: test_raw

    def test_raw(self):
        cmy = MySQL()
        self.assertEqual(False, cmy.raw())
        cmy.raw(True)
        self.assertEqual(True, cmy.raw())
        cmy.raw(False)
        self.assertEqual(False, cmy.raw())

        self.assertRaises(TypeError, cmy.raw, 'a')
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:9,代码来源:test_cext_api.py

示例8: test_buffered

    def test_buffered(self):
        cmy = MySQL()
        self.assertEqual(False, cmy.buffered())
        cmy.buffered(True)
        self.assertEqual(True, cmy.buffered())
        cmy.buffered(False)
        self.assertEqual(False, cmy.buffered())

        self.assertRaises(TypeError, cmy.buffered, 'a')
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:9,代码来源:test_cext_api.py

示例9: test_thread_id

    def test_thread_id(self):
        cmy = MySQL()
        self.assertRaises(MySQLInterfaceError, cmy.thread_id)

        cmy.connect(**self.connect_kwargs)

        if tests.PY2:
            self.assertIsInstance(cmy.thread_id(), long)
        else:
            self.assertIsInstance(cmy.thread_id(), int)
        self.assertGreater(cmy.thread_id(), 0)
        thread_id = cmy.thread_id()
        cmy.close()

        self.assertRaises(MySQLError, cmy.thread_id)
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:15,代码来源:test_cext_api.py

示例10: test_escape_string

    def test_escape_string(self):
        cases = [
            ('new\nline', b'new\\nline'),
            ('carriage\rreturn', b'carriage\\rreturn'),
            ('control\x1aZ', b'control\\ZZ'),
            ("single'quote", b"single\\'quote"),
            ('double"quote', b'double\\"quote'),
            ('back\slash', b'back\\\\slash'),
            ('nul\0char', b'nul\\0char'),
            (u"Kangxi⽃\0⽇", b'Kangxi\xe2\xbd\x83\\0\xe2\xbd\x87'),
            (b'bytes\0ob\'j\n"ct\x1a', b'bytes\\0ob\\\'j\\n\\"ct\\Z'),
        ]

        cmy = MySQL()
        cmy.connect(**self.connect_kwargs)

        unicode_string = u"Kangxi⽃\0⽇"
        self.assertRaises(UnicodeEncodeError, cmy.escape_string, unicode_string)

        cmy.set_character_set("UTF8")

        for value, exp in cases:
            self.assertEqual(exp, cmy.escape_string(value))

        self.assertRaises(TypeError, cmy.escape_string, 1234);
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:25,代码来源:test_cext_api.py

示例11: test_set_character_set

    def test_set_character_set(self):
        cmy1 = MySQL(buffered=True)
        self.assertRaises(MySQLInterfaceError, cmy1.set_character_set, 'latin2')

        cmy1.connect(**self.connect_kwargs)
        orig = cmy1.character_set_name()

        cmy1.set_character_set('utf8')
        charset = cmy1.character_set_name()
        self.assertNotEqual(orig, charset)
        self.assertEqual('utf8', charset)

        self.assertRaises(MySQLInterfaceError,
                          cmy1.set_character_set, 'ham_spam')

        variables = ('character_set_connection',)
        exp = {b'character_set_connection': b'utf8',}
        self.assertEqual(exp, get_variables(cmy1, variables=variables))

        exp = {b'character_set_connection': b'big5',}
        cmy1.set_character_set('big5')
        self.assertEqual(exp, get_variables(cmy1, variables=variables))
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:22,代码来源:test_cext_api.py

示例12: test_get_character_set_info

    def test_get_character_set_info(self):
        cmy = MySQL()
        self.assertRaises(MySQLInterfaceError, cmy.get_character_set_info)
        cmy.connect(**self.connect_kwargs)

        # We go by the default of MySQL, which is latin1/swedish_ci
        exp = {'comment': '', 'name': 'latin1_swedish_ci',
               'csname': 'latin1', 'mbmaxlen': 1, 'number': 8, 'mbminlen': 1}
        result = cmy.get_character_set_info()
        # make 'comment' deterministic
        result['comment'] = ''
        self.assertEqual(exp, result)

        cmy.query("SET NAMES utf8")
        cmy.set_character_set('utf8')

        exp = {'comment': '', 'name': 'utf8_general_ci',
               'csname': 'utf8', 'mbmaxlen': 3, 'number': 33, 'mbminlen': 1}
        result = cmy.get_character_set_info()
        # make 'comment' deterministic
        result['comment'] = ''
        self.assertEqual(exp, result)
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:22,代码来源:test_cext_api.py

示例13: test_get_host_info

    def test_get_host_info(self):
        config = self.connect_kwargs.copy()
        cmy = MySQL(buffered=True)
        self.assertRaises(MySQLInterfaceError, cmy.get_host_info)

        cmy.connect(**config)

        if os.name == 'posix':
            # On POSIX systems we would be connected by UNIX socket
            self.assertTrue('via UNIX socket' in cmy.get_host_info())

        # Connect using TCP/IP
        config['unix_socket'] = None
        cmy.connect(**config)
        self.assertTrue('via TCP/IP' in cmy.get_host_info())
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:15,代码来源:test_cext_api.py

示例14: test_affected_rows

    def test_affected_rows(self):
        cmy = MySQL(buffered=True)
        cmy.connect(**self.connect_kwargs)

        table = "affected_rows"

        cmy.select_db('myconnpy')
        cmy.query("DROP TABLE IF EXISTS {0}".format(table))
        cmy.query("CREATE TABLE {0} (c1 INT, c2 INT)".format(table))

        cmy.query("INSERT INTO {0} (c1, c2) VALUES "
                  "(1, 10), (2, 20), (3, 30)".format(table))
        self.assertEqual(3, cmy.affected_rows())

        cmy.query("UPDATE {0} SET c2 = c2 + 1 WHERE c1 < 3".format(table))
        self.assertEqual(2, cmy.affected_rows())

        cmy.query("DELETE FROM {0} WHERE c1 IN (1, 2, 3)".format(table))
        self.assertEqual(3, cmy.affected_rows())

        cmy.query("DROP TABLE IF EXISTS {0}".format(table))
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:21,代码来源:test_cext_api.py

示例15: test_get_client_info

    def test_get_client_info(self):
        cmy = MySQL(buffered=True)

        match = re.match(r"(\d+\.\d+.\d+)(.*)", cmy.get_client_info())
        self.assertNotEqual(None, match)
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:5,代码来源:test_cext_api.py


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