Bug #68971 mysql_fetch_fields returns the view name instead of the table name in org_table
Submitted: 16 Apr 2013 10:45 Modified: 25 Apr 2013 18:26
Reporter: Jean-Pierre Vansimpsen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.5.30, 5.0.97, 5.1.70, 5.5.32, 5.6.12, 5.7.2 OS:Microsoft Windows (XP 32bits)
Assigned to: CPU Architecture:Any

[16 Apr 2013 10:45] Jean-Pierre Vansimpsen
Description:
In the MYSQL_FIELD, if the column is selected from a view, the org_table does not always contain the underlying table name, but it contains the view name.

How to repeat:
For instance, in the Sakila DB provided with the Installer, the customer_list view and the staff_list view both give the view name instead of the table name.
[16 Apr 2013 12:51] Sveta Smirnova
Thank you for the report.

This is not a bug: view is designed not only for purpose of making writing queries more fast, but also to such security aspect as hiding underlying tables. So this is expected that MYSQL_FIELD returns information about view, but not about underlying tables.
[18 Apr 2013 10:34] Jean-Pierre Vansimpsen
Thanks for the answer.

But, this is what I found in the manual (chapter 22 - page 3073) :

• char * org_table
The name of the table, as a null-terminated string. Aliases are ignored.

If the column is selected from a view, org_table names the underlying table.

For a UNION, the value is the empty string. For a
procedure parameter, the procedure name.

Now, if I use the 'actor_info' view on the same sakila DB, the field contains the table name 'actor' and not the view name.
Same remark for film_list view, nicer_but_slower_film_list view and sales_by_film_category in the same DB.
Then, may be this is where the bug is ?
Would be also interesting to correct the manual ?
Regards.
[23 Apr 2013 19:51] Sveta Smirnova
Thank you for the feedback.

Indeed http://dev.mysql.com/doc/refman/5.5/en/c-api-data-structures.html says:

 char * org_table

The name of the table, as a null-terminated string. Aliases are ignored. If the column is selected from a view, org_table names the underlying table. For a UNION, the value is the empty string. For a procedure parameter, the procedure name. 

In my opinion this is still documentation bug, but this must be fixed.
[23 Apr 2013 19:51] Sveta Smirnova
test case

Attachment: bug68971.c (text/plain), 628 bytes.

[25 Apr 2013 18:26] Paul Dubois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

Revised text:

The name of the table, as a null-terminated string. Aliases are
ignored. If the column is selected from a view, org_table names the
view. For a UNION, the value is the empty string. For a procedure
parameter, the procedure name.