Apparently the mysqldump was not acceptable for import.
[openemr.git] / interface / main / myadmin / scripts / inno2pma.sh
blob17a599da61a3e982476ff0d077a656e0000f6234
1 #!/bin/sh
3 # inno2pma
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.
20 # requires :
21 # mysql client tools
22 # standard unix shell tools
23 # special PHPMyAdmin relation table setup
27 # config
29 database="triohost2"
30 #table="domains"
31 relationdb="phpmyadmin"
32 relationtable="PMA_relation"
34 # end config
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" "`
40 case $first_token in
41 CREATE)
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
45 FOREIGN)
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
55 esac
56 done