Ejemplo n.º 1
0
    def test_change_user(self):
        if is_skysql():
            self.skipTest("SkySQL failure")
        if self.connection.server_version < 100103:
            self.skipTest("CREATE OR REPLACE USER not supported")
        if is_maxscale():
            self.skipTest("MAXSCALE doesn't get new user immediately")
        if self.connection.server_name == "localhost":
            curs = self.connection.cursor(buffered=True)
            curs.execute(
                "select * from information_schema.plugins where plugin_name='unix_socket' and plugin_status='ACTIVE'"
            )
            if curs.rowcount > 0:
                del curs
                self.skipTest("unix_socket is active")
            del curs

        default_conf = conf()
        cursor = self.connection.cursor()
        cursor.execute("drop user if exists foo")
        if is_mysql() and self.connection.server_version < 80000:
            cursor.execute("create user foo@'%'")
            cursor.execute("GRANT ALL on `" + default_conf["database"] +
                           "`.* TO foo@'%' IDENTIFIED BY 'heyPassw-!µ20§rd'")
        else:
            cursor.execute(
                "create user foo@'%' IDENTIFIED BY 'heyPassw-!µ20§rd'")
            cursor.execute("GRANT ALL on `" + default_conf["database"] +
                           "`.* TO foo@'%'")
        new_conn = create_connection()
        new_conn.change_user("foo", "heyPassw-!µ20§rd", "")
        self.assertEqual("foo", new_conn.user)
        cursor.execute("drop user foo")
        del new_conn
        del cursor
Ejemplo n.º 2
0
 def test_xfield_types(self):
     cursor = self.connection.cursor()
     fieldinfo = mariadb.fieldinfo()
     cursor.execute(
         "CREATE TEMPORARY TABLE test_xfield_types (a tinyint not null auto_increment primary "
         "key, b smallint, c int, d bigint, e float, f decimal, g double, h char(10), i varchar(255), j blob, k json, index(b))"
     )
     info = cursor.description
     self.assertEqual(info, None)
     cursor.execute("SELECT * FROM test_xfield_types")
     info = cursor.description
     self.assertEqual(fieldinfo.type(info[0]), "TINY")
     self.assertEqual(fieldinfo.type(info[1]), "SHORT")
     self.assertEqual(fieldinfo.type(info[2]), "LONG")
     self.assertEqual(fieldinfo.type(info[3]), "LONGLONG")
     self.assertEqual(fieldinfo.type(info[4]), "FLOAT")
     self.assertEqual(fieldinfo.type(info[5]), "NEWDECIMAL")
     self.assertEqual(fieldinfo.type(info[6]), "DOUBLE")
     self.assertEqual(fieldinfo.type(info[7]), "STRING")
     self.assertEqual(fieldinfo.type(info[8]), "VAR_STRING")
     self.assertEqual(fieldinfo.type(info[9]), "BLOB")
     if not is_maxscale() and (self.connection.server_version_info >
                               (10, 5, 1) or is_mysql()):
         self.assertEqual(fieldinfo.type(info[10]), "JSON")
     else:
         self.assertEqual(fieldinfo.type(info[10]), "BLOB")
     self.assertEqual(fieldinfo.flag(info[0]),
                      "NOT_NULL | PRIMARY_KEY | AUTO_INCREMENT | NUMERIC")
     self.assertEqual(fieldinfo.flag(info[1]), "PART_KEY | NUMERIC")
     self.assertEqual(fieldinfo.flag(info[9]), "BLOB | BINARY")
     del cursor
Ejemplo n.º 3
0
 def test_conpy27(self):
     if is_mysql():
         self.skipTest("Skip (MySQL)")
     con = create_connection()
     cursor = con.cursor(prepared=True)
     cursor.execute("SELECT ?", (1, ))
     row = cursor.fetchone()
     self.assertEqual(row[0], 1)
     cursor.execute("SELECT ?, ?, ?", ('foo', ))
     row = cursor.fetchone()
     self.assertEqual(row[0], 'foo')
     del cursor, con
Ejemplo n.º 4
0
 def test_conpy42(self):
     if is_mysql():
         self.skipTest("Skip (MySQL)")
     con = create_connection()
     cursor = con.cursor()
     cursor.execute("CREATE TEMPORARY TABLE conpy42(a GEOMETRY)")
     cursor.execute(
         "INSERT INTO conpy42 VALUES (PointFromText('point(1 1)'))")
     cursor.execute("SELECT a FROM conpy42")
     row = cursor.fetchone()
     self.assertEqual(
         row[0],
         b'\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?'
     )
     del cursor
Ejemplo n.º 5
0
 def test_conpy150(self):
     if is_mysql():
         self.skipTest("Skip (MySQL)")
     connection = create_connection()
     cursor = connection.cursor()
     cursor.execute(
         "create temporary table t1 (id int, a datetime not null default '0000-00-00 00:00:00', b date not null default '0000-00-00')"
     )
     cursor.execute("insert into t1 (id) values (1)")
     cursor.execute("select * from t1")
     row = cursor.fetchone()
     self.assertEqual(row[1], None)
     self.assertEqual(row[2], None)
     cursor.execute("select * from t1 WHERE 1=?", (1, ))
     row = cursor.fetchone()
     self.assertEqual(row[1], None)
     self.assertEqual(row[2], None)
     del cursor
     connection.close()
Ejemplo n.º 6
0
    def test_conpy133(self):
        if is_mysql():
            self.skipTest("Skip (MySQL)")
        conn = create_connection()

        cursor = conn.cursor()
        cursor.execute("SELECT /*! ? */", (1, ))
        row = cursor.fetchone()
        self.assertEqual(row[0], 1)
        del cursor

        cursor = conn.cursor()
        cursor.execute("SELECT /*M! ? */", (1, ))
        row = cursor.fetchone()
        self.assertEqual(row[0], 1)
        del cursor

        cursor = conn.cursor()
        cursor.execute("SELECT /*M!50601 ? */", (1, ))
        row = cursor.fetchone()
        self.assertEqual(row[0], 1)
        del cursor

        cursor = conn.cursor()
        cursor.execute("SELECT /*!40301 ? */", (1, ))
        row = cursor.fetchone()
        self.assertEqual(row[0], 1)
        del cursor

        cursor = conn.cursor()
        try:
            cursor.execute("SELECT /*!50701 ? */", (1, ))
        except mariadb.DataError:
            pass
        del cursor

        cursor = conn.cursor()
        try:
            cursor.execute("SELECT /*!250701 ? */", (1, ))
        except mariadb.DataError:
            pass
        del cursor