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