Select function on tables now works basically
authorchriskl <chriskl>
Mon, 27 Jan 2003 15:18:03 +0000 (15:18 +0000)
committerchriskl <chriskl>
Mon, 27 Jan 2003 15:18:03 +0000 (15:18 +0000)
classes/database/BaseDB.php
display.php
lang/english.php
tables.php

index c34ce1908634e970343a9a985c6e9ef63c6f3fc9..1c9e971cda774b716c234cae7713602b2b1791d8 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: BaseDB.php,v 1.8 2003/01/18 06:38:37 chriskl Exp $
+ * $Id: BaseDB.php,v 1.9 2003/01/27 15:18:03 chriskl Exp $
  */
 
 include_once('classes/database/ADODB_base.php');
@@ -82,6 +82,53 @@ class BaseDB extends ADODB_base {
                }
        }
        
+       /**
+        * Generates the SQL for the 'select' function
+        * @param $table The table from which to select
+        * @param $show An array of columns to show
+        * @param $values An array mapping columns to values
+        * @param $nulls An array of columns that are null
+        * @return The SQL query
+        */
+       function getSelectSQL($table, $show, $values, $nulls) {
+               $this->fieldClean($table);
+
+               $sql = "SELECT \"" . join('","', $show) . "\" FROM \"{$table}\"";
+
+               // If we have values specified, add them to the WHERE clause
+               $first = true;
+               if (sizeof($values) > 0) {
+                       foreach ($values as $k => $v) {
+                               if ($v != '' && !in_array($k, $nulls)) {
+                                       if ($first) {
+                                               $this->fieldClean($k);
+                                               $this->clean($v);
+                                               // @@ FIX THIS QUOTING
+                                               $sql .= " WHERE \"{$k}\"='{$v}'";
+                                               $first = false;
+                                       } else {
+                                               $sql .= " AND \"{$k}\"='{$v}'";
+                                       }
+                               }
+                       }
+               }
+
+               // If we have NULL values specified, add them to the WHERE clause
+               if (sizeof($nulls) > 0) {
+                       foreach ($nulls as $v) {
+                               if ($first) {
+                                       $this->fieldClean($k);
+                                       $sql .= " WHERE \"{$k}\" IS NULL";
+                                       $first = false;
+                               } else {
+                                       $sql .= " AND \"{$k}\" IS NULL";
+                               }
+                       }
+               }
+
+               return $sql;
+       }
+
        /**
         * Returns a recordset of all columns in a relation.  Used for data export.
         * @@ Note: Really needs to use a cursor
index de28557624ae9cd8b757a747150082882d08b33b..91b3cb6286b8f4a3e736fe30261ecfa6b7232eb6 100644 (file)
@@ -9,12 +9,14 @@
         * @param $return_desc The return link name
         * @param $page The current page
         *
-        * $Id: display.php,v 1.2 2003/01/27 14:09:51 chriskl Exp $
+        * $Id: display.php,v 1.3 2003/01/27 15:18:03 chriskl Exp $
         */
 
        // Include application functions
        include_once('conf/config.inc.php');
 
+       global $strQueryResults, $guiMaxRows, $strRows;
+
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        $PHP_SELF = $_SERVER['PHP_SELF'];
 
index cf7853485a8d1312e869e5f3f76329a146f3a05d..175bfa0ca4acdb12d8bac075e8c0e2a7e7b48cfc 100755 (executable)
@@ -4,7 +4,7 @@
         * Language template file for WebDB. Use this to base language
         * files.
         *
-        * $Id: english.php,v 1.48 2003/01/27 14:09:52 chriskl Exp $
+        * $Id: english.php,v 1.49 2003/01/27 15:18:03 chriskl Exp $
         */
 
        // Language and character set
        $strField = 'Field';
        $strFields = 'Fields';
        $strNumFields = 'Num. Of Fields';
+       $strSelectNeedsCol = 'You must show at least one column';
 
        // Users
        $strUserAdmin = 'User Admin';
index 9e5aad892e5ea629d1badfcb0417a13cc72f638c..a8d8a9aa0578a5bac0192b7deeca9762538dfa25 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.3 2003/01/25 23:59:08 slubek Exp $
+        * $Id: tables.php,v 1.4 2003/01/27 15:18:03 chriskl Exp $
         */
 
        // Include application functions
                global $localData, $database, $misc;
                global $strField, $strType, $strNull, $strFunction, $strValue, $strTables, $strSelect;
                global $strShow, $strInvalidParam, $strCancel, $strRowInserted, $strRowInsertedBad;
-               global $strSave;
+               global $strSave, $strBack, $strSelectNeedsCol;
                global $PHP_SELF;
 
                if ($confirm) {
                                echo "<table>\n<tr>";
 
                                // Output table header
-                               echo "<tr><th class=data>{$strShow}</th><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strNull}</th><th class=data>{$strFunction}</th><th class=data>{$strValue}</th></tr>";
+                               echo "<tr><th class=data>{$strShow}</th><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strNull}</th><th class=data>{$strValue}</th></tr>";
 
                                $i = 0;
                                while (!$attrs->EOF) {
                                                        isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked' : '', "></td>";
                                        else
                                                echo "&nbsp;</td>";
-                                       echo "<td class=data{$id} nowrap><input size=10 name=\"function[{$attrs->f['attname']}]\"></td>";
                                        echo "<td class=data{$id} nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
                                                $_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
                                        echo "</tr>\n";
                        echo "</form>\n";
                }
                else {
+                       if (!isset($_POST['show'])) $_POST['show'] = array();
                        if (!isset($_POST['values'])) $_POST['values'] = array();
                        if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
-                       $localData->getSelectSQL($query, $count);
-
-                       $status = $localData->selectRows($_POST['table'], $_POST['values'], $_POST['nulls']);
-                       if ($status == 0) {
-                               // @@ This test here is sort of dodgy!
-                               if ($_POST['choice'] == $strSave)
-                                       doDefault($strRowInserted);
-                               else {
-                                       $_REQUEST['values'] = array();
-                                       $_REQUEST['nulls'] = array();
-                                       doInsertRow(true, $strRowInserted);
-                               }
+                       
+                       if (sizeof($_POST['show']) == 0)
+                               doSelectRows(true, $strSelectNeedsCol);
+                       else {
+                               // Generate query SQL
+                               $query = $localData->getSelectSQL($_REQUEST['table'], array_keys($_POST['show']),
+                                       $_POST['values'], array_keys($_POST['nulls']));
+                               $_REQUEST['query'] = $query;
+                               $_REQUEST['return_url'] = "tables.php?action=confselectrows&{$misc->href}&table={$_REQUEST['table']}";
+                               $_REQUEST['return_desc'] = $strBack;
+
+                               include('display.php');
+                               exit;
                        }
-                       else
-                               doInsertRow(true, $strRowInsertedBad);
                }
 
        }