Search code examples
c++mariadbmariasql

Determine tables that takes a part in the query result?


I use libmariadb to communicate with mysql server.

  • mysql_real_query - to execute queries
  • mysql_store_result - to fetch result

Is there a way to figure out from MYSQL_RES (or else), what tables takes a part in the query result?

For example, for query

SELECT name, number FROM person INNER JOIN phone ON ...

I want discover which fields come from the table 'person' and which from 'phone'.

PS:

  1. using aliases in the query is not a solution.
  2. postgres API has this functionality through function PQftable, so I hope that MariaDB (MySQL) too.

Solution

  • To retrieve information about tables for particular fields in the result need to use function:

    mysql_fetch_field()
    

    And get string org_table from MYSQL_FIELD.