From 6bf0507654792f74eca88875801390bd18a149c1 Mon Sep 17 00:00:00 2001 From: Robert Treat Date: Mon, 20 Apr 2009 23:22:29 -0400 Subject: [PATCH] fix for bug #2742616, autocomplete on tables in different schemas --- aciur.js | 10 ++++++---- autocomplete.php | 3 ++- tables.php | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/aciur.js b/aciur.js index 710b2509..8ce0d5a6 100644 --- 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(); } diff --git a/autocomplete.php b/autocomplete.php index 680eba5f..5a662dfe 100644 --- a/autocomplete.php +++ b/autocomplete.php @@ -1,11 +1,12 @@ 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); diff --git a/tables.php b/tables.php index 582a2cc2..dd6c2311 100644 --- a/tables.php +++ b/tables.php @@ -477,7 +477,7 @@ // 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(); @@ -502,7 +502,7 @@ $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 = "
"; } -- 2.39.5