fix for bug #2742616, autocomplete on tables in different schemas
authorRobert Treat <robert@new-host.home>
Tue, 21 Apr 2009 03:22:29 +0000 (23:22 -0400)
committerRobert Treat <robert@new-host.home>
Tue, 21 Apr 2009 03:22:29 +0000 (23:22 -0400)
aciur.js
autocomplete.php
tables.php

index 710b2509921e34eb8e0c6168ebe7f785f587f4f9..8ce0d5a6cf50cd8b1f81851a373b23d19d81ba96 100644 (file)
--- a/aciur.js
+++ b/aciur.js
@@ -11,6 +11,7 @@ var asg = new Array();
 var rasg = new Array();
 var rasgc = new Array();
 var iMoR = false;
+var g_c_ns = "";
 var g_c_tb = "";
 var g_c_fk = "";
 var g_c_sid = "";
@@ -57,7 +58,8 @@ function hKU(oEvent) {
        }
 }
 
-function initac(tb,fk,sid,db,v) {
+function initac(ns,tb,fk,sid,db,v) {
+    g_c_ns = ns;
     g_c_tb = tb;
     g_c_fk = fk;
     g_c_sid = sid;
@@ -240,7 +242,7 @@ function dF(v) {
        g_i_ac = document.getElementById(v).checked;
 }
 
-function makeAC(tx,n,tb,fk,sid,db) {
+function makeAC(tx,n,ns,tb,fk,sid,db) {
        otxb = document.getElementById(tx);
        c_fac_c = n;
        if(document.getElementById('no_ac').checked) {
@@ -254,7 +256,7 @@ function makeAC(tx,n,tb,fk,sid,db) {
                otxb.onkeyup = function (oEvent) {
                        if (!oEvent) { oEvent = window.event; } hKU(oEvent); 
                };
-               initac(tb,fk,sid,db,v);
+               initac(ns, tb,fk,sid,db,v);
        } else {
                otxb.onkeyup = function() {};
        }
@@ -291,7 +293,7 @@ function rS(tx) {
 
 function SG1(s) {
        if(!iMoR && s.length>0) {
-               pr("autocomplete.php","tb="+g_c_tb+"&database="+g_c_db+"&server="+g_c_sid+"&fk="+g_c_fk+"&v="+escapeHTML(s)+"");
+               pr("autocomplete.php","ns="+g_c_ns+"&tb="+g_c_tb+"&database="+g_c_db+"&server="+g_c_sid+"&fk="+g_c_fk+"&v="+escapeHTML(s)+"");
        } else if(!s.length) {
                hideAC();
        }
index 680eba5f5ec379d7a94c66969fcda11265cbdd34..5a662dfe94f25290cd17419103ca23dd794a153e 100644 (file)
@@ -1,11 +1,12 @@
 <?php
        include_once('libraries/lib.inc.php');
        $data->clean($_REQUEST['tb']);
+       $data->clean($_REQUEST['ns']);
        $data->clean($_REQUEST['fk']);
        $data->clean($_REQUEST['v']);
 
        // FIXME: At some point this should be schema qualified
-       $szSQL = 'SELECT * FROM "' . $_REQUEST['tb'] . '" WHERE "' . $_REQUEST['fk']
+       $szSQL = 'SELECT * FROM "' . $_REQUEST['ns'] . '"."' . $_REQUEST['tb'] . '" WHERE "' . $_REQUEST['fk']
                . "\"::text LIKE '" . $_REQUEST['v'] . "%' ORDER BY \"". $_REQUEST['fk'] .'" LIMIT 11';
 
        $objRes = $data->selectSet($szSQL);
index 582a2cc25b1cd99d01a5c45568bafff1ac86f633..dd6c23113002f8ea76b80e5d11228d7c2aa64519 100644 (file)
                                        // FIXME: add a better support for FKs on multi columns
                                        if ($constraints->fields['contype'] == 'f') {
                                                $arrayLocals[$nC] = $constraints->fields['p_field'];
-                                               $arrayRefs[$nC] = array($constraints->fields['f_table'], $constraints->fields['f_field']);
+                                               $arrayRefs[$nC] = array($constraints->fields['f_schema'], $constraints->fields['f_table'], $constraints->fields['f_field']);
                                                $nC++;
                                        }
                                        $constraints->moveNext();
                                                $idxFound = array_search($attrs->fields['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]}','{$arrayRefs[$idxFound][2]}','{$_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>";
                                                }