示例#1
0
    def test_example(self):
        conn = umysqldb.connect(host='127.0.0.1',
                                port=3306,
                                user='******',
                                passwd='',
                                db='mysql')

        cur = conn.cursor()

        cur.execute("SELECT Host,User FROM user")

        # print cur.description

        # r = cur.fetchall()
        # print r
        # ...or...
        u = False

        for r in cur.fetchall():
            u = u or conn.user in r

        self.assertTrue(u)

        cur.close()
        conn.close()
示例#2
0
 def test_issue_6(self):
     """ exception: TypeError: ord() expected a character, but string of length 0 found """
     conn = umysqldb.connect(host="localhost",
                             user="******",
                             passwd="",
                             db="mysql")
     c = conn.cursor()
     c.execute("select * from user")
     conn.close()
示例#3
0
 def test_issue_33(self):
     conn = umysqldb.connect(host="localhost", user="******", db=self.databases[0]["db"], charset="utf8")
     c = conn.cursor()
     try:
         c.execute(_uni("create table hei\xc3\x9fe (name varchar(32))", "utf8"))
         c.execute(_uni("insert into hei\xc3\x9fe (name) values ('Pi\xc3\xb1ata')", "utf8"))
         c.execute(_uni("select name from hei\xc3\x9fe", "utf8"))
         self.assertEqual(_uni("Pi\xc3\xb1ata","utf8"), c.fetchone()[0])
     finally:
         c.execute(_uni("drop table hei\xc3\x9fe", "utf8"))
示例#4
0
 def test_issue_33(self):
     conn = umysqldb.connect(host="localhost",
                             user="******",
                             db=self.databases[0]["db"],
                             charset="utf8")
     c = conn.cursor()
     try:
         c.execute(
             _uni("create table hei\xc3\x9fe (name varchar(32))", "utf8"))
         c.execute(
             _uni(
                 "insert into hei\xc3\x9fe (name) values ('Pi\xc3\xb1ata')",
                 "utf8"))
         c.execute(_uni("select name from hei\xc3\x9fe", "utf8"))
         self.assertEqual(_uni("Pi\xc3\xb1ata", "utf8"), c.fetchone()[0])
     finally:
         c.execute(_uni("drop table hei\xc3\x9fe", "utf8"))
示例#5
0
 def test_issue_17(self):
     """ could not connect mysql use passwod """
     conn = self.connections[0]
     host = self.databases[0]["host"]
     db = self.databases[0]["db"]
     c = conn.cursor()
     # grant access to a table to a user with a password
     try:
         c.execute("create table issue17 (x varchar(32) primary key)")
         c.execute("insert into issue17 (x) values ('hello, world!')")
         c.execute("grant all privileges on %s.issue17 to 'issue17user'@'%%' identified by '1234'" % db)
         conn.commit()
         
         conn2 = umysqldb.connect(host=host, user="******", passwd="1234", db=db)
         c2 = conn2.cursor()
         c2.execute("select x from issue17")
         self.assertEqual("hello, world!", c2.fetchone()[0])
     finally:
         c.execute("drop table issue17")
示例#6
0
    def test_example(self):
        conn = umysqldb.connect(host='127.0.0.1', port=3306, user='******', passwd='', db='mysql')
   

        cur = conn.cursor()

        cur.execute("SELECT Host,User FROM user")

        # print cur.description

        # r = cur.fetchall()
        # print r
        # ...or...
        u = False

        for r in cur.fetchall():
            u = u or conn.user in r

        self.assertTrue(u)

        cur.close()
        conn.close()
示例#7
0
    def test_issue_17(self):
        """ could not connect mysql use passwod """
        conn = self.connections[0]
        host = self.databases[0]["host"]
        db = self.databases[0]["db"]
        c = conn.cursor()
        # grant access to a table to a user with a password
        try:
            c.execute("create table issue17 (x varchar(32) primary key)")
            c.execute("insert into issue17 (x) values ('hello, world!')")
            c.execute(
                "grant all privileges on %s.issue17 to 'issue17user'@'%%' identified by '1234'"
                % db)
            conn.commit()

            conn2 = umysqldb.connect(host=host,
                                     user="******",
                                     passwd="1234",
                                     db=db)
            c2 = conn2.cursor()
            c2.execute("select x from issue17")
            self.assertEqual("hello, world!", c2.fetchone()[0])
        finally:
            c.execute("drop table issue17")
示例#8
0
# -*- coding:utf-8 -*-
# author:Lizr
# date:2013-6-7
# 清档工具,开服时用,小心使用


import umysqldb

# 初始化
conn = umysqldb.connect(host="10.1.1.18", port=3306, user="******", passwd="1231234", db="gamesg2")
cur = conn.cursor()
cur.execute("show tables")
tables = cur.fetchall()
for table in tables:
    table = table[0]
    if table.startswith("tb_cfg_"):
        continue
    elif table in ("tb_config", "tb_config_core"):
        continue
    else:
        cur.execute("truncate table %s" % table)
cur.execute("ALTER TABLE  `tb_user` AUTO_INCREMENT =1001")
conn.commit()


# 将开发网的拆分2表 扩展成10表
cur.execute("show tables")
result = cur.fetchall()
alltables = [r[0] for r in result]

# 必需要检查有没有少表
示例#9
0
 def test_issue_6(self):
     """ exception: TypeError: ord() expected a character, but string of length 0 found """
     conn = umysqldb.connect(host="localhost",user="******",passwd="",db="mysql")
     c = conn.cursor()
     c.execute("select * from user")
     conn.close()
示例#10
0
 def test_issue_34(self):
     try:
         umysqldb.connect(host="localhost", port=1237, user="******")
         self.fail()
     except umysqldb.OperationalError, e:
         self.assertEqual(2003, e.args[0])
示例#11
0
def test_access_denied_should_raise_OperationalError():
    umysqldb.connect(host='127.0.0.1', user='******', passwd='fdsa')
示例#12
0
 def test_issue_34(self):
     try:
         umysqldb.connect(host="localhost", port=1237, user="******")
         self.fail()
     except umysqldb.OperationalError, e:
         self.assertEqual(2003, e.args[0])
示例#13
0
# -*- coding:utf-8 -*-
# author:Lizr
# date:2013-6-7
# 清档工具,开服时用,小心使用

import umysqldb
# 初始化
conn = umysqldb.connect(host='10.1.1.18',
                        port=3306,
                        user='******',
                        passwd='1231234',
                        db='gamesg2')
cur = conn.cursor()
cur.execute("show tables")
tables = cur.fetchall()
for table in tables:
    table = table[0]
    if table.startswith('tb_cfg_'):
        continue
    elif table in ('tb_config', 'tb_config_core'):
        continue
    else:
        cur.execute("truncate table %s" % table)
cur.execute('ALTER TABLE  `tb_user` AUTO_INCREMENT =1001')
conn.commit()

# 将开发网的拆分2表 扩展成10表
cur.execute("show tables")
result = cur.fetchall()
alltables = [r[0] for r in result]
示例#14
0
def test_access_denied_should_raise_OperationalError():
    umysqldb.connect(host='127.0.0.1', user='******', passwd='fdsa')
示例#15
0
    def setUp(self):
        self.connections = []

        for params in self.databases:
            self.connections.append(umysqldb.connect(**params))
示例#16
0
    def setUp(self):
        self.connections = []

        for params in self.databases:
            self.connections.append(umysqldb.connect(**params))