Bug #3833 Query Window's default_table corrupted
Submitted: 20 May 2004 4:14 Modified: 1 Jun 2004 0:43
Reporter: Jonah Tsai Email Updates:
Status: Closed Impact on me:
None 
Category:MySQLCC Severity:S2 (Serious)
Version:0.94beta OS:Any (all)
Assigned to: Bugs System CPU Architecture:Any

[20 May 2004 4:14] Jonah Tsai
Description:
Using MySQLCC against MySQL server v.5+, in the QueryWindow after a SELECT query is executed, the default table name gets corrupted.

For instance, the next query/insert whatever will all get something like this:
"SELECT * FROM test.1;"

Table test.1, of course, does not exist, and it should have been test.<previous table used>.

If you so happen to have a table named "1", you are in for some nasty surprises!!!

The root of the problem is at CQueryWindow.cpp:470.
"default_table = explain_query->row(mysql()->mysql()->version().major >= 4 && 
              mysql()->mysql()->version().minor >= 1 ? 2 : 0);"

The above line was in the "Explain" section of the code. After each SELECT query, an "EXPLAIN <last query>" is executed automatically. So, after the explain, the default_table is changed to either column "0" or "2" of the explain result, depending on the version of the server. The above code obviously is incorrect b/c it deals with only major verion 4 and below. It should have been:
....(major > 4 || (major == 4 && minor >= 1) ? 2 : 0); // shorten for clarity

How to repeat:
1. Connect MySQLCC to a v.5 MySQL DB.
2. Open any table by right click on the table and select "Open Table/Return all rows"
3. You will see immediately that an error message similar to the following.
"[Localhost] ERROR 1146: Table 'test.1' doesn't exist"

4. Switch to the explain tab, and you will see the first colume has the value "1".
This "1" is used to set as the default_table.

Suggested fix:
I hate long winded and convoluted code, but I will go along here.
Change CQueryWindow.cpp:470 to
default_table = explain_query->row( (mysql()->mysql()->version().major > 4
                                       || (mysql()->mysql()->version().major == 4
                                             && mysql()->mysql()->version().minor >=1)) ? 2 : 0);
[1 Jun 2004 0:43] Jorge del Conde
Hi!

MySQLCC has been discontinued and will not be developed nor maintained anymore with the exception of Critical bugs.

In the near future we will release the substitute of MySQLCC called MySQL Query Browser.