5 # insert InnoDB foreign keys into phpmyadmin relation table
6 # by Ernie Hershey 3/15/2003
8 # THIS IS AN EXPERIMENTAL SCRIPT - PLEASE DO NOT USE THIS
9 # IF YOU DON'T UNDERSTAND WHAT IT IS DOING!
11 # This was posted on the Open Discussion forum by
12 # ehershey. The idea is interesting, however we should
13 # implement it in PHP.
15 # In future versions of phpMyAdmin the use of a proprietary
16 # storage of relational tables will be discarded in favor of
17 # the InnoDB relations (or in addition to). Support of InnoDB
18 # relations is on our ToDo-List.
22 # standard unix shell tools
23 # special PHPMyAdmin relation table setup
31 relationdb
="phpmyadmin"
32 relationtable
="PMA_relation"
36 mysqldump
--no-data $database $table |
egrep "^CREATE|^ FOREIGN" |
while read line
38 line
=`echo "$line"|sed 's/^ *//g`
39 first_token
=`echo "$line" | cut -f1 -d" "`
42 table_name
=`echo "$line"|sed 's/CREATE TABLE \(.*\) (/\1/'`
43 echo "DELETE FROM $relationtable WHERE master_db='$database' AND master_table='$table_name'" | mysql
$relationdb
46 localcolumn
=`echo "$line" | cut -f2 -d\\\``
47 foreigntablefull=`echo "$line" | cut
-f4 -d\\\
``
48 foreigndb
=`echo $foreigntablefull | cut -f1 -d.`
49 foreigntable
=`echo $foreigntablefull | cut -f2 -d.`
50 foreigncolumn
=`echo "$line" | cut -f6 -d\\\``
52 echo processing foreign key on column $database.$table_name.$localcolumn to $foreigndb.$foreigntable.$foreigncolumn >&2
53 echo "INSERT INTO $relationtable VALUES ('$database','$table_name','$localcolumn','$foreigndb','$foreigntable','$foreigncolumn');" | mysql $relationdb