Menu

How to obtain table names of result fields

Help
2001-07-17
2012-09-19
  • Dirk Holtwick

    Dirk Holtwick - 2001-07-17

    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

     
    • Andy Dustman

      Andy Dustman - 2001-07-17

      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".

       
      • Dirk Holtwick

        Dirk Holtwick - 2001-07-17

        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>".

         
        • Andy Dustman

          Andy Dustman - 2001-07-17

          Why do you need it?

           
          • Dirk Holtwick

            Dirk Holtwick - 2001-07-17

            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 ;-)

             
            • Andy Dustman

              Andy Dustman - 2001-07-17

              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.

               

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.