Enable autocomplete also for FK with quoted identifiers
authorsoranzo <soranzo>
Wed, 3 Jan 2007 15:35:42 +0000 (15:35 +0000)
committersoranzo <soranzo>
Wed, 3 Jan 2007 15:35:42 +0000 (15:35 +0000)
display.php
tables.php

index 9d55e5f9d8347c5c553d8f1bf8c0b1c4a59e9f71..38607fc198cc947e26f3cb84652b071527c8f788 100644 (file)
@@ -9,7 +9,7 @@
         * @param $return_desc The return link name
         * @param $page The current page
         *
-        * $Id: display.php,v 1.56 2007/01/02 19:04:27 soranzo Exp $
+        * $Id: display.php,v 1.57 2007/01/03 15:35:42 soranzo Exp $
         */
 
        // Prevent timeouts on large exports (non-safe mode only)
                        $misc->printTitle($lang['streditrow']);
                        $misc->printMsg($msg);
 
-                       $bAllowAC = ($conf["autocomplete"]!='disable') ? TRUE : FALSE ;
+                       $bAllowAC = ($conf['autocomplete'] != 'disable') ? TRUE : FALSE;
                        if($bAllowAC) {
                                $constraints = $data->getConstraints($_REQUEST['table']);
                                $arrayLocals = array();
                                $arrayRefs = array();
                                $nC = 0;
-                               // A word of caution, the following does not support multicolumn FK's at the moment
                                while(!$constraints->EOF) {
-                                       preg_match('/foreign key \((\w+)\) references ([\w]+)\((\w+)\)/i', $constraints->fields["consrc"], $matches);
+                                       // The following RE will match a FK constrain with a single (quoted or not) referencing column. At the moment we don't support multicolumn FKs
+                                       preg_match('/^FOREIGN KEY \(("[^"]*"|[^\s",]*)\) REFERENCES (.*)\((.*)\)/i', $constraints->fields['consrc'], $matches);
                                        if(!empty($matches)) {
-                                               $arrayLocals[$nC] = $matches[1];
-                                               $arrayRefs[$nC] = array($matches[2], $matches[3]);
+                                               // Strip possible quotes and save
+                                               $arrayLocals[$nC] = preg_replace('/"(.*)"/', '$1', $matches[1]);
+                                               $arrayRefs[$nC] = array(preg_replace('/"(.*)"/', '$1', $matches[2]), preg_replace('/"(.*)"/', '$1', $matches[3]));
                                                $nC++;
                                        }
                                        $constraints->moveNext();
                                $i = 0;
                                while (!$attrs->EOF) {
                                        $szValueName = "values[{$attrs->f['attname']}]";
-                                       $szEvents = "";
-                                       $szDivPH = "";
+                                       $szEvents = '';
+                                       $szDivPH = '';
                                        if($bAllowAC) {
                                                $idxFound = array_search($attrs->f['attname'], $arrayLocals);
                                                // In PHP < 4.2.0 array_search returns NULL on failure
                                                if ($idxFound !== NULL && $idxFound !== FALSE) {
-                                                       $szEvent = "makeAC('{$szValueName}',{$i},'{$arrayRefs[$idxFound][0]}','{$arrayRefs[$idxFound][1]}','{$_REQUEST["server"]}','{$_REQUEST["database"]}');";
+                                                       $szEvent = "makeAC('{$szValueName}',{$i},'{$arrayRefs[$idxFound][0]}','{$arrayRefs[$idxFound][1]}','{$_REQUEST['server']}','{$_REQUEST['database']}');";
                                                        $szEvents = "onfocus=\"{$szEvent}\" onblur=\"hideAC();document.getElementById('ac_form').onsubmit=function(){return true;};\" onchange=\"{$szEvent}\" id=\"{$szValueName}\" onkeyup=\"{$szEvent}\" autocomplete=\"off\" class='ac_field'";
                                                        $szDivPH = "<div id=\"fac{$i}_ph\"></div>";
                                                }
                        if (!$error) echo "<input type=\"submit\" name=\"save\" value=\"{$lang['strsave']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        if($bAllowAC) {
-                               $szChecked = $conf["autocomplete"]!='default off' ? "checked=\"checked\"" : "";
+                               $szChecked = $conf['autocomplete'] != 'default off' ? 'checked="checked"' : '';
                                echo "<input type=\"checkbox\" name=\"no_ac\" id=\"no_ac\" onclick=\"rEB(this.checked);\" value=\"1\" {$szChecked} /><label for='no_ac' onmouseover='this.style.cursor=\"pointer\";'>{$lang['strac']}</label>\n";
                        }
                        echo "</p>\n";
index b7cbb5783aca7751c05d94089f5fc680568425a3..5f6e557973cc9792edd699c0c71a40eb5d788456 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.84 2007/01/02 19:04:27 soranzo Exp $
+        * $Id: tables.php,v 1.85 2007/01/03 15:35:42 soranzo Exp $
         */
 
        // Include application functions
                global $lang;
                global $PHP_SELF;
 
-               $bAllowAC = ($conf["autocomplete"]!='disable') ? TRUE : FALSE ;
+               $bAllowAC = ($conf['autocomplete'] != 'disable') ? TRUE : FALSE;
 
                if ($confirm) {
                        $misc->printTrail('table');
                                $arrayLocals = array();
                                $arrayRefs = array();
                                $nC = 0;
-                               // A word of caution, the following does not support multicolumn FK's at the moment
                                while(!$constraints->EOF) {
-                                       preg_match('/foreign key \((\w+)\) references ([\w]+)\((\w+)\)/i', $constraints->fields["consrc"], $matches);
+                                       // The following RE will match a FK constrain with a single (quoted or not) referencing column. At the moment we don't support multicolumn FKs
+                                       preg_match('/^FOREIGN KEY \(("[^"]*"|[^\s",]*)\) REFERENCES (.*)\((.*)\)/i', $constraints->fields['consrc'], $matches);
                                        if(!empty($matches)) {
-                                               $arrayLocals[$nC] = $matches[1];
-                                               $arrayRefs[$nC] = array($matches[2], $matches[3]);
+                                               // Strip possible quotes and save
+                                               $arrayLocals[$nC] = preg_replace('/"(.*)"/', '$1', $matches[1]);
+                                               $arrayRefs[$nC] = array(preg_replace('/"(.*)"/', '$1', $matches[2]), preg_replace('/"(.*)"/', '$1', $matches[3]));
                                                $nC++;
                                        }
                                        $constraints->moveNext();
                                $i = 0;
                                while (!$attrs->EOF) {
                                        $szValueName = "values[{$attrs->f['attname']}]";
-                                       $szEvents = "";
-                                       $szDivPH = "";
+                                       $szEvents = '';
+                                       $szDivPH = '';
                                        if($bAllowAC) {
                                                $idxFound = array_search($attrs->f['attname'], $arrayLocals);
                                                // In PHP < 4.2.0 array_search returns NULL on failure
                                                if ($idxFound !== NULL && $idxFound !== FALSE) { 
-                                                       $szEvent = "makeAC('{$szValueName}',{$i},'{$arrayRefs[$idxFound][0]}','{$arrayRefs[$idxFound][1]}','{$_REQUEST["server"]}','{$_REQUEST["database"]}');";
+                                                       $szEvent = "makeAC('{$szValueName}',{$i},'{$arrayRefs[$idxFound][0]}','{$arrayRefs[$idxFound][1]}','{$_REQUEST['server']}','{$_REQUEST['database']}');";
                                                        $szEvents = "onfocus=\"{$szEvent}\" onblur=\"hideAC();document.getElementById('ac_form').onsubmit=function(){return true;};\" onchange=\"{$szEvent}\" id=\"{$szValueName}\" onkeyup=\"{$szEvent}\" autocomplete=\"off\" class='ac_field'";
                                                        $szDivPH = "<div id=\"fac{$i}_ph\"></div>";
                                                }
                        echo "<input type=\"submit\" name=\"insertandrepeat\" value=\"{$lang['strinsertandrepeat']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        if($bAllowAC) {
-                               $szChecked = $conf["autocomplete"]!='default off' ? "checked=\"checked\"" : "";
+                               $szChecked = $conf['autocomplete'] != 'default off' ? 'checked="checked"' : '';
                                echo "<input type=\"checkbox\" name=\"no_ac\" id=\"no_ac\" onclick=\"rEB(this.checked);\" value=\"1\" {$szChecked} /><label for='no_ac' onmouseover='this.style.cursor=\"pointer\";'>{$lang['strac']}</label>\n";
                        }
                        echo "</p>\n";