Tracker: Bugs

1 (in 2.6.0) error in search mode with foreign key - ID: 983992
Last Update: Settings changed ( rabus )

phpMyAdmin 2.5.7-pl1
MySQL 4.0.20-log running on localhost

I create to tables in two different databases:

test:
CREATE TABLE `test` (
`EMPLOYEE_ID` int(11) NOT NULL default '0',
KEY `EMPLOYEE_ID` (`EMPLOYEE_ID`)
) TYPE=InnoDB;

human_resources:
CREATE TABLE `employee` (
`EMPLOYEE_ID` int(11) NOT NULL auto_increment,
PRIMARY KEY (`EMPLOYEE_ID`),
) TYPE=InnoDB;

and create reference:
ALTER TABLE test.test ADD FOREIGN KEY
(EMPLOYEE_ID) REFERENCES
human_resources.employee(EMPLOYEE_ID)

in search mode on table test.test got error on field
employee_id (print screen in attached file)

SQL-query :
SHOW TABLE STATUS FROM `test` LIKE 'employee'
MySQL said:
#1146 - Table 'test.employee' doesn't exist


Ilya Aniskovets ( aig ) - 2004-07-02 11:20

1

Closed

Fixed

Marc Delisle

None

2.5.7

Public


Comments ( 15 )

Date: 2004-07-05 14:56
Sender: lem9Project Admin & DonorAccepting Donations

Logged In: YES
user_id=210714

fixed in cvs for 2.6.0, thanks.


Date: 2004-07-02 18:17
Sender: lem9Project Admin & DonorAccepting Donations

Logged In: YES
user_id=210714

OK, tried 4.0.18 and 4.0.20 and they report
`human_resources`.`employee` (`EMPLOYEE_ID`).
I will code a general fix for this.


Date: 2004-07-02 17:07
Sender: aig

Logged In: YES
user_id=218271

CREATE TABLE `test` (
`EMPLOYEE_ID` int(11) NOT NULL default '0',
KEY `EMPLOYEE_ID` (`EMPLOYEE_ID`),
CONSTRAINT `test_ibfk_1` FOREIGN KEY
(`EMPLOYEE_ID`) REFERENCES
`human_resources`.`employee` (`EMPLOYEE_ID`)
) TYPE=InnoDB


Date: 2004-07-02 17:05
Sender: lem9Project Admin & DonorAccepting Donations

Logged In: YES
user_id=210714

Ok, I am not running 4.0.20 for the moment. On my 4.0.16
system, it reports only one identifier
`human_resources.employee`
enclosed by backticks:
CREATE TABLE `test` (
`EMPLOYEE_ID` int(11) NOT NULL default '0',
KEY `EMPLOYEE_ID` (`EMPLOYEE_ID`),
CONSTRAINT `0_982` FOREIGN KEY (`EMPLOYEE_ID`) REFERENCES
`human_resources.employee` (`EMPLOYEE_ID`)
) TYPE=InnoDB

Just to confirm, can you show me the output of SHOW CREATE
TABLE test; I guess we will have to support both possibilities.


Date: 2004-07-02 16:28
Sender: aig

Logged In: YES
user_id=218271

explode wold fail because function PMA_SQP_parse
splits 'human_resources.employee' to three arrays:
[31] => Array ( [type] => quote_backtick [data] =>
`human_resources` )
[32] => Array ( [type] => punct_qualifier
[data] => . )
[33] => Array ( [type] => quote_backtick [data]
=> `employee` )

but explode is applied to thirst one, second one, and third
separately.
explode('.',$identifier)
where $identifier = $arr[$i]['data']


Date: 2004-07-02 16:21
Sender: aig

Logged In: YES
user_id=218271

PHP Version 4.3.7


Date: 2004-07-02 16:21
Sender: aig

Logged In: YES
user_id=218271

trace (human_resources)
trace2 Array ( [0] => human_resources ) trace (employee)
trace2 Array ( [0] => employee )


Date: 2004-07-02 15:45
Sender: lem9Project Admin & DonorAccepting Donations

Logged In: YES
user_id=210714

I cannot understand why current code (explode) would fail,
please trace this in sqlparser.lib.php (also, which PHP
version are you running?)
if ($seen_references) {
$identifier =
str_replace('`','',$arr[$i]['data']);
if ($in_bracket) {

$foreign[$foreign_key_number]['ref_index_list'][] = $identifier;
} else {
// identifier can be table or db.table
echo "trace (" . $identifier . ")<br>";
$db_table = explode('.',$identifier);
echo "trace2 ";
print_r($db_table);
if (isset($db_table[1])) {

$foreign[$foreign_key_number]['ref_db_name'] = $db_table[0];

$foreign[$foreign_key_number]['ref_table_name'] = $db_table[1];
} else {

$foreign[$foreign_key_number]['ref_table_name'] = $db_table[0];
}



Date: 2004-07-02 15:29
Sender: aig

Logged In: YES
user_id=218271

i fix this bug :)
in file 'sqlparser.lib.php' at line 1497:
if ($seen_references) {
$identifier = str_replace('`','',$arr[$i]['data']);
if ($in_bracket) {
$foreign[$foreign_key_number]['ref_index_list'][] =
$identifier;
} else {
// identifier can be table or db.table
if (isset($arr[$i+1]['data']) && $arr[$i+1]['data'] == ".") {
$foreign[$foreign_key_number]['ref_db_name'] = $identifier;
} else {
$foreign[$foreign_key_number]['ref_table_name'] =
$identifier;
}
}
}



Date: 2004-07-02 14:53
Sender: aig

Logged In: YES
user_id=218271

My further researches have shown that the information on
base human_resources is eaten with function
PMA_SQP_analyze as after performance PMA_SQP_parse
($show_create_table) the information still remains, however
after performance PMA_SQP_analyze she vanishes:

after PMA_SQP_parse:
Array ( [raw] => CREATE TABLE `test` ( `EMPLOYEE_ID` int
(11) NOT NULL default '0', KEY `EMPLOYEE_ID`
(`EMPLOYEE_ID`), CONSTRAINT `test_ibfk_1` FOREIGN
KEY (`EMPLOYEE_ID`) REFERENCES
`human_resources`.`employee` (`EMPLOYEE_ID`) )
TYPE=InnoDB [0] => Array ( [type] => alpha_reservedWord
[data] => CREATE ) [1] => Array ( [type] =>
alpha_reservedWord [data] => TABLE ) [2] => Array ( [type]
=> quote_backtick [data] => `test` ) [3] => Array ( [type] =>
punct_bracket_open_round [data] => ( ) [4] => Array ( [type]
=> white_newline [data] => ) [5] => Array ( [type] =>
quote_backtick [data] => `EMPLOYEE_ID` ) [6] => Array (
[type] => alpha_columnType [data] => int ) [7] => Array (
[type] => punct_bracket_open_round [data] => ( ) [8] =>
Array ( [type] => digit_integer [data] => 11 ) [9] => Array (
[type] => punct_bracket_close_round [data] => ) ) [10] =>
Array ( [type] => alpha_reservedWord [data] => NOT ) [11]
=> Array ( [type] => alpha_reservedWord [data] => NULL )
[12] => Array ( [type] => alpha_columnAttrib [data] =>
default ) [13] => Array ( [type] => quote_single [data] => '0' )
[14] => Array ( [type] => punct_listsep [data] => , ) [15] =>
Array ( [type] => white_newline [data] => ) [16] => Array (
[type] => alpha_reservedWord [data] => KEY ) [17] => Array
( [type] => quote_backtick [data] => `EMPLOYEE_ID` ) [18]
=> Array ( [type] => punct_bracket_open_round [data] => ( )
[19] => Array ( [type] => quote_backtick [data] =>
`EMPLOYEE_ID` ) [20] => Array ( [type] =>
punct_bracket_close_round [data] => ) ) [21] => Array (
[type] => punct_listsep [data] => , ) [22] => Array ( [type] =>
white_newline [data] => ) [23] => Array ( [type] =>
alpha_reservedWord [data] => CONSTRAINT ) [24] => Array
( [type] => quote_backtick [data] => `test_ibfk_1` ) [25] =>
Array ( [type] => alpha_reservedWord [data] => FOREIGN )
[26] => Array ( [type] => alpha_reservedWord [data] =>
KEY ) [27] => Array ( [type] => punct_bracket_open_round
[data] => ( ) [28] => Array ( [type] => quote_backtick [data]
=> `EMPLOYEE_ID` ) [29] => Array ( [type] =>
punct_bracket_close_round [data] => ) ) [30] => Array (
[type] => alpha_reservedWord [data] => REFERENCES )
[31] => Array ( [type] => quote_backtick [data] =>
`human_resources` ) [32] => Array ( [type] => punct_qualifier
[data] => . ) [33] => Array ( [type] => quote_backtick [data]
=> `employee` ) [34] => Array ( [type] =>
punct_bracket_open_round [data] => ( ) [35] => Array (
[type] => quote_backtick [data] => `EMPLOYEE_ID` ) [36]
=> Array ( [type] => punct_bracket_close_round [data] => ) )
[37] => Array ( [type] => white_newline [data] => ) [38] =>
Array ( [type] => punct_bracket_close_round [data] => ) )
[39] => Array ( [type] => alpha_reservedWord [data] =>
TYPE ) [40] => Array ( [type] => punct [data] => = ) [41] =>
Array ( [type] => alpha_columnAttrib [data] => InnoDB ) [len]
=> 42 )

after PMA_SQP_analyze:
Array ( [0] => Array ( [querytype] => CREATE
[select_expr_clause] => [position_of_first_select] =>
[from_clause] => [group_by_clause] => [order_by_clause]
=> [having_clause] => [where_clause] =>
[where_clause_identifiers] => Array ( ) [queryflags] => Array
( ) [select_expr] => Array ( ) [table_ref] => Array ( )
[foreign_keys] => Array ( [0] => Array ( [constraint] =>
test_ibfk_1 [index_list] => Array ( [0] => EMPLOYEE_ID )
[ref_table_name] => employee [ref_index_list] => Array ( [0]
=> EMPLOYEE_ID ) ) ) ) )


Date: 2004-07-02 14:52
Sender: aig

Logged In: YES
user_id=218271

Array ( [constraint] => test_ibfk_1 [index_list] => Array ( [0]
=> EMPLOYEE_ID ) [ref_table_name] => employee
[ref_index_list] => Array ( [0] => EMPLOYEE_ID ) )
Array ( [EMPLOYEE_ID] => Array ( [constraint] =>
test_ibfk_1 [foreign_db] => test [foreign_table] => employee
[foreign_field] => EMPLOYEE_ID ) )


Date: 2004-07-02 14:42
Sender: lem9Project Admin & DonorAccepting Donations

Logged In: YES
user_id=210714

Ok, now in libraries/relation.lib.php, line 339, add a print_r:

if (isset($foreign) && is_array($foreign)) {
print_r($foreign);
return $foreign;
} else {
return FALSE;
}

and line 311:
foreach($analyzed_sql[0]['foreign_keys'] AS $one_key) {
print_r($one_key);
echo "<br>";




Date: 2004-07-02 14:37
Sender: aig

Logged In: YES
user_id=218271

Similarly the mistake in function PMA_getForeigners. As she
generates a wrong name of the database (test insteed
human_resources).
I insert command 'printf($foreigners);' after line 90 in
file 'tbl_select.php':

Array ( [EMPLOYEE_ID] => Array ( [constraint] =>
test_ibfk_1 [foreign_db] => test [foreign_table] => employee
[foreign_field] => EMPLOYEE_ID ) )


Date: 2004-07-02 14:15
Sender: aig

Logged In: YES
user_id=218271

trace test employee
Error

SQL-query :

SHOW TABLE STATUS FROM `test` LIKE 'employee'

MySQL said:


#1146 - Table 'test.employee' doesn't exist

[Documentation] · [Back]


Date: 2004-07-02 13:28
Sender: lem9Project Admin & DonorAccepting Donations

Logged In: YES
user_id=210714

Tried to reproduce this bug, could not. Please do some
tracing for me. In libraries/get_foreign.lib.php, add 2
lines around line 28:

echo "trace $foreign_db $foreign_table ";
$the_total = PMA_countRecords($foreign_db,
$foreign_table, TRUE);
echo "trace after";



Attached Files ( 2 )

Filename Description Download
error.PNG Table 'test.employee' doesn't exist error Download
error_trace.PNG traced error Download

Changes ( 8 )

Field Old Value Date By
status_id Open 2004-09-27 18:47 rabus
close_date - 2004-09-27 18:47 rabus
priority 5 2004-07-05 14:56 lem9
resolution_id None 2004-07-05 14:56 lem9
summary error in search mode with foreign key references 2004-07-05 14:56 lem9
File Added 92661: error_trace.PNG 2004-07-02 14:15 aig
assigned_to nobody 2004-07-02 12:48 lem9
File Added 92638: error.PNG 2004-07-02 11:20 aig