Example #1
0
    def test_example(self):
        conn = pymysql.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()
Example #2
0
    def setUp(self):
        try:
            self.connections = []

            for params in self.databases:
                self.connections.append(pymysql.connect(**params))
        except pymysql.err.OperationalError as e:
            self.skipTest("Cannot connect to MySQL - skipping pymysql tests because of (%s) %s" % (type(e), e))
Example #3
0
 def test_issue_6(self):
     """ exception: TypeError: ord() expected a character, but string of length 0 found """
     conn = pymysql.connect(host="localhost",
                            user="******",
                            passwd="",
                            db="mysql")
     c = conn.cursor()
     c.execute("select * from user")
     conn.close()
Example #4
0
 def test_issue_33(self):
     conn = pymysql.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"))
Example #5
0
    def setUp(self):
        try:
            self.connections = []

            for params in self.databases:
                self.connections.append(pymysql.connect(**params))
        except pymysql.err.OperationalError as e:
            self.skipTest(
                'Cannot connect to MySQL - skipping pymysql tests because of (%s) %s'
                % (type(e), e))
Example #6
0
 def test_issue_33(self):
     conn = pymysql.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"))
Example #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 = pymysql.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")
Example #8
0
    def test_example(self):
        conn = pymysql.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()
Example #9
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 = pymysql.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")
Example #10
0
 def test_issue_34(self):
     try:
         pymysql.connect(host="localhost", port=1237, user="******")
         self.fail()
     except pymysql.OperationalError, e:
         self.assertEqual(2003, e.args[0])
Example #11
0
 def test_issue_6(self):
     """ exception: TypeError: ord() expected a character, but string of length 0 found """
     conn = pymysql.connect(host="localhost",user="******",passwd="",db="mysql")
     c = conn.cursor()
     c.execute("select * from user")
     conn.close()
Example #12
0
 def test_issue_34(self):
     try:
         pymysql.connect(host="localhost", port=1237, user="******")
         self.fail()
     except pymysql.OperationalError, e:
         self.assertEqual(2003, e.args[0])