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 with warnings.catch_warnings(): warnings.simplefilter("ignore") yield c.execute("drop table if exists issue17") yield c.execute("create table issue17 (x varchar(32) primary key)") try: yield c.execute("insert into issue17 (x) values ('hello, world!')") yield c.execute( "grant all privileges on %s.issue17 to 'issue17user'@'%%' identified by '1234'" % db) yield conn.commit() conn2 = yield tmysql.connect(host=host, user="******", passwd="1234", db=db) c2 = conn2.cursor() yield c2.execute("select x from issue17") self.assertEqual("hello, world!", c2.fetchone()[0]) finally: yield c.execute("drop table issue17")
def test_example(self): conn = tmysql.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()
def test_issue_34(self): try: yield tmysql.connect(host="localhost", port=1237, user="******") self.fail() except tmysql.OperationalError as e: self.assertEqual(2003, e.args[0]) except Exception: self.fail()
def test_issue_6(self): """ exception: TypeError: ord() expected a character, but string of length 0 found """ # ToDo: this test requires access to db 'mysql'. kwargs = self.databases[0].copy() kwargs['db'] = "mysql" conn = yield tmysql.connect(**kwargs) c = conn.cursor() yield c.execute("select * from user") yield conn.close_async()
def test_issue_33(self): conn = yield tmysql.connect(charset="utf8", **self.databases[0]) c = conn.cursor() with warnings.catch_warnings(): warnings.simplefilter("ignore") yield c.execute(b"drop table if exists hei\xc3\x9fe".decode("utf8")) try: yield c.execute(b"create table hei\xc3\x9fe (name varchar(32))".decode("utf8")) yield c.execute(b"insert into hei\xc3\x9fe (name) values ('Pi\xc3\xb1ata')".decode("utf8")) yield c.execute(b"select name from hei\xc3\x9fe".decode("utf8")) self.assertEqual(b"Pi\xc3\xb1ata".decode("utf8"), c.fetchone()[0]) finally: yield c.execute(b"drop table hei\xc3\x9fe".decode("utf8"))
def test_issue_114(self): """ autocommit is not set after reconnecting with ping() """ conn = yield tmysql.connect(charset="utf8", **self.databases[0]) yield conn.autocommit(False) c = conn.cursor() yield c.execute("""select @@autocommit;""") self.assertFalse(c.fetchone()[0]) yield conn.close_async() yield conn.ping() yield c.execute("""select @@autocommit;""") self.assertFalse(c.fetchone()[0]) yield conn.close_async() # Ensure autocommit() is still working conn = yield tmysql.connect(charset="utf8", **self.databases[0]) c = conn.cursor() yield c.execute("""select @@autocommit;""") self.assertFalse(c.fetchone()[0]) yield conn.close_async() yield conn.ping() yield conn.autocommit(True) yield c.execute("""select @@autocommit;""") self.assertTrue(c.fetchone()[0]) yield conn.close_async()
def test_issue_33(self): conn = yield tmysql.connect(charset="utf8", **self.databases[0]) c = conn.cursor() with warnings.catch_warnings(): warnings.simplefilter("ignore") yield c.execute( b"drop table if exists hei\xc3\x9fe".decode("utf8")) try: yield c.execute( b"create table hei\xc3\x9fe (name varchar(32))".decode("utf8")) yield c.execute( b"insert into hei\xc3\x9fe (name) values ('Pi\xc3\xb1ata')". decode("utf8")) yield c.execute(b"select name from hei\xc3\x9fe".decode("utf8")) self.assertEqual(b"Pi\xc3\xb1ata".decode("utf8"), c.fetchone()[0]) finally: yield c.execute(b"drop table hei\xc3\x9fe".decode("utf8"))
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 with warnings.catch_warnings(): warnings.simplefilter("ignore") yield c.execute("drop table if exists issue17") yield c.execute("create table issue17 (x varchar(32) primary key)") try: yield c.execute("insert into issue17 (x) values ('hello, world!')") yield c.execute("grant all privileges on %s.issue17 to 'issue17user'@'%%' identified by '1234'" % db) yield conn.commit() conn2 = yield tmysql.connect(host=host, user="******", passwd="1234", db=db) c2 = conn2.cursor() yield c2.execute("select x from issue17") self.assertEqual("hello, world!", c2.fetchone()[0]) finally: yield c.execute("drop table issue17")
def _get_conn(self): now = self.io_loop.time() # Try to reuse in free pool while self._free_conn: conn = self._free_conn.popleft() if now - conn.connected_time > self.max_recycle_sec: self._close_async(conn) continue log.debug("Reusing connection from pool: %s", self.stat()) fut = Future() fut.set_result(conn) return fut # Open new connection if self.max_open == 0 or self._opened_conns < self.max_open: self._opened_conns += 1 log.debug("Creating new connection: %s", self.stat()) return connect(**self.connect_kwargs) # Wait to other connection is released. fut = Future() self._waitings.append(fut) return fut
def _connect_all(self): for params in self.databases: conn = yield tmysql.connect(io_loop=self.io_loop, **params) self.connections.append(conn)
def test_utf8mb4(self): """This test requires MySQL >= 5.5""" arg = self.databases[0].copy() arg['charset'] = 'utf8mb4' conn = yield tmysql.connect(**arg)