MySQL in it's standard API offers a way to obtain the table name of a result, e.g. you have a query like that: "select * from a, b where ..." then you get results from the table "a" and "b". The method describe() returns just the field names. I patched this method sometimes in the C code to add to the returned tuples also the tablename, that I need to simulate my own fetchDict() method. Is there another way to do this or could we patch describe() or add something like get_fields().
Bye, Dirk
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Couldn't we implement describe2() for instance? MySQLdb.cursors.CursorOldDictRowsMixIn doesn't work for me, because it returns just names like "<table>.<field>" I think, and then I have to parse the field parts. I need both modes for my DB application, that means keys like "<table>.<field>" and "<field>".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We have written an application server that uses your MySQLdb. This server was first build on the old Python interface to MySQL and uses the features of fetchDict(). In a newer version we try to be compatible with the DB API 2.0 but our old appserver is still in use.
I thought a little change in MySQLdb to get these informations would be a good idea, because it is a special feature of MySQL that offers these possibilities and since MySQLdb remained the last direct MySQL interface for Python it should be complete.
But I may also patch your version for my private needs, so it works. An official implementation in MySQLdb would have been more elegant ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
CursorOldDictRowsMixIn makes the cursor work like cursors from the old Mysqldb/MySQLmodule, except they only return dictionaries. Also see the included CompatMysqldb module, which is the original Mysqldb adapted to use _mysql.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MySQL in it's standard API offers a way to obtain the table name of a result, e.g. you have a query like that: "select * from a, b where ..." then you get results from the table "a" and "b". The method describe() returns just the field names. I patched this method sometimes in the C code to add to the returned tuples also the tablename, that I need to simulate my own fetchDict() method. Is there another way to do this or could we patch describe() or add something like get_fields().
Bye, Dirk
We can't change what is returned by describe(), which is stored in cursor.description, without breaking compatibility with the Python DB API.
Try MySQLdb.cursors.CursorOldDictRowsMixIn. This sets the keys of the dictionaries to be "table.row".
Couldn't we implement describe2() for instance? MySQLdb.cursors.CursorOldDictRowsMixIn doesn't work for me, because it returns just names like "<table>.<field>" I think, and then I have to parse the field parts. I need both modes for my DB application, that means keys like "<table>.<field>" and "<field>".
Why do you need it?
We have written an application server that uses your MySQLdb. This server was first build on the old Python interface to MySQL and uses the features of fetchDict(). In a newer version we try to be compatible with the DB API 2.0 but our old appserver is still in use.
I thought a little change in MySQLdb to get these informations would be a good idea, because it is a special feature of MySQL that offers these possibilities and since MySQLdb remained the last direct MySQL interface for Python it should be complete.
But I may also patch your version for my private needs, so it works. An official implementation in MySQLdb would have been more elegant ;-)
CursorOldDictRowsMixIn makes the cursor work like cursors from the old Mysqldb/MySQLmodule, except they only return dictionaries. Also see the included CompatMysqldb module, which is the original Mysqldb adapted to use _mysql.