Try to improve insert row. Choose between inserting a value or an expression. Suppo...
authorchriskl <chriskl>
Sat, 10 May 2003 13:15:42 +0000 (13:15 +0000)
committerchriskl <chriskl>
Sat, 10 May 2003 13:15:42 +0000 (13:15 +0000)
classes/database/BaseDB.php
lang/english.php
lang/recoded/english.php
tables.php

index bb005210065c977de3389a1255fc2a40bf575f61..062f6a2602b59babbdda921bb8a5d060fc320040 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.14 2003/05/01 03:27:54 chriskl Exp $
+ * $Id: BaseDB.php,v 1.15 2003/05/10 13:15:42 chriskl Exp $
  */
 
 include_once('classes/database/ADODB_base.php');
@@ -66,30 +66,35 @@ class BaseDB extends ADODB_base {
         * @param $table The table in which to insert
         * @param $values An array mapping new values for the row
         * @param $nulls An array mapping column => something if it is to be null
+        * @param $format An array of the data type (VALUE or EXPRESSION)
+        * @param $types An array of field types
         * @return 0 success
         * @return -1 invalid parameters
         */
-       function insertRow($table, $vars, $nulls) {
-               if (!is_array($vars) || !is_array($nulls)) return -1;
+       function insertRow($table, $vars, $nulls, $format, $types) {
+               if (!is_array($vars) || !is_array($nulls) || !is_array($format)
+                       || !is_array($types)) return -1;
                // @@ WE CANNOT USE insert AS WE NEED TO NOT QUOTE SOME THINGS
                // @@ WHAT ABOUT BOOLEANS??
                else {
                        $this->fieldClean($table);
-       
+
                        // Build clause
                        if (sizeof($vars) > 0) {
                                $fields = '';
                                $values = '';
                                foreach($vars as $key => $value) {
+                                       $doEscape = $format[$key] == 'VALUE';
                                        $this->clean($key);
-                                       $this->clean($value);
+                                       if ($doEscape) $this->clean($value);
        
                                        if ($fields) $fields .= ", \"{$key}\"";
                                        else $fields = "INSERT INTO \"{$table}\" (\"{$key}\"";
        
                                        // Handle NULL values
                                        if (isset($nulls[$key])) $tmp = 'NULL';
-                                       else $tmp = "'{$value}'";
+                                       elseif ($doEscape) $tmp = "'{$value}'";
+                                       else $tmp = $value;
                                        
                                        if ($values) $values .= ", {$tmp}";
                                        else $values = ") VALUES ({$tmp}";
index 85d052434b1829b0ee956c9c3c80454d6b3afb8e..2e2f087b27aa586972c3418665c3709184c18c72 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.76 2003/05/08 15:14:15 chriskl Exp $
+        * $Id: english.php,v 1.77 2003/05/10 13:15:42 chriskl Exp $
         */
 
        // Language and character set
@@ -83,6 +83,7 @@
        $lang['strformat'] = 'Format';
        $lang['strdata'] = 'Data';
        $lang['strconfirm'] = 'Confirm';
+       $lang['strexpression'] = 'Expression';
 
        // Error handling
        $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.';
index fd32b25ab89a0b814140f57f4cc0130b65035470..246b8666943c8100ce6fdf1ca1d2cb5f9fa4f80f 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.28 2003/05/08 15:14:15 chriskl Exp $
+        * $Id: english.php,v 1.29 2003/05/10 13:15:43 chriskl Exp $
         */
 
        // Language and character set
@@ -83,6 +83,7 @@
        $lang['strformat'] = 'Format';
        $lang['strdata'] = 'Data';
        $lang['strconfirm'] = 'Confirm';
+       $lang['strexpression'] = 'Expression';
 
        // Error handling
        $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.';
index 988c89e9231e8183b6cee2804cdd7bd3fae0bfcc..6c7ef35cd9867a8a004165ea7d50f73bd13a5c97 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.19 2003/05/05 03:03:53 chriskl Exp $
+        * $Id: tables.php,v 1.20 2003/05/10 13:15:42 chriskl Exp $
         */
 
        // Include application functions
 
                        echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
                        if ($attrs->recordCount() > 0) {
-                               echo "<table>\n<tr>";
+                               echo "<table>\n";
 
                                // Output table header
-                               echo "<tr><th class=data>{$lang['strfield']}</th><th class=data>{$lang['strtype']}</th><th class=data>{$lang['strnull']}</th><th class=data>{$lang['strvalue']}</th></tr>";
+                               echo "<tr><th class=\"data\">{$lang['strfield']}</th><th class=\"data\">{$lang['strtype']}</th>";
+                               echo "<th class=\"data\">{$lang['strformat']}</th>";
+                               echo "<th class=\"data\">{$lang['strnull']}</th><th class=\"data\">{$lang['strvalue']}</th></tr>";
                                
                                $i = 0;
                                while (!$attrs->EOF) {
                                        $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);
                                        // Set up default value if there isn't one already
                                        if (!isset($_REQUEST['values'][$attrs->f['attname']]))
-                                               $_REQUEST['values'][$attrs->f['attname']] = null;
+                                               $_REQUEST['values'][$attrs->f['attname']] = $attrs->f['adsrc'];
+                                       // Default format to 'LITERAL' if there is no default, otherwise
+                                       // default to 'EXPRESSION'...
+                                       if (!isset($_REQUEST['format'][$attrs->f['attname']]))
+                                               $_REQUEST['format'][$attrs->f['attname']] = ($attrs->f['adsrc'] === null) ? 'VALUE' : 'EXPRESSION';
                                        // Continue drawing row
                                        $id = (($i % 2) == 0 ? '1' : '2');
                                        echo "<tr>\n";
-                                       echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['attname']), "</td>";
-                                       echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['type']), "</td>";
-                                       echo "<td class=data{$id} nowrap>";
+                                       echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", htmlspecialchars($attrs->f['attname']), "</td>";
+                                       echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
+                                       echo htmlspecialchars($attrs->f['type']);
+                                       echo "<input type=\"hidden\" name=\"types[", htmlspecialchars($attrs->f['attname']), "]\" value=\"", 
+                                               htmlspecialchars($attrs->f['type']), "\" /></td>";
+                                       echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
+                                       echo "<select name=\"format[", htmlspecialchars($attrs->f['attname']), "]\">\n";
+                                       echo "<option value=\"VALUE\"", ($_REQUEST['format'][$attrs->f['attname']] == 'VALUE') ? ' selected' : '', ">{$lang['strvalue']}</option>\n";
+                                       echo "<option value=\"EXPRESSION\"", ($_REQUEST['format'][$attrs->f['attname']] == 'EXPRESSION') ? ' selected' : '', ">{$lang['strexpression']}</option>\n";
+                                       echo "</select>\n</td>\n";
+                                       echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
                                        // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)
                                        if (!$attrs->f['attnotnull'])
-                                               echo "<input type=checkbox name=\"nulls[{$attrs->f['attname']}]\"",
-                                                       isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked' : '', "></td>";
+                                               echo "<input type=\"checkbox\" name=\"nulls[", htmlspecialchars($attrs->f['attname']), "]\"",
+                                                       isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked' : '', " /></td>";
                                        else
                                                echo "&nbsp;</td>";
-                                       echo "<td class=data{$id} nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
+                                       echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $localData->printField("values[{$attrs->f['attname']}]",
                                                $_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
                                        echo "</tr>\n";
                                        $i++;
                        }
                        else echo "<p>{$lang['strnodata']}</p>\n";
 
-                       echo "<input type=hidden name=action value=insertrow>\n";
-                       echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+                       echo "<input type=\"hidden\" name=\"action\" value=\"insertrow\" />\n";
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                        echo $misc->form;
-                       echo "<p><input type=submit name=save value=\"{$lang['strsave']}\">\n";
-                       echo "<input type=submit name=saveandrepeat value=\"{$lang['strsaveandrepeat']}\">\n";
-                       echo "<input type=submit name=cancel value=\"{$lang['strcancel']}\"></p>\n";
+                       echo "<p><input type=\"submit\" name=\"save\" value=\"{$lang['strsave']}\" />\n";
+                       echo "<input type=\"submit\" name=\"saveandrepeat\" value=\"{$lang['strsaveandrepeat']}\" />\n";
+                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
                        echo "</form>\n";
                }
                else {
                        if (!isset($_POST['values'])) $_POST['values'] = array();
                        if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
 
-                       $status = $localData->insertRow($_POST['table'], $_POST['values'], $_POST['nulls']);
+                       $status = $localData->insertRow($_POST['table'], $_POST['values'], 
+                                                                                               $_POST['nulls'], $_POST['format'], $_POST['types']);
                        if ($status == 0) {
                                if (isset($_POST['save']))
                                        doDefault($lang['strrowinserted']);