* Allow SQL script upload to parse arbitrary SQL, including multiline
SQL statements
* Add support for PostgreSQL 8.1devel
+* primary key and unique key at table creation (Andreas Huber)
Bugs
* Tree Icons are displayed middle instead of top
* Fix inability to drop database using the drop link
* Stop duplicate insert on re-POST of data
* Correct last internal oid value for PostgreSQL 8.0
+* Fix bug with exporting schema for servers < 7.3
Translations
* Japanese from Tadashi Jokagi
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.256 2005/03/11 08:36:08 chriskl Exp $
+ * $Id: Postgres.php,v 1.257 2005/03/18 19:51:57 xzilla Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
* @param $colcomment An array of comments
* @param $comment Table comment
* @param $tablespace The tablespace name ('' means none/default)
+ * @param $uniquekey An Array indicating the fields that are unique (those indexes that are set)
+ * @param $primarykey An Array indicating the field used for the primarykey (those indexes that are set)
* @return 0 success
* @return -1 no fields supplied
*/
function createTable($name, $fields, $field, $type, $array, $length, $notnull,
- $default, $withoutoids, $colcomment, $tblcomment, $tablespace) {
+ $default, $withoutoids, $colcomment, $tblcomment, $tablespace,
+ $uniquekey, $primarykey) {
$this->fieldClean($name);
$this->clean($tblcomment);
// Add array qualifier if necessary
if ($array[$i] == '[]') $sql .= '[]';
// Add other qualifiers
- if (isset($notnull[$i])) $sql .= " NOT NULL";
+ if (!isset($primarykey[$i])) {
+ if (isset($uniquekey[$i])) $sql .= " UNIQUE";
+ if (isset($notnull[$i])) $sql .= " NOT NULL";
+ }
if ($default[$i] != '') $sql .= " DEFAULT {$default[$i]}";
if ($colcomment[$i] != '') $comment_sql .= "COMMENT ON COLUMN \"{$name}\".\"{$field[$i]}\" IS '{$colcomment[$i]}';\n";
if (!$found) return -1;
+ // PRIMARY KEY
+ $primarykeycolumns = array();
+ for ($i = 0; $i < $fields; $i++) {
+ if (isset($primarykey[$i])) {
+ $primarykeycolumns[] = "\"{$field[$i]}\"";
+ }
+ }
+ if (count($primarykeycolumns) > 0) {
+ $sql .= ", PRIMARY KEY (" . implode(", ", $primarykeycolumns) . ")";
+ }
+
$sql .= ")";
// WITHOUT OIDS
if ($indexes->recordCount() > 0) {
$sql .= "\n-- Indexes\n\n";
while (!$indexes->EOF) {
- $sql .= $indexes->f['idxdef'] . ";\n";
+ $sql .= $indexes->f['inddef'] . ";\n";
$indexes->moveNext();
}
/**
* List tables in a database
*
- * $Id: tables.php,v 1.70 2005/03/13 23:15:15 mr-russ Exp $
+ * $Id: tables.php,v 1.71 2005/03/18 19:51:56 xzilla Exp $
*/
// Include application functions
// Output table header
echo "<table>\n";
echo "\t<tr><th colspan=\"2\" class=\"data required\">{$lang['strcolumn']}</th><th colspan=\"2\" class=\"data required\">{$lang['strtype']}</th>";
- echo"<th class=\"data\">{$lang['strlength']}</th><th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>\n";
+ echo "<th class=\"data\">{$lang['strlength']}</th><th class=\"data\">{$lang['strnotnull']}</th>";
+ echo "<th class=\"data\">{$lang['struniquekey']}</th><th class=\"data\">{$lang['strprimarykey']}</th>";
+ echo "<th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>\n";
for ($i = 0; $i < $_REQUEST['fields']; $i++) {
if (!isset($_REQUEST['field'][$i])) $_REQUEST['field'][$i] = '';
echo "\t\t<td><input name=\"length[{$i}]\" size=\"10\" value=\"",
htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n";
echo "\t\t<td><input type=\"checkbox\" name=\"notnull[{$i}]\"", (isset($_REQUEST['notnull'][$i])) ? ' checked="checked"' : '', " /></td>\n";
+ echo "\t\t<td align=\"center\"><input type=\"checkbox\" name=\"uniquekey[{$i}]\""
+ .(isset($_REQUEST['uniquekey'][$i]) ? ' checked="checked"' :'')." /></td>\n";
+ echo "\t\t<td align=\"center\"><input type=\"checkbox\" name=\"primarykey[{$i}]\" "
+ .(isset($_REQUEST['primarykey'][$i]) ? ' checked="checked"' : '')
+ ." /></td>\n";
echo "\t\t<td><input name=\"default[{$i}]\" size=\"20\" value=\"",
htmlspecialchars($_REQUEST['default'][$i]), "\" /></td>\n";
echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"",
break;
case 3:
global $data, $lang, $_reload_browser;
-
+
if (!isset($_REQUEST['notnull'])) $_REQUEST['notnull'] = array();
+ if (!isset($_REQUEST['uniquekey'])) $_REQUEST['uniquekey'] = array();
+ if (!isset($_REQUEST['primarykey'])) $_REQUEST['primarykey'] = array();
// Default tablespace to null if it isn't set
if (!isset($_REQUEST['spcname'])) $_REQUEST['spcname'] = null;
$status = $data->createTable($_REQUEST['name'], $_REQUEST['fields'], $_REQUEST['field'],
$_REQUEST['type'], $_REQUEST['array'], $_REQUEST['length'], $_REQUEST['notnull'], $_REQUEST['default'],
- isset($_REQUEST['withoutoids']), $_REQUEST['colcomment'], $_REQUEST['tblcomment'], $_REQUEST['spcname']);
+ isset($_REQUEST['withoutoids']), $_REQUEST['colcomment'], $_REQUEST['tblcomment'], $_REQUEST['spcname'],
+ $_REQUEST['uniquekey'], $_REQUEST['primarykey']);
if ($status == 0) {
$_reload_browser = true;