relation table new vars

This commit is contained in:
Marc Delisle
2002-04-26 16:54:05 +00:00
parent 1b5ad193d2
commit 5677d360b6
3 changed files with 44 additions and 42 deletions

View File

@@ -17,6 +17,8 @@ $Source$
to Mike Beck (mike.beck at ibmiller.de)
(experimental: some things remain to be tested)
* Documentation.html: example for automatic joints
* tbl_qbe.php3, tbl_printview.php3, libraries/display_tbl.lib.php3,
Documentation.html: rename fields in the relation table
2002-04-26 Alexander M. Turek <rabus@users.sourceforge.net>
* libraries/common.lib.php3: fixed a controluser bug.

View File

@@ -586,12 +586,12 @@ $cfg['PmaAbsoluteUri'] = (!empty($HTTPS) ? 'https' : 'http') . '://'
currently uses this to
<ul>
<li>
make clickable, when you browse the src table, the data values
that point to the dest table;
make clickable, when you browse the master table, the data values
that point to the foreign table;
</li>
<li>
display links on the table properties page, to check referential
integrity (display missing foreign keys) for each described key.
integrity (display missing foreign keys) for each described key;
</li>
<li>
in query-by-example, create automatic joints (see an example
@@ -610,11 +610,11 @@ $cfg['PmaAbsoluteUri'] = (!empty($HTTPS) ? 'https' : 'http') . '://'
following this scheme:<br />
<tt>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CREATE TABLE `relation` (<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`src_table` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`src_column` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`dest_table` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`dest_column` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRIMARY KEY (`src_table`,`src_column`)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`master_table` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`master_field` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`foreign_table` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`foreign_field` varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRIMARY KEY (`master_table`,`master_field`)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;) TYPE=MyISAM COMMENT='Table Relation';<br />
</tt>
</li>
@@ -1563,11 +1563,11 @@ $cfg['PmaAbsoluteUri'] = (!empty($HTTPS) ? 'https' : 'http') . '://'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INSERT INTO persons VALUES (15, 'Paul', 'S', 'C');<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CREATE TABLE relation (<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src_table varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src_column varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest_table varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest_column varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRIMARY KEY (src_table,src_column)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;master_table varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;master_field varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreign_table varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreign_field varchar(32) NOT NULL default '',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRIMARY KEY (master_table,master_field)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;) TYPE=MyISAM;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INSERT INTO relation VALUES ('persons', 'town_code', 'towns', 'town_code');<br />

View File

@@ -746,24 +746,24 @@ if(count($Field)>0){
$wheretabs=$where;
}
// i expect it will make sense to have the table which is most often
// found as dest_table as the one to start our FROM...
// found as foreign_table as the one to start our FROM...
// but we have to make sure that if there is a WHERE clause then we have
// a master out of those that are used there
// We will need this a few times:
$incrit = '(\''. str_replace(',', "','", implode(',',$alltabs)) . '\')';
$rel_query = 'SELECT src_table as wer,count(dest_table) as hits from '.PMA_backquote($cfg['Server']['relation']);
$rel_query .= ' WHERE src_table IN '.$incrit.' AND dest_table in '.$incrit;
$rel_query .= ' GROUP by src_table ORDER by hits desc ';
$rel_query = 'SELECT master_table as wer,count(foreign_table) as hits from '.PMA_backquote($cfg['Server']['relation']);
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit;
$rel_query .= ' GROUP by master_table ORDER by hits desc ';
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
// if we don't find anything we try the other way round
if(mysql_num_rows($rel_id)==0){
$rel_query = 'SELECT dest_table as wer,count(src_table) as hits from '.PMA_backquote($cfg['Server']['relation']);
$rel_query .= ' WHERE src_table IN '.$incrit.' AND dest_table in '.$incrit;
$rel_query .= ' GROUP by dest_table ORDER by hits desc ';
$rel_query = 'SELECT foreign_table as wer,count(master_table) as hits from '.PMA_backquote($cfg['Server']['relation']);
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit;
$rel_query .= ' GROUP by foreign_table ORDER by hits desc ';
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
}
@@ -779,7 +779,7 @@ if(count($Field)>0){
}
if(is_array($wheretabs)){
while (list($key, $value) = each ($wheretabs)){
if($row['src_table']==$key){
if($row['master_table']==$key){
$master = $row['wer'];
$ex=1;
break;
@@ -809,26 +809,26 @@ if(count($Field)>0){
$incrit_s = '(\''. str_replace(',', "','", implode(',',$reltabs)) . '\')';
$rel_query = 'SELECT * from '.PMA_backquote($cfg['Server']['relation']);
$rel_query .= ' WHERE src_table IN '.$incrit.' AND dest_table in '.$incrit_s;
$rel_query .= ' ORDER by dest_table,src_table ';
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit_s;
$rel_query .= ' ORDER by foreign_table,master_table ';
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
while ($row = mysql_fetch_array($rel_id)){
$dest_table = $row['dest_table'];
if($rel[$dest_table]['mcon']==0){
$foreign_table = $row['foreign_table'];
if($rel[$foreign_table]['mcon']==0){
// if we allready found a link to the mastertable we don't want another
// otherwise we take whatever we get
$rel[$dest_table]['link'] = ' LEFT JOIN '.PMA_backquote($dest_table);
$rel[$dest_table]['link'] .= ' ON '.PMA_backquote($row['src_table']).'.'.PMA_backquote($row['src_column']);
$rel[$dest_table]['link'] .= ' = '.PMA_backquote($row['dest_table']).'.'.PMA_backquote($row['dest_column']) .' ';
$rel[$foreign_table]['link'] = ' LEFT JOIN '.PMA_backquote($foreign_table);
$rel[$foreign_table]['link'] .= ' ON '.PMA_backquote($row['master_table']).'.'.PMA_backquote($row['master_field']);
$rel[$foreign_table]['link'] .= ' = '.PMA_backquote($row['foreign_table']).'.'.PMA_backquote($row['foreign_field']) .' ';
}
if($row['src_table'] == $master){
$rel[$dest_table]['mcon']=1;
if($row['master_table'] == $master){
$rel[$foreign_table]['mcon']=1;
}
}
// possibly we still don't have all - there might be some that are
// only found as a dest_table in relation to one of those that we allready have
// only found as a foreign_table in relation to one of those that we allready have
if($master!=''){
$found[] = $master;
$qry_from = PMA_backquote($master);
@@ -846,26 +846,26 @@ if(count($Field)>0){
$incrit_s = '(\''. str_replace(',', "','", implode(',',$rest)) . '\')';
$rel_query = 'SELECT * from '.$cfg['Server']['relation'];
$rel_query .= ' WHERE src_table IN '.$incrit_s.' AND dest_table in '.$incrit_d;
$rel_query .= ' ORDER by src_table,dest_table ';
$rel_query .= ' WHERE master_table IN '.$incrit_s.' AND foreign_table in '.$incrit_d;
$rel_query .= ' ORDER by master_table,foreign_table ';
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
while ($row = mysql_fetch_array($rel_id)){
$dest_table = $row['dest_table'];
// echo 'pr<70>fe '.$src_table;
if($rel[$dest_table]['mcon']==0){
$foreign_table = $row['foreign_table'];
// echo 'pr<70>fe '.$master_table;
if($rel[$foreign_table]['mcon']==0){
// if we allready found a link to the mastertable we don't want another
// otherwise we take whatever we get
$rel[$dest_table]['link'] = ' LEFT JOIN '.$dest_table;
$rel[$dest_table]['link'] .= ' ON '.PMA_backquote($row['dest_table']).'.'.PMA_backquote($row['dest_column']);
$rel[$dest_table]['link'] .= ' = '.PMA_backquote($row['src_table']).'.'.PMA_backquote($row['src_column']) .' ';
$rel[$foreign_table]['link'] = ' LEFT JOIN '.$foreign_table;
$rel[$foreign_table]['link'] .= ' ON '.PMA_backquote($row['foreign_table']).'.'.PMA_backquote($row['foreign_field']);
$rel[$foreign_table]['link'] .= ' = '.PMA_backquote($row['master_table']).'.'.PMA_backquote($row['master_field']) .' ';
// in extreme cases we hadn't found a master yet, so let's use
// the one we found now
$master = $row['dest_table'];
$master = $row['foreign_table'];
}
if($row['src_table'] == $master){
$rel[$dest_table]['mcon']=1;
if($row['master_table'] == $master){
$rel[$foreign_table]['mcon']=1;
}
}
}