Search code examples
pythonmysqlpython-stacklesspython-db-api

MySQL driver issues with INFORMATION_SCHEMA?


I'm trying out the Concurrence framework for Stackless Python. It includes a MySQL driver and when running some code that previously ran fine with MySQLdb it fails.

What I am doing:

  1. Connecting to the MySQL database using dbapi with username/password/port/database.

  2. Executing SELECT * FROM INFORMATION_SCHEMA.COLUMNS

This fails with message:

Table 'mydatabase.columns' doesn't exist

"mydatabase" is the database I specified in step 1.

When doing the same query in the MySQL console after issuing "USE mydatabase", it works perfectly.

Checking the network communication yields something like this:

>>>myusername
>>>scrambled password
>>>mydatabase

>>>CMD 3 SET AUTOCOMMIT = 0
<<<0

>>>CMD 3 SELECT * FROM INFORMATION_SCHEMA.COLUMNS
<<<255
<<<Table 'mydatabase.columns' doesn't exist

Is this a driver issue (since it works in MySQLdb)? Or am I not supposed to be able to query INFORMATION_SCHEMA this way?

If I send a specific "USE INFORMATION_SCHEMA" before trying to query it, I get the expected result. But, I do not want to have to sprinkle my code all over with "USE" queries.


Solution

  • I finally found the reason.

    The driver just echoed the server capability flags back in the protocol handshake, with the exception of compression:

    ## concurrence/database/mysql/client.py ##
    
    client_caps = server_caps 
    
    #always turn off compression
    client_caps &= ~CAPS.COMPRESS
    

    As the server has the capability...

    CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */

    ...that was echoed back to the server, telling it not to allow that syntax.

    Adding client_caps &= ~CAPS.NO_SCHEMA did the trick.