Fix join clause created by view wizard for pre 7.3 (tbl2 = ...). Drop a lot of whites...
authorsoranzo <soranzo>
Mon, 7 Jun 2004 20:03:08 +0000 (20:03 +0000)
committersoranzo <soranzo>
Mon, 7 Jun 2004 20:03:08 +0000 (20:03 +0000)
HISTORY
classes/Gui.php
views.php

diff --git a/HISTORY b/HISTORY
index ef055051961a81d42486cd3a268c7c7a63f04cc2..fd0911e9e640a843d989294032c04b0812548d21 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -13,6 +13,7 @@ Version 3.4.1
 Bugs
 * Fix export of mixed case tables pre 7.4
 * Fix table export problems pre 7.3
+* Fix join clause created by view wizard for pre 7.3
 
 Version 3.4
 -----------
index fba1289a1c7a58966897ddb92db6296872e70823..859f30a6dba5bca9ebf48fceed7c82d481d47ff9 100755 (executable)
@@ -2,7 +2,7 @@
        /**
         * Class to handle basic HTML GUI functions
         *
-        * $Id: Gui.php,v 1.1 2004/05/10 02:13:27 chriskl Exp $
+        * $Id: Gui.php,v 1.2 2004/06/07 20:03:22 soranzo Exp $
         */
         class GUI {
 
                 * @param (optional) $bBlankEntry bool to specify whether or not we want a blank selection 
                 * @param (optional) $szDefault string to specify the default VALUE selected 
                 * @param (optional) $bMultiple bool to specify whether or not we want a multi select combo box
-                * @param (optional) $iSize int to specify the size IF a multi select combo              
-                * @return string with the generated HTML select box             
+                * @param (optional) $iSize int to specify the size IF a multi select combo
+                * @return string with the generated HTML select box
                 */
-               function printCombo(&$arrOptions, $szName, $bBlankEntry = true, $szDefault = '', $bMultiple = false, $iSize = 10) {                     
+               function printCombo(&$arrOptions, $szName, $bBlankEntry = true, $szDefault = '', $bMultiple = false, $iSize = 10) {
                        $htmlOut = '';
                        if ($bMultiple) // If multiple select combo
                                $htmlOut .= "<select name=\"$szName\" id=\"$szName\" multiple=\"multiple\" size=\"$iSize\">\n";
index c4ab459c25b3bbb57e9e1bb3d200f163b6584dc5..b4ac0fff37fa2d5fd5a2cd9cbac281ffb1a7af1f 100644 (file)
--- a/views.php
+++ b/views.php
@@ -3,7 +3,7 @@
        /**
         * Manage views in a database
         *
-        * $Id: views.php,v 1.42 2004/06/04 05:26:35 chriskl Exp $
+        * $Id: views.php,v 1.43 2004/06/07 20:03:20 soranzo Exp $
         */
 
        // Include application functions
                        echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateviewwiz']}</h2>\n";               
                        $misc->printMsg($msg);
                        
-                       $tblCount = sizeof($_POST['formTables']);                                               
+                       $tblCount = sizeof($_POST['formTables']);
                        //unserialize our schema/table information and store in arrSelTables
                        for ($i = 0; $i < $tblCount; $i++) {
                                $arrSelTables[] = unserialize($_POST['formTables'][$i]);
-                       }                                                                       
+                       }
                        
-                       $linkCount = $tblCount;                                         
+                       $linkCount = $tblCount;
                        // If we can get foreign key info then get our linking keys
                        if ($data->hasForeignKeysInfo()) {
                                $rsLinkKeys = $data->getLinkingKeys($arrSelTables);
                                }
                                
                                $attrs = &$data->getTableAttributes($arrSelTables[$i]['tablename']);
-                               while (!$attrs->EOF) {                                          
+                               while (!$attrs->EOF) {
                                        if ($data->hasSchemas() ) {
                                                $arrFields["{$arrSelTables[$i]['schemaname']}.{$arrSelTables[$i]['tablename']}.{$attrs->f['attname']}"] = serialize(array('schemaname' => $arrSelTables[$i]['schemaname'], 'tablename' => $arrSelTables[$i]['tablename'], 'fieldname' => $attrs->f['attname']) );
                                        }
                                }
                                
                                //reset back to our original schema in case we switched from it
-                               if ($data->hasSchemas() ) {                             
+                               if ($data->hasSchemas() ) {
                                        $data->setSchema($curSchema);
                                }
-                       }                                               
-                       asort($arrFields);                      
+                       }
+                       asort($arrFields);
                        
                        echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
                        echo "<table>\n";
                        echo "</td>\n</tr>\n";
                        echo "<tr><th class=\"data\">{$lang['strcomment']}</th></tr>";
                        echo "<tr>\n<td class=\"data1\">\n";
-                       // View comments                        
+                       // View comments
                        echo "<textarea name=\"formComment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">", 
                                htmlspecialchars($_REQUEST['formComment']), "</textarea>\n";
                        echo "</td>\n</tr>\n";
                        // Output selector for fields to be retrieved from view
                        echo "<table>\n";
                        echo "<tr><th class=\"data\">{$lang['strfields']}</th></tr>";
-                       echo "<tr>\n<td class=\"data1\">\n";                    
+                       echo "<tr>\n<td class=\"data1\">\n";
                        echo GUI::printCombo($arrFields, 'formFields[]', false, '', true);
-                       echo "</td>\n</tr>\n</table>\n<br />\n";                                                
-                                                                       
-                       // Output the Linking keys combo boxes only if we detect linking keys
+                       echo "</td>\n</tr>\n</table>\n<br />\n";
+                       
+                       // Output the Linking keys combo boxes
                        echo "<table>\n";
-                       echo "<tr><th class=\"data\">{$lang['strviewlink']}</th></tr>";                                 
+                       echo "<tr><th class=\"data\">{$lang['strviewlink']}</th></tr>";
                        $rowClass = 'data1';
                        for ($i = 0; $i < $linkCount; $i++) {
                                // Initialise variables
                                if (!isset($formLink[$i]['operator'])) $formLink[$i]['operator'] = 'INNER JOIN';
                                echo "<tr>\n<td class=\"$rowClass\">\n";
-                                                       
+                               
                                if ($data->hasForeignKeysInfo() && !$rsLinkKeys->EOF) {
                                        $curLeftLink = htmlspecialchars(serialize(array('schemaname' => $rsLinkKeys->f['p_schema'], 'tablename' => $rsLinkKeys->f['p_table'], 'fieldname' => $rsLinkKeys->f['p_field']) ) );
-                                       $curRightLink = htmlspecialchars(serialize(array('schemaname' => $rsLinkKeys->f['f_schema'], 'tablename' => $rsLinkKeys->f['f_table'], 'fieldname' => $rsLinkKeys->f['f_field']) ) );                                           
+                                       $curRightLink = htmlspecialchars(serialize(array('schemaname' => $rsLinkKeys->f['f_schema'], 'tablename' => $rsLinkKeys->f['f_table'], 'fieldname' => $rsLinkKeys->f['f_field']) ) );
                                        $rsLinkKeys->moveNext();
                                }
                                else {
                                echo GUI::printCombo($data->joinOps, "formLink[$i][operator]", true, $formLink[$i]['operator']);
                                echo GUI::printCombo($arrFields, "formLink[$i][rightlink]", true, $curRightLink, false );
                                echo "</td>\n</tr>\n";
-                               $rowClass = $rowClass == 'data1' ? 'data2' : 'data1';                   
+                               $rowClass = $rowClass == 'data1' ? 'data2' : 'data1';
                        }
                        echo "</table>\n<br />\n";
-                                                               
+                       
                        // Build list of available operators (infix only)
                        $arrOperators = array();
                        foreach ($data->selectOps as $k => $v) {
                        // Output additional conditions, note that this portion of the wizard treats the right hand side as literal values 
                        //(not as database objects) so field names will be treated as strings, use the above linking keys section to perform joins
                        echo "<table>\n";
-                       echo "<tr><th class=\"data\">{$lang['strviewconditions']}</th></tr>";                                   
+                       echo "<tr><th class=\"data\">{$lang['strviewconditions']}</th></tr>";
                        $rowClass = 'data1';
-                       for ($i = 0; $i < $linkCount; $i++) {                           
+                       for ($i = 0; $i < $linkCount; $i++) {
                                echo "<tr>\n<td class=\"$rowClass\">\n";
                                echo GUI::printCombo($arrFields, "formCondition[$i][field]");
                                echo GUI::printCombo($arrOperators, "formCondition[$i][operator]", false, false);
                                echo "<input type=\"text\" name=\"formCondition[$i][txt]\" />\n";
                                echo "</td>\n</tr>\n";
                                $rowClass = $rowClass == 'data1' ? 'data2' : 'data1';
-                       }                       
+                       }
                        echo "</table>\n";
-                       echo "<p><input type=\"hidden\" name=\"action\" id=\"action\" value=\"save_create_wiz\" />\n";                  
-                       echo "<input type=\"submit\" value=\"{$lang['strnext']}\" />\n";
+                       echo "<p><input type=\"hidden\" name=\"action\" id=\"action\" value=\"save_create_wiz\" />\n";
+                       echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
-                                               
-                       foreach ($arrSelTables AS $curTable) {                          
+                       
+                       foreach ($arrSelTables AS $curTable) {
                                echo "<input type=\"hidden\" name=\"formTables[]\" id=\"formTables[]\" value=\"" . htmlspecialchars(serialize($curTable) ) . "\" />\n";
                        }
                        
                        echo $misc->form;
                        echo "</form>\n";
-               }       
+               }
        }
        
        /**
                                                        $arrRightLink = unserialize($curLink['rightlink']);
                                                        
                                                        $tbl1 = $data->hasSchemas() ? "\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\"" : $arrLeftLink['tablename'];
-                                                       $tbl2 = $data->hasSchemas() ? "\"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\"" : $arrLeftLink['tablename'];                                                                                         
-                                                                                                       
+                                                       $tbl2 = $data->hasSchemas() ? "\"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\"" : $arrRightLink['tablename'];
+                                                       
                                                        if ( (!in_array($curLink, $arrJoined) && in_array($tbl1, $arrUsedTbls)) || !count($arrJoined) ) {
-                                                                                                                       
+                                                               
                                                                // Make sure for multi-column foreign keys that we use a table alias tables joined to more than once
                                                                // This can (and should be) more optimized for multi-column foreign keys
                                                                $adj_tbl2 = in_array($tbl2, $arrUsedTbls) ? "$tbl2 AS alias_ppa_" . mktime() : $tbl2;
-                                                                                                                                                                               
-                                                               if ($data->hasSchemas() ) {     
+                                                               
+                                                               if ($data->hasSchemas() ) {
                                                                        $linkFields .= strlen($linkFields) ? "{$curLink['operator']} $adj_tbl2 ON (\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\".\"{$arrLeftLink['fieldname']}\" = \"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\".\"{$arrRightLink['fieldname']}\") " : "$tbl1 {$curLink['operator']} $adj_tbl2 ON (\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\".\"{$arrLeftLink['fieldname']}\" = \"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\".\"{$arrRightLink['fieldname']}\") ";
                                                                }
                                                                else {
                                                                        $linkFields .= strlen($linkFields) ? "{$curLink['operator']} $adj_tbl2 ON (\"{$arrLeftLink['tablename']}\".\"{$arrLeftLink['fieldname']}\" = \"{$arrRightLink['tablename']}\".\"{$arrRightLink['fieldname']}\") " : "$tbl1 {$curLink['operator']} $adj_tbl2 ON (\"{$arrLeftLink['tablename']}\".\"{$arrLeftLink['fieldname']}\" = \"{$arrRightLink['tablename']}\".\"{$arrRightLink['fieldname']}\") ";
-                                                               }                                                               
+                                                               }
                                                                
                                                                $arrJoined[] = $curLink;
                                                                if (!in_array($tbl1, $arrUsedTbls) )  $arrUsedTbls[] = $tbl1;
                                                                if (!in_array($tbl2, $arrUsedTbls) )  $arrUsedTbls[] = $tbl2;
-                                                       }                                               
+                                                       }
                                                }
-                                               $j++;                                   
+                                               $j++;
                                        }
-                               }                               
-                       }                       
+                               }
+                       }
                        
                        //if linkfields has no length then either _POST['formLink'] was not set, or there were no join conditions 
                        //just select from all seleted tables - a cartesian join do a
                        if (!strlen($linkFields) ) {
                                foreach ($_POST['formTables'] AS $curTable) {
                                        $arrTmp = unserialize($curTable);
-                                       if ($data->hasSchemas() ) {                                     
+                                       if ($data->hasSchemas() ) {
                                                $linkFields .= strlen($linkFields) ? ", \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\"" : "\"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\"";
                                        }
                                        else {
                                                $linkFields .= strlen($linkFields) ? ", \"{$arrTmp['tablename']}\"" : "\"{$arrTmp['tablename']}\"";
-                                       }                               
-                               }                               
-                       }                       
+                                       }
+                               }
+                       }
                        
                        $addConditions = '';
                        if (is_array($_POST['formCondition']) ) {
                                foreach ($_POST['formCondition'] AS $curCondition) {
-                                       if (strlen($curCondition['field']) && strlen($curCondition['txt']) ) {                                          
+                                       if (strlen($curCondition['field']) && strlen($curCondition['txt']) ) {
                                                $arrTmp = unserialize($curCondition['field']);
                                                if ($data->hasSchemas() ) {
                                                        $addConditions .= strlen($addConditions) ? " AND \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['operator']} '{$curCondition['txt']}' " : " \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['operator']} '{$curCondition['txt']}' ";
-                                               }                                               
+                                               }
                                                else {
                                                        $addConditions .= strlen($addConditions) ? " AND \"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['field']} {$curCondition['operator']} '{$curCondition['txt']}' " : " \"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['operator']} '{$curCondition['txt']}' ";
-                                               }                                               
-                                       }       
-                               }               
+                                               }
+                                       }
+                               }
                        }
                        
                        $viewQuery = "SELECT $selFields FROM $linkFields ";
                                $_reload_browser = true;
                                doDefault($lang['strviewcreated']);
                        }
-                       else                            
+                       else
                                doSetParamsCreate($lang['strviewcreatedbad']);
                }
-       }       
+       }
        
        /**
         * Show default list of views in the database