From bf13cdad0ef93a408b37fb7f1bff7d5629906ba0 Mon Sep 17 00:00:00 2001 From: chriskl Date: Wed, 31 Mar 2004 07:46:39 +0000 Subject: [PATCH] allow creating domains with type length and array types --- HISTORY | 2 ++ classes/database/Postgres73.php | 33 ++++++++++++++++++++++++++++++--- domains.php | 19 +++++++++++++++---- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/HISTORY b/HISTORY index 741807bd..ffd1e92f 100644 --- 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 diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index f958b5bc..be0561a0 100644 --- a/classes/database/Postgres73.php +++ b/classes/database/Postgres73.php @@ -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})"; diff --git a/domains.php b/domains.php index d50dfd87..3a103f87 100644 --- a/domains.php +++ b/domains.php @@ -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 @@ -278,6 +278,8 @@ 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'] = ''; @@ -301,8 +303,17 @@ $misc->printVal($types->f[$data->typFields['typname']]), "\n"; $types->moveNext(); } - echo "\n"; - echo "\n"; + echo "\n"; + + // Type length + echo ""; + + // Output array type selector + echo "\n"; + echo "{$lang['strnotnull']}\n"; echo "\n"; @@ -333,7 +344,7 @@ // 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']); -- 2.39.5