From 661108fbb280b7a22e7d4e91d0890c06cdb2880b Mon Sep 17 00:00:00 2001 From: ioguix Date: Mon, 14 Jan 2008 17:55:01 +0000 Subject: [PATCH] fix for bug report #1868987 and some cleanup. Needs some more cleanup and work for a better FK support on multi-columns --- aciur.js | 24 +++++++++++------------- autocomplete.php | 9 ++++++++- tables.php | 18 +++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/aciur.js b/aciur.js index a817a9a8..710b2509 100644 --- a/aciur.js +++ b/aciur.js @@ -80,10 +80,11 @@ if(!bnsr) { oRange.moveStart("character",p_len); oRange.moveEnd("character",p_len); oRange.select(); - } else if (otxb.setSelectionRange) { + } + else if (otxb.setSelectionRange) { otxb.setSelectionRange(p_len,p_len); + } } -} otxb.focus(); } @@ -97,12 +98,10 @@ function tA(p_suggestion) { } } -function findPosX(obj) -{ +function findPosX(obj) { if(obj) { var curleft = 0; - if (obj.offsetParent) - { + if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft @@ -115,18 +114,15 @@ function findPosX(obj) } } -function findPosY(obj) -{ +function findPosY(obj) { if(obj) { var curtop = 0; var n = 0; if (obj.y) { curtop += obj.y; } - else if (obj.offsetParent) - { - while (obj.offsetParent) - { + else if (obj.offsetParent) { + while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; } @@ -256,7 +252,8 @@ function makeAC(tx,n,tb,fk,sid,db) { curopt = 0; bnsr = false; otxb.onkeyup = function (oEvent) { - if (!oEvent) { oEvent = window.event; } hKU(oEvent); }; + if (!oEvent) { oEvent = window.event; } hKU(oEvent); + }; initac(tb,fk,sid,db,v); } else { otxb.onkeyup = function() {}; @@ -270,6 +267,7 @@ function gfacc(s) { function iA(parent, node, referenceNode) { parent.insertBefore(node, referenceNode.nextSibling); } + var asg = new Array(); var rasg = new Array(); var rasgc = new Array(); diff --git a/autocomplete.php b/autocomplete.php index 823658c6..d2535659 100644 --- a/autocomplete.php +++ b/autocomplete.php @@ -1,11 +1,18 @@ clean($_REQUEST['tb']) . ' WHERE ' . $data->clean($_REQUEST['fk']) . " LIKE '" . $data->clean($_REQUEST['v']) . "%' LIMIT 11"; + $data->clean($_REQUEST['tb']); + $data->clean($_REQUEST['fk']); + $data->clean($_REQUEST['v']); + + $szSQL = 'SELECT * FROM ' . $_REQUEST['tb'] . ' WHERE ' . $_REQUEST['fk'] + . "::text LIKE '" . $_REQUEST['v'] . "%' ORDER BY ". $_REQUEST['fk'] ." LIMIT 11"; + $objRes = $data->selectSet($szSQL); $arrayRes = array(); while (!$objRes->EOF) { $arrayRes[] = $objRes->fields[$_REQUEST['fk']]; $objRes->moveNext(); } + echo implode('PPA_EOF;|', $arrayRes); ?> diff --git a/tables.php b/tables.php index 329947f7..c9190261 100644 --- a/tables.php +++ b/tables.php @@ -3,7 +3,7 @@ /** * List tables in a database * - * $Id: tables.php,v 1.108 2007/12/27 18:28:36 ioguix Exp $ + * $Id: tables.php,v 1.109 2008/01/14 17:55:01 ioguix Exp $ */ // Include application functions @@ -451,7 +451,8 @@ global $data, $misc, $conf; global $lang; - $bAllowAC = ($conf['autocomplete'] != 'disable') ? TRUE : FALSE; + $bAllowAC = (($conf['autocomplete'] != 'disable') ? TRUE : FALSE) + && $data->hasConstraintsInfo(); if ($confirm) { $misc->printTrail('table'); @@ -460,17 +461,16 @@ $attrs = $data->getTableAttributes($_REQUEST['table']); if($bAllowAC) { - $constraints = $data->getConstraints($_REQUEST['table']); + $constraints = $data->getConstraintsWithFields($_REQUEST['table']); + $arrayLocals = array(); $arrayRefs = array(); $nC = 0; while(!$constraints->EOF) { - // 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)) { - // 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])); + // 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']); $nC++; } $constraints->moveNext(); -- 2.39.5