home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / inno2pma.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2003-11-18  |  1.7 KB  |  56 lines

  1. #!/bin/sh
  2. #
  3. # inno2pma
  4. #
  5. # insert InnoDB foreign keys into phpmyadmin relation table
  6. # by Ernie Hershey 3/15/2003
  7. #
  8. # THIS IS AN EXPERIMENTAL SCRIPT - PLEASE DO NOT USE THIS
  9. # IF YOU DON'T UNDERSTAND WHAT IT IS DOING!
  10. #
  11. # This was posted on the Open Discussion forum by
  12. # ehershey. The idea is interesting, however we should
  13. # implement it in PHP.
  14. #
  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.
  19. #
  20. # requires :
  21. # mysql client tools
  22. # standard unix shell tools
  23. # special PHPMyAdmin relation table setup
  24. #
  25. #
  26.  
  27. # config
  28.  
  29. database="triohost2"
  30. #table="domains"
  31. relationdb="phpmyadmin"
  32. relationtable="PMA_relation"
  33.  
  34. # end config
  35.  
  36. mysqldump --no-data $database $table | egrep "^CREATE|^ FOREIGN" | while read line
  37. do
  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
  44.       ;;
  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\\\``
  51.  
  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
  54.       ;;
  55.  esac
  56. done