allow creating domains with type length and array types
authorchriskl <chriskl>
Wed, 31 Mar 2004 07:46:39 +0000 (07:46 +0000)
committerchriskl <chriskl>
Wed, 31 Mar 2004 07:46:39 +0000 (07:46 +0000)
HISTORY
classes/database/Postgres73.php
domains.php

diff --git a/HISTORY b/HISTORY
index 741807bdaa83bc4032d0270e345d4c3d105406df..ffd1e92f36d130e7b49d48c8fb299cdb9f920d4d 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -8,6 +8,8 @@ Features
 * Add CACHE and CYCLE parameters in sequence creation
 * View, add, edit and delete comments on views, schemas and columns (Dan Boren)
 * Allow creating array columns in tables
+* Allow adding array columns to tables
+* Allow creating domains with type length and arrays
 
 Bugs
 * Fix pg_dump output for PostgreSQL 7.0.x and 7.1.x
index f958b5bc40697b2d910c811779a9b40efdcee69c..be0561a01716cce0e7c2f7c57d2e8822de2ed9bb 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres73.php,v 1.91 2004/03/12 08:56:54 chriskl Exp $
+ * $Id: Postgres73.php,v 1.92 2004/03/31 07:46:39 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1177,15 +1177,42 @@ class Postgres73 extends Postgres72 {
         * Creates a domain
         * @param $domain The name of the domain to create
         * @param $type The base type for the domain
+        * @param $length Optional type length
+        * @param $array True for array type, false otherwise
         * @param $notnull True for NOT NULL, false otherwise
         * @param $default Default value for domain     
         * @param $check A CHECK constraint if there is one
         * @return 0 success
         */
-       function createDomain($domain, $type, $notnull, $default, $check) {
+       function createDomain($domain, $type, $length, $array, $notnull, $default, $check) {
                $this->fieldClean($domain);
                
-               $sql = "CREATE DOMAIN \"{$domain}\" AS {$type}";
+               $sql = "CREATE DOMAIN \"{$domain}\" AS ";
+
+               if ($length == '')
+                       $sql .= $type;
+               else {
+                       switch ($type) {
+                               // Have to account for weird placing of length for with/without
+                               // time zone types
+                               case 'timestamp with time zone':
+                               case 'timestamp without time zone':
+                                       $qual = substr($type, 9);
+                                       $sql .= "timestamp({$length}){$qual}";
+                                       break;
+                               case 'time with time zone':
+                               case 'time without time zone':
+                                       $qual = substr($type, 4);
+                                       $sql .= "time({$length}){$qual}";
+                                       break;
+                               default:
+                                       $sql .= "{$type}({$length})";
+                       }
+               }
+               
+               // Add array qualifier, if requested
+               if ($array) $sql .= '[]';
+               
                if ($notnull) $sql .= ' NOT NULL';
                if ($default != '') $sql .= " DEFAULT {$default}";
                if ($this->hasDomainConstraints() && $check != '') $sql .= " CHECK ({$check})";
index d50dfd87a6c56134c94524fa0b9ba61380560c19..3a103f875634c380c22042bd344de7f81f01ac09 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage domains in a database
         *
-        * $Id: domains.php,v 1.8 2003/12/30 03:09:29 chriskl Exp $
+        * $Id: domains.php,v 1.9 2004/03/31 07:46:39 chriskl Exp $
         */
 
        // Include application functions
                
                if (!isset($_POST['domname'])) $_POST['domname'] = '';
                if (!isset($_POST['domtype'])) $_POST['domtype'] = '';
+               if (!isset($_POST['domlength'])) $_POST['domlength'] = '';
+               if (!isset($_POST['domarray'])) $_POST['domarray'] = '';
                if (!isset($_POST['domdefault'])) $_POST['domdefault'] = '';
                if (!isset($_POST['domcheck'])) $_POST['domcheck'] = '';
 
                                $misc->printVal($types->f[$data->typFields['typname']]), "</option>\n";
                        $types->moveNext();
                }
-               echo "</select>\n";             
-               echo "</td></tr>\n";
+               echo "</select>\n";
+               
+               // Type length
+               echo "<input type=\"text\" size=\"4\" name=\"domlength\" value=\"", htmlspecialchars($_POST['domlength']), "\" />";
+
+               // Output array type selector
+               echo "<select name=\"domarray\">\n";
+               echo "<option value=\"\"", ($_POST['domarray'] == '') ? ' selected="selected"' : '', "></option>\n";
+               echo "<option value=\"[]\"", ($_POST['domarray'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
+               echo "</select></td></tr>\n";
+
                echo "<tr><th class=\"data left\">{$lang['strnotnull']}</th>\n";
                echo "<td class=\"data1\"><input type=\"checkbox\" name=\"domnotnull\"", 
                        (isset($_POST['domnotnull']) ? ' checked="checked"' : ''), " /></td></tr>\n";
                // Check that they've given a name and a definition
                if ($_POST['domname'] == '') doCreate($lang['strdomainneedsname']);
                else {           
-                       $status = $data->createDomain($_POST['domname'], $_POST['domtype'], 
+                       $status = $data->createDomain($_POST['domname'], $_POST['domtype'], $_POST['domlength'], $_POST['domarray'] != '',
                                                                                                                                isset($_POST['domnotnull']), $_POST['domdefault'], $_POST['domcheck']);
                        if ($status == 0)
                                doDefault($lang['strdomaincreated']);