]> git.joonet.de Git - adminer.git/commitdiff
Support for virtual foreign keys
authorJakub Vrana <jakub@vrana.cz>
Fri, 29 Oct 2010 11:58:08 +0000 (13:58 +0200)
committerJakub Vrana <jakub@vrana.cz>
Fri, 29 Oct 2010 12:01:19 +0000 (14:01 +0200)
adminer/include/adminer.inc.php
adminer/include/functions.inc.php
adminer/schema.inc.php
changes.txt
editor/include/adminer.inc.php

index 9181d3118109f34b0ac3fdb78c578172f4196d17..7e183a7115ec4ebf06e3e86c7567e32a60353d6b 100644 (file)
@@ -108,6 +108,14 @@ document.getElementById('username').focus();
                echo "\n";
        }
        
+       /** Get foreign keys for table
+       * @param string
+       * @return array same format as foreign_keys()
+       */
+       function foreignKeys($table) {
+               return foreign_keys($table);
+       }
+       
        /** Find backward keys for table
        * @param string
        * @param string
index 489108f26588582131cf9ea3e9cdbd68fabe92d9..1d9c186086ddab6937e48ffab18ed870a6e3d3d1 100644 (file)
@@ -550,8 +550,9 @@ function hidden_fields_get() {
 * @return array array($col => array())
 */
 function column_foreign_keys($table) {
+       global $adminer;
        $return = array();
-       foreach (foreign_keys($table) as $foreign_key) {
+       foreach ($adminer->foreignKeys($table) as $foreign_key) {
                foreach ($foreign_key["source"] as $val) {
                        $return[$val][] = $foreign_key;
                }
index 6410ffe8259dbaa21cb9465b9f3233ffd5b71764..1a7e0576e7af26a399970720f2b18069a7cd27ab 100644 (file)
@@ -27,23 +27,21 @@ foreach (table_status() as $row) {
                $schema[$row["Name"]]["fields"][$name] = $field;
        }
        $schema[$row["Name"]]["pos"] = ($table_pos[$row["Name"]] ? $table_pos[$row["Name"]] : array($top, 0));
-       if (fk_support($row)) {
-               foreach (foreign_keys($row["Name"]) as $val) {
-                       if (!$val["db"]) {
-                               $left = $base_left;
-                               if ($table_pos[$row["Name"]][1] || $table_pos[$val["table"]][1]) {
-                                       $left = min(floatval($table_pos[$row["Name"]][1]), floatval($table_pos[$val["table"]][1])) - 1;
-                               } else {
-                                       $base_left -= .1;
-                               }
-                               while ($lefts[(string) $left]) {
-                                       // find free $left
-                                       $left -= .0001;
-                               }
-                               $schema[$row["Name"]]["references"][$val["table"]][(string) $left] = array($val["source"], $val["target"]);
-                               $referenced[$val["table"]][$row["Name"]][(string) $left] = $val["target"];
-                               $lefts[(string) $left] = true;
+       foreach ($adminer->foreignKeys($row["Name"]) as $val) {
+               if (!$val["db"]) {
+                       $left = $base_left;
+                       if ($table_pos[$row["Name"]][1] || $table_pos[$val["table"]][1]) {
+                               $left = min(floatval($table_pos[$row["Name"]][1]), floatval($table_pos[$val["table"]][1])) - 1;
+                       } else {
+                               $base_left -= .1;
                        }
+                       while ($lefts[(string) $left]) {
+                               // find free $left
+                               $left -= .0001;
+                       }
+                       $schema[$row["Name"]]["references"][$val["table"]][(string) $left] = array($val["source"], $val["target"]);
+                       $referenced[$val["table"]][$row["Name"]][(string) $left] = $val["target"];
+                       $lefts[(string) $left] = true;
                }
        }
        $top = max($top, $schema[$row["Name"]]["pos"][0] + 2.5 + $pos);
index 4cb4f24e3f522c098735569457a64e85686e4ef0..7b3dad974c9e7192a4f4397bb502a5a382e0f212 100644 (file)
@@ -4,6 +4,7 @@ Highlight and edit SQL command in processlist
 Disable XSS "protection" of IE8
 Timestamp in export
 Link to bookmark SQL command
+Support for virtual foreign keys
 Immunity against zend.ze1_compatibility_mode
 Fix last page with empty result set
 
index af6b47e1420dbdd03c336f5c0cbee164650cbbc5..0ebbb868ab82054f3fc97aecd1e11c5aa3df1cc0 100644 (file)
@@ -65,6 +65,10 @@ document.getElementById('username').focus();
                echo "<a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a>\n";
        }
        
+       function foreignKeys($table) {
+               return foreign_keys($table);
+       }
+       
        function backwardKeys($table, $tableName) {
                $return = array();
                foreach (get_rows("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME