+ endterm="sql-update-title">.)
1998-04-15
-
- SQL92
-
- ALTER TABLE/RENAME
- is a
Postgres language extension.
-
+
SQL92
+ The ADD COLUMN form is compliant with the exception that
+ it does not support defaults and constraints, as explained above.
+ The ALTER COLUMN form is in full compliance.
+
- SQL92 specifies some additional capabilities for ALTER TABLE
- statement which are not yet directly supported by
-
-
-
-
-
-
-ALTER TABLE table ALTER [
- COLUMN ] column
- SET DEFAULT default
-ALTER TABLE table ALTER [
- COLUMN ] column
- ADD [ CONSTRAINT
>constrain> ]
- class="PARAMETER">table-constraint
-
-
-
- Puts the default value or constraint specified into the
- definition of column in the table.
- See CREATE TABLE for the
- syntax of the default and table-constraint clauses.
- If a default clause already exists, it will be replaced by
- the new definition. If any constraints on this column already
- exist, they will be retained using a boolean AND with the new
- constraint.
-
-
- Currently, to set new default constraints on an existing column
- the table must be recreated and reloaded:
-
-CREATE TABLE temp AS SELECT * FROM distributors;
-DROP TABLE distributors;
-CREATE TABLE distributors (
- did DECIMAL(3) DEFAULT 1,
- name VARCHAR(40) NOT NULL,
- city VARCHAR(30)
-);
-INSERT INTO distributors SELECT * FROM temp;
-DROP TABLE temp;
-
-
-
-
+ SQL92 specifies some additional capabilities for ALTER TABLE
+ statement which are not yet directly supported by
PostgreSQL:
-
-
-
-ALTER TABLE table
- DROP DEFAULT default
-ALTER TABLE table
- DROP CONSTRAINT constraint { RESTRICT | CASCADE }
+
+
+
+
+ALTER TABLE table ADD table constraint definition
+ALTER TABLE table DROP CONSTRAINT constraint { RESTRICT | CASCADE }
- Removes the default value specified by default or the rule
- specified by constraint from the definition of a table.
- If RESTRICT is specified only a constraint with no dependent
- constraints can be destroyed.
- If CASCADE is specified, Any constraints that are dependent on
- this constraint are also dropped.
+ Adds or removes a table constraint (such as a check constraint,
+ unique constraint, or foreign key constraint). To create
+ or remove a unique constraint, create or drop a unique index,
+ respectively (see ).
+ To change other kinds of constraints you need to recreate
+ and reload the table, using other parameters to the
+
+ command.
-
- Currently, to remove a default value or constraints on an
- existing column the table must be recreated and reloaded:
-
+ For example, to drop any constraints on a table distributors:
CREATE TABLE temp AS SELECT * FROM distributors;
DROP TABLE distributors;
-ALTER TABLE table
- DROP [ COLUMN ] column { RESTRICT | CASCADE }
+ALTER TABLE table DROP [ COLUMN ] column { RESTRICT | CASCADE }
Removes a column from a table.
- If RESTRICT is specified only a column with no dependent
- objects can be destroyed.
- If CASCADE is specified, all objects that are dependent on
- this column are also dropped.
-
-
Currently, to remove an existing column the table must be
recreated and reloaded:
-
CREATE TABLE temp AS SELECT did, city FROM distributors;
DROP TABLE distributors;
+
+
+ The clauses to rename columns and tables are
PostgreSQL
+ extensions. SQL92 does not provide for them.
+
+
-NOTICE: BeginTransactionBlock and not in default state
+NOTICE: BEGIN: already a transaction in progress
- By default,
Postgres executes transactions
+ By default,
PostgreSQL executes transactions
in unchained mode
(also known as autocommit
in other database
systems).
The default transaction isolation level in
is READ COMMITTED, where queries inside the transaction see only changes
committed before query execution. So, you have to use
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
- If the transaction is committed,
Postgres
+ If the transaction is committed,
PostgreSQL
will ensure either that all updates are done or else that none of
them are done. Transactions have the standard
ACID
(atomic, consistent, isolatable, and durable) property.
Notes
- The keyword TRANSACTION is just a cosmetic alternative to WORK.
- Neither keyword need be specified.
-
-
Refer to
for further information
BEGIN
- is a
Postgres language extension.
+ is a
PostgreSQL language extension.
There is no explicit BEGIN
transaction initiation is always implicit and it terminates either
+ Incidentally, the BEGIN keyword is used for a different
+ purpose in embedded SQL. You are advised to be careful about the transaction
+ semantics when porting database applications.
+
+
SQL92 also requires SERIALIZABLE to be the default
transaction isolation level.
-END
+COMMIT
-NOTICE EndTransactionBlock and not inprogress/abort state
+NOTICE: COMMIT: no transaction in progress
SQL92
- Full compatibility.
+
SQL92 only specifies the two forms
COMMIT
+ and COMMIT WORK. Otherwise full compatibility.
-END
+COMMIT
-NOTICE EndTransactionBlock and not inprogress/abort state
+NOTICE: COMMIT: no transaction in progress
synonym for
.
extension which provides functionality equivalent to
.
%#
-
If the username is postgres, a
+
If the current user is a database superuser, then a
#
, otherwise a >
.
Before starting up in interactive mode,
psql attempts
- to read and execute the files /etc/psqlrc and
- $HOME/.psqlrc. They could be used to set up the client or
- the server to taste (using the \set and SET
- commands).
+ to read and execute commands from the file $HOME/.psqlrc. It
+ could be used to set up the client or the server to taste (using the \set
+ and SET commands).
psql supports the readline and history libraries for
convenienent line editing and retrieval. The command history is stored in a file
- named .psqlrc in your home directory and is reloaded when
+ named .psql_history in your home directory and is reloaded when
Tab-completion is also supported, although
the completion logic makes no claim to be an
SQL parser.
Notice the changing prompt.
testdb=> CREATE TABLE my_table (
-testdb-> first int4 not null default 0,
+testdb-> first integer not null default 0,
testdb-> second text
testdb-> );
CREATE
Now look at the table definition again:
testdb=> \d my_table
- Table "my_table"
- Attribute | Type | Info
------------+------+--------------------
- first | int4 | not null default 0
- second | text |
+ Table "my_table"
+ Attribute | Type | Modifier
+-----------+---------+--------------------
+ first | integer | not null default 0
+ second | text |
At this point you decide to change the prompt to something more
-NOTICE: UserAbortTransactionBlock and not in in-progress state
-ABORT
+NOTICE: ROLLBACK: no transaction in progress
Notes
- The keywords WORK and TRANSACTION are noise and can be omitted.
-
-
Use
to successfully terminate a transaction.
SQL92
- Full compatibility. The TRANSACTION keyword is a
+
SQL92 only specifies the two forms
ROLLBACK
+ and ROLLBACK WORK. Otherwise full compatibility.
1999-07-20
-UPDATE table SET R">colle> = expression [, ...]
+UPDATE table SET colle> = expression [, ...]
[ FROM fromlist ]
[ WHERE condition ]
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.59 2000/01/26 05:56:04 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.60 2000/01/29 16:58:29 petere Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
return;
if (s->blockState != TBLOCK_DEFAULT)
- elog(NOTICE, "BeginTransactionBlock and not in default state ");
+ elog(NOTICE, "BEGIN: already a transaction in progress");
/* ----------------
* set the current transaction block state information
* default state.
* ----------------
*/
- elog(NOTICE, "EndTransactionBlock and not inprogress/abort state ");
+ elog(NOTICE, "COMMIT: no transaction in progress");
s->blockState = TBLOCK_ENDABORT;
}
/* ----------------
* this case should not be possible, because it would mean
- * the user entered an "abort" from outside a transaction block.
+ * the user entered a "rollback" from outside a transaction block.
* So we print an error message, abort the transaction and
* enter the "ENDABORT" state so we will end up in the default
* state after the upcoming CommitTransactionCommand().
* ----------------
*/
- elog(NOTICE, "UserAbortTransactionBlock and not in in-progress state");
+ elog(NOTICE, "ROLLBACK: no transaction in progress");
AbortTransaction();
s->blockState = TBLOCK_ENDABORT;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.66 2000/01/26 05:56:13 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.67 2000/01/29 16:58:34 petere Exp $
*
* NOTES
* The PortalExecutorHeapMemory crap needs to be eliminated
Relation idescs[Num_pg_attr_indices];
Relation ridescs[Num_pg_class_indices];
bool hasindex;
-// List *rawDefaults = NIL;
/*
* permissions checking. this would normally be done in utility.c,
/*
* XXX is the following check sufficient?
*/
- if (((Form_pg_class) GETSTRUCT(reltup))->relkind == RELKIND_INDEX)
+ if (((Form_pg_class) GETSTRUCT(reltup))->relkind != RELKIND_RELATION)
{
- elog(ERROR, "ALTER TABLE: index relation \"%s\" not changed",
+ elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table",
relationName);
}
0, 0);
if (HeapTupleIsValid(tup))
- elog(ERROR, "ALTER TABLE: column name \"%s\" already exists in relation \"%s\"",
+ elog(ERROR, "ALTER TABLE: column name \"%s\" already exists in table \"%s\"",
colDef->colname, relationName);
/*
/* keep the system catalog indices current */
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
CatalogIndexInsert(irelations, Num_pg_attr_indices, attr_rel, newtuple);
- CatalogCloseIndices(Num_pg_attrdef_indices, irelations);
+ CatalogCloseIndices(Num_pg_attr_indices, irelations);
/* get rid of actual default definition */
drop_default(myrelid, attnum);
}
- else
- elog(NOTICE, "ALTER TABLE: there was no default on column \"%s\" of relation \"%s\"",
- colName, relationName);
+
heap_endscan(scan);
heap_close(attr_rel, NoLock);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.55 2000/01/26 05:56:13 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.56 2000/01/29 16:58:34 petere Exp $
*
*-------------------------------------------------------------------------
*/
* ----------------
*/
-static int checkAttrExists(char *attributeName,
- char *attributeType, List *schema);
+static bool checkAttrExists(const char *attributeName,
+ const char *attributeType, List *schema);
static List *MergeAttributes(List *schema, List *supers, List **supconstr);
static void StoreCatalogInheritance(Oid relationId, List *supers);
if (!strcmp(coldef->colname, restdef->colname))
{
- elog(ERROR, "attribute '%s' duplicated",
+ elog(ERROR, "CREATE TABLE: attribute \"%s\" duplicated",
coldef->colname);
}
}
{
if (!strcmp(strVal(lfirst(entry)), strVal(lfirst(rest))))
{
- elog(ERROR, "relation '%s' duplicated",
+ elog(ERROR, "CREATE TABLE: inherited relation \"%s\" duplicated",
strVal(lfirst(entry)));
}
}
tupleDesc = RelationGetDescr(relation);
constr = tupleDesc->constr;
- /* XXX shouldn't this test be stricter? No indexes, for example? */
- if (relation->rd_rel->relkind == 'S')
- elog(ERROR, "MergeAttr: Can't inherit from sequence superclass '%s'", name);
+ if (relation->rd_rel->relkind != RELKIND_RELATION)
+ elog(ERROR, "CREATE TABLE: inherited relation \"%s\" is not a table", name);
for (attrno = relation->rd_rel->relnatts - 1; attrno >= 0; attrno--)
{
* check validity
*
*/
- if (checkAttrExists(attributeName, attributeType, inhSchema) ||
- checkAttrExists(attributeName, attributeType, schema))
- {
+ if (checkAttrExists(attributeName, attributeType, schema))
+ elog(ERROR, "CREATE TABLE: attribute \"%s\" already exists in inherited schema",
+ attributeName);
+ if (checkAttrExists(attributeName, attributeType, inhSchema))
/*
* this entry already exists
*/
continue;
- }
/*
* add an entry to the schema
heap_close(relation, RowExclusiveLock);
}
+
+
/*
- * returns 1 if attribute already exists in schema, 0 otherwise.
+ * returns true if attribute already exists in schema, false otherwise.
*/
-static int
-checkAttrExists(char *attributeName, char *attributeType, List *schema)
+static bool
+checkAttrExists(const char *attributeName, const char *attributeType, List *schema)
{
List *s;
{
ColumnDef *def = lfirst(s);
- if (!strcmp(attributeName, def->colname))
+ if (strcmp(attributeName, def->colname)==0)
{
-
/*
* attribute exists. Make sure the types are the same.
*/
if (strcmp(attributeType, def->typename->name) != 0)
- {
- elog(ERROR, "%s and %s conflict for %s",
- attributeType, def->typename->name, attributeName);
- }
- return 1;
+ elog(ERROR, "CREATE TABLE: attribute \"%s\" type conflict (%s and %s)",
+ attributeName, attributeType, def->typename->name);
+ return true;
}
}
- return 0;
+ return false;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.136 2000/01/27 18:11:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.137 2000/01/29 16:58:37 petere Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
$$ = (Node *)n;
}
/* ALTER TABLE DROP [COLUMN] {RESTRICT|CASCADE} */
- | ALTER TABLE relation_name opt_inh_star DROP opt_column ColId /* drop_behavior */
+ | ALTER TABLE relation_name opt_inh_star DROP opt_column ColId drop_behavior
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'D';
n->relname = $3;
n->inh = $4;
n->name = $7;
- /* n->behavior = $8; */
+ n->behavior = $8;
$$ = (Node *)n;
}
/* ALTER TABLE ADD CONSTRAINT ... */
| ALTER TABLE relation_name opt_inh_star DROP CONSTRAINT name drop_behavior
{
AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'X';
+ n->subtype = 'X';
n->relname = $3;
n->inh = $4;
n->name = $7;
;
alter_column_action:
- SET DEFAULT a_expr_or_null { $$ = $3; }
+ SET DEFAULT a_expr { $$ = $3; }
+ | SET DEFAULT NULL_P { $$ = NULL; }
| DROP DEFAULT { $$ = NULL; }
;
*
* Transactions:
*
- * abort transaction
- * (ABORT)
- * begin transaction
- * (BEGIN)
- * end transaction
- * (END)
+ * BEGIN / COMMIT / ROLLBACK
+ * (also older versions END / ABORT)
*
*****************************************************************************/
TransactionStmt: ABORT_TRANS opt_trans
{
TransactionStmt *n = makeNode(TransactionStmt);
- n->command = ABORT_TRANS;
+ n->command = ROLLBACK;
$$ = (Node *)n;
}
| BEGIN_TRANS opt_trans
| COMMIT opt_trans
{
TransactionStmt *n = makeNode(TransactionStmt);
- n->command = END_TRANS;
+ n->command = COMMIT;
$$ = (Node *)n;
}
| END_TRANS opt_trans
{
TransactionStmt *n = makeNode(TransactionStmt);
- n->command = END_TRANS;
+ n->command = COMMIT;
$$ = (Node *)n;
}
| ROLLBACK opt_trans
{
TransactionStmt *n = makeNode(TransactionStmt);
- n->command = ABORT_TRANS;
+ n->command = ROLLBACK;
$$ = (Node *)n;
}
;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.81 2000/01/26 05:57:07 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.82 2000/01/29 16:58:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
{ \
if (IsAbortedTransactionBlockState()) \
{ \
- elog(NOTICE, "(transaction aborted): %s", \
- "all queries ignored until end of transaction block"); \
+ elog(NOTICE, "current transaction is aborted, " \
+ "queries ignored until end of transaction block"); \
commandTag = "*ABORT STATE*"; \
break; \
} \
BeginTransactionBlock();
break;
- case END_TRANS:
- PS_SET_STATUS(commandTag = "END");
+ case COMMIT:
+ PS_SET_STATUS(commandTag = "COMMIT");
EndTransactionBlock();
break;
- case ABORT_TRANS:
- PS_SET_STATUS(commandTag = "ABORT");
+ case ROLLBACK:
+ PS_SET_STATUS(commandTag = "ROLLBACK");
UserAbortTransactionBlock();
break;
}
{
RenameStmt *stmt = (RenameStmt *) parsetree;
- PS_SET_STATUS(commandTag = "RENAME");
+ PS_SET_STATUS(commandTag = "ALTER");
CHECK_IF_ABORTED();
relname = stmt->relname;
if (!allowSystemTableMods && IsSystemRelationName(relname))
- elog(ERROR, "class \"%s\" is a system catalog",
+ elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
relname);
#ifndef NO_SECURITY
if (!pg_ownercheck(userName, relname, RELNAME))
- elog(ERROR, "you do not own class \"%s\"",
- relname);
+ elog(ERROR, "permission denied");
#endif
/* ----------------
{
AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
- PS_SET_STATUS(commandTag = "ALTER TABLE");
+ PS_SET_STATUS(commandTag = "ALTER");
CHECK_IF_ABORTED();
/*
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.82 2000/01/20 21:51:05 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.83 2000/01/29 16:58:42 petere Exp $
#
#-------------------------------------------------------------------------
-E*)
MULTIBYTE=`echo $1 | sed 's/^-E//'`
;;
+ -*)
+ echo "$CMDNAME: invalid option: $1"
+ echo "Try -? for help."
+ exit 1
+ ;;
*)
PGDATA=$1
;;
echo " $CMDNAME [options] datadir"
echo
echo "Options:"
- echo " [-D, --pgdata] Location for this database"
+ echo " [-D, --pgdata] Location for this database"
echo " -W, --pwprompt Prompt for a password for the new superuser's"
if [ -n "$MULTIBYTE" ]
then
- echo " -e, --encoding Set the default multibyte encoding for new databases"
+ echo " -E, --encoding Set the default multibyte encoding for new databases"
fi
echo " -i, --sysid Database sysid for the superuser"
echo "Less commonly used options: "
- echo " -L, --pglib Where to find the input files (should happend automatically"
+ echo " -L, --pglib Where to find the input files"
echo " -t, --template Re-initialize template database only"
echo " -d, --debug Generate lots of debugging output"
echo " -n, --noclean Do not clean up after errors"
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.140 2000/01/27 05:33:49 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.141 2000/01/29 16:58:44 petere Exp $
*
*
puts("pg_dump (PostgreSQL) " PG_RELEASE "." PG_VERSION "." PG_SUBVERSION);
puts("Portions Copyright (c) 1996-2000, PostgreSQL, Inc");
puts("Portions Copyright (C) 1996 Regents of the University of California");
- puts("Read the file COPYING to see the usage and distribution terms.");
+ puts("Read the file COPYRIGHT to see the usage and distribution terms.");
}
case '?':
/* getopt returns '?' on unknown argument. That's not
quite what we want */
- if (strcmp(argv[optind-1], "-?")==0)
+ if (strcmp(argv[optind-1], "-?")==0 || strcmp(argv[optind-1], "--help")==0)
{
help(progname);
exit(1);
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.15 2000/01/23 01:27:37 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.16 2000/01/29 16:58:48 petere Exp $
*/
#include
#include "command.h"
switch (cmd[1])
{
case '\0':
- case '?':
+ case '+':
if (options[0])
success = describeTableDetails(options[0], show_verbose);
else
SetVariable(pset.vars, "HOST", PQhost(pset.db));
SetVariable(pset.vars, "PORT", PQport(pset.db));
+ pset.issuper = test_superuser(PQuser(pset.db));
+
return success;
}
+/*
+ * Test if the given user is a database superuser.
+ * (Used to set up the prompt right.)
+ */
+bool
+test_superuser(const char * username)
+{
+ PGresult *res;
+ char buf[64 + NAMEDATALEN];
+ bool answer;
+
+ if (!username)
+ return false;
+
+ sprintf(buf, "SELECT usesuper FROM pg_user WHERE usename = '%.*s'", NAMEDATALEN, username);
+ res = PSQLexec(buf);
+
+ answer =
+ (PQntuples(res)>0 && PQnfields(res)>0
+ && !PQgetisnull(res,0,0)
+ && PQgetvalue(res,0,0)
+ && strcmp(PQgetvalue(res,0,0), "t")==0);
+ PQclear(res);
+ return answer;
+}
+
+
+
/*
* do_edit -- handler for \e
*
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/command.h,v 1.6 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.h,v 1.7 2000/01/29 16:58:48 petere Exp $
*/
#ifndef COMMAND_H
#define COMMAND_H
bool
process_file(char *filename);
+bool
+test_superuser(const char * username);
+
bool
do_pset(const char *param,
const char *value,
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.10 2000/01/19 20:08:33 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.11 2000/01/29 16:58:48 petere Exp $
*/
#include
#include "common.h"
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.4 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.5 2000/01/29 16:58:48 petere Exp $
*/
#ifndef COMMON_H
#define COMMON_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.8 2000/01/21 04:21:12 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.9 2000/01/29 16:58:48 petere Exp $
*/
#include
#include "copy.h"
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.h,v 1.5 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.h,v 1.6 2000/01/29 16:58:48 petere Exp $
*/
#ifndef COPY_H
#define COPY_H
-#!/usr/bin/perl
+#! /usr/bin/perl
+#################################################################
+# create_help.pl -- converts SGML docs to internal psql help
#
-# This script automatically generates the help on SQL in psql from the
-# SGML docs. So far the format of the docs was consistent enough that
-# this worked, but this here is my no means an SGML parser.
+# Copyright 2000 by PostgreSQL Global Development Group
#
-# It might be a good idea that this is just done once before distribution
-# so people that don't have the docs or have slightly messed up docs or
-# don't have perl, etc. won't have to bother.
+# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.3 2000/01/29 16:58:48 petere Exp $
+#################################################################
+
+#
+# This script automatically generates the help on SQL in psql from
+# the SGML docs. So far the format of the docs was consistent
+# enough that this worked, but this here is my no means an SGML
+# parser.
#
# Call: perl create_help.pl sql_help.h
-# (Do not rely on this script to be executable.)
-# The name of the header file doesn't matter to this script, but it sure
-# does matter to the rest of the source.
+# The name of the header file doesn't matter to this script, but it
+# sure does matter to the rest of the source.
#
# A rule for this is also in the psql makefile.
#
print OUT
"/*
- * This file is automatically generated from the SGML documentation.
- * Direct changes here will be overwritten.
+ * *** Do not change this file directly. Changes will be overwritten. ***
+ *
+ * This file was generated by
+ * $^X $0 $outputfile
+ * from the DocBook documentation in
+ * $docdir
+ *
*/
+
#ifndef $define
#define $define
print OUT " { \"$cmdname\",\n \"$cmddesc\",\n \"$cmdsynopsis\" },\n\n";
}
else {
- print STDERR "Couldn't parse file '$file'. (N='$cmdname' D='$cmddesc')\n";
+ print STDERR "$0: parsing file '$file' failed at or near line $. (N='$cmdname' D='$cmddesc')\n";
}
}
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.14 2000/01/20 15:29:20 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.15 2000/01/29 16:58:48 petere Exp $
*/
#include
#include "describe.h"
tmp = malloc(size);
if (!tmp)
{
- perror("malloc");
+ psql_error("out of memory");
exit(EXIT_FAILURE);
}
return tmp;
/* truncate table name */
if (strlen(name) > NAMEDATALEN) {
- char *my_name = xmalloc(NAMEDATALEN+1);
- strncpy(my_name, name, NAMEDATALEN);
- my_name[NAMEDATALEN] = '\0';
- name = my_name;
+ char *my_name = xmalloc(NAMEDATALEN+1);
+ strncpy(my_name, name, NAMEDATALEN);
+ my_name[NAMEDATALEN] = '\0';
+ name = my_name;
}
/* Get general table info */
sprintf(buf,
- "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules\n"
- "FROM pg_class WHERE relname='%s'",
- name);
+ "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules\n"
+ "FROM pg_class WHERE relname='%s'",
+ name);
res = PSQLexec(buf);
if (!res)
- return false;
+ return false;
/* Did we get anything? */
if (PQntuples(res) == 0)
headers[1] = "Type";
cols = 2;
- if (tableinfo.relkind == 'r' || tableinfo.relkind == 's')
+ if (tableinfo.relkind == 'r')
{
- cols++;
- headers[cols-1] = "Extra";
+ cols++;
+ headers[cols-1] = "Modifier";
}
if (desc)
{
- cols++;
+ cols++;
headers[cols-1] = "Description";
}
/* Check if table is a view */
if (tableinfo.hasrules) {
- PGresult *result;
- sprintf(buf, "SELECT definition FROM pg_views WHERE viewname = '%s'", name);
- result = PSQLexec(buf);
- if (!result)
- {
- PQclear(res);
- PQclear(result);
- return false;
- }
-
- if (PQntuples(result) > 0)
- view_def = xstrdup(PQgetvalue(result, 0, 0));
- PQclear(result);
+ PGresult *result;
+ sprintf(buf, "SELECT definition FROM pg_views WHERE viewname = '%s'", name);
+ result = PSQLexec(buf);
+ if (!result)
+ {
+ PQclear(res);
+ PQclear(result);
+ return false;
+ }
+
+ if (PQntuples(result) > 0)
+ view_def = xstrdup(PQgetvalue(result, 0, 0));
+ PQclear(result);
}
for (i = 0; i < PQntuples(res); i++)
{
int4 attypmod = atoi(PQgetvalue(res, i, 3));
- const char *attype = PQgetvalue(res, i, 1);
+ const char *attype = PQgetvalue(res, i, 1);
+ const char *typename;
+ bool isarray = false;
/* Name */
cells[i * cols + 0] = (char *)PQgetvalue(res, i, 0); /* don't free this afterwards */
/* Type */
- /* (convert some internal type names to "readable") */
+ if (attype[0] == '_')
+ {
+ isarray = true;
+ attype++;
+ }
+ /* (convert some internal type names to SQL'ish) */
+ if (strcmp(attype, "bpchar")==0)
+ typename = "char";
+ else if (strcmp(attype, "int2")==0)
+ typename = "smallint";
+ else if (strcmp(attype, "int4")==0)
+ typename = "integer";
+ else if (strcmp(attype, "int8")==0)
+ typename = "bigint";
+ else if (strcmp(attype, "bool")==0)
+ typename = "boolean";
+ else
+ typename = attype;
+ /* more might need to be added when date/time types are sorted out */
+
cells[i * cols + 1] = xmalloc(NAMEDATALEN + 16);
- if (strcmp(attype, "bpchar") == 0)
- sprintf(cells[i * cols + 1], "char(%d)", attypmod != -1 ? attypmod - VARHDRSZ : 0);
- else if (strcmp(attype, "varchar") == 0)
- sprintf(cells[i * cols + 1], "varchar(%d)", attypmod != -1 ? attypmod - VARHDRSZ : 0);
- else if (strcmp(attype, "numeric") == 0)
+ if (strcmp(typename, "char") == 0)
+ sprintf(cells[i * cols + 1], "char(%d)", attypmod != -1 ? attypmod - VARHDRSZ : 1);
+ else if (strcmp(typename, "varchar") == 0)
+ sprintf(cells[i * cols + 1], "varchar(%d)", attypmod != -1 ? attypmod - VARHDRSZ : 1);
+ else if (strcmp(typename, "numeric") == 0)
sprintf(cells[i * cols + 1], "numeric(%d,%d)", ((attypmod - VARHDRSZ) >> 16) & 0xffff,
(attypmod - VARHDRSZ) & 0xffff);
- else if (attype[0] == '_')
- sprintf(cells[i * cols + 1], "%s[]", attype + 1);
else
- strcpy(cells[i * cols + 1], attype);
+ strcpy(cells[i * cols + 1], typename);
+
+ if (isarray)
+ strcat(cells[i * cols + 1], "[]");
/* Extra: not null and default */
/* (I'm cutting off the 'default' string at 128) */
- if (tableinfo.relkind == 'r' || tableinfo.relkind == 's')
- {
- cells[i * cols + 2] = xmalloc(128 + 128);
- cells[i * cols + 2][0] = '\0';
- if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
- strcat(cells[i * cols + 2], "not null");
-
- /* handle "default" here */
- if (strcmp(PQgetvalue(res, i, 5), "t") == 0)
- {
- PGresult *result;
-
- sprintf(buf, "SELECT substring(d.adsrc for 128) FROM pg_attrdef d, pg_class c\n"
- "WHERE c.relname = '%s' AND c.oid = d.adrelid AND d.adnum = %s",
- name, PQgetvalue(res, i, 6));
-
- result = PSQLexec(buf);
- if (!result)
- error = true;
- else
- {
- if (cells[i * cols + 2][0])
- strcat(cells[i * cols + 2], " ");
- strcat(cells[i * cols + 2], "default ");
- strcat(cells[i * cols + 2], PQgetvalue(result, 0, 0));
- PQclear(result);
- }
- }
- }
-
- if (error)
- break;
-
+ if (tableinfo.relkind == 'r')
+ {
+ cells[i * cols + 2] = xmalloc(128 + 128);
+ cells[i * cols + 2][0] = '\0';
+ if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
+ strcat(cells[i * cols + 2], "not null");
+
+ /* handle "default" here */
+ if (strcmp(PQgetvalue(res, i, 5), "t") == 0)
+ {
+ PGresult *result;
+
+ sprintf(buf, "SELECT substring(d.adsrc for 128) FROM pg_attrdef d, pg_class c\n"
+ "WHERE c.relname = '%s' AND c.oid = d.adrelid AND d.adnum = %s",
+ name, PQgetvalue(res, i, 6));
+
+ result = PSQLexec(buf);
+ if (!result)
+ error = true;
+ else
+ {
+ if (cells[i * cols + 2][0])
+ strcat(cells[i * cols + 2], " ");
+ strcat(cells[i * cols + 2], "default ");
+ strcat(cells[i * cols + 2], PQgetvalue(result, 0, 0));
+ PQclear(result);
+ }
+ }
+ }
+
+ if (error)
+ break;
+
/* Description */
if (desc)
cells[i * cols + cols-1] = (char*)PQgetvalue(res, i, 7);
}
/* Make title */
- title = xmalloc(20 + strlen(name));
+ title = xmalloc(22 + strlen(name));
switch (tableinfo.relkind) {
- case 'r':
- if (view_def)
- sprintf(title, "View \"%s\"", name);
- else
- sprintf(title, "Table \"%s\"", name);
- break;
- case 'S':
- sprintf(title, "Sequence \"%s\"", name);
- break;
- case 'i':
- sprintf(title, "Index \"%s\"", name);
- break;
- case 's':
- sprintf(title, "System table \"%s\"", name);
- break;
- default:
- sprintf(title, "?%c?", tableinfo.relkind);
+ case 'r':
+ if (view_def)
+ sprintf(title, "View \"%s\"", name);
+ else
+ sprintf(title, "Table \"%s\"", name);
+ break;
+ case 'S':
+ sprintf(title, "Sequence \"%s\"", name);
+ break;
+ case 'i':
+ sprintf(title, "Index \"%s\"", name);
+ break;
+ case 's':
+ sprintf(title, "Special relation \"%s\"", name);
+ break;
+ default:
+ sprintf(title, "?%c?", tableinfo.relkind);
}
/* Make footers */
/* Information about the index */
if (tableinfo.relkind == 'i')
{
- PGresult * result;
-
- sprintf(buf, "SELECT i.indisunique, i.indisprimary, a.amname\n"
- "FROM pg_index i, pg_class c, pg_am a\n"
- "WHERE i.indexrelid = c.oid AND c.relname = '%s' AND c.relam = a.oid",
- name);
-
- result = PSQLexec(buf);
- if (!result)
- error = true;
- else
- {
- footers = xmalloc(2 * sizeof(*footers));
- footers[0] = xmalloc(NAMEDATALEN + 32);
- sprintf(footers[0], "%s%s",
- strcmp(PQgetvalue(result, 0, 0), "t")==0 ? "unique " : "",
- PQgetvalue(result, 0, 2)
- );
- if (strcmp(PQgetvalue(result, 0, 1), "t")==0)
- strcat(footers[0], " (primary key)");
- footers[1] = NULL;
- }
+ PGresult * result;
+
+ sprintf(buf, "SELECT i.indisunique, i.indisprimary, a.amname\n"
+ "FROM pg_index i, pg_class c, pg_am a\n"
+ "WHERE i.indexrelid = c.oid AND c.relname = '%s' AND c.relam = a.oid",
+ name);
+
+ result = PSQLexec(buf);
+ if (!result)
+ error = true;
+ else
+ {
+ footers = xmalloc(2 * sizeof(*footers));
+ footers[0] = xmalloc(NAMEDATALEN + 32);
+ sprintf(footers[0], "%s%s",
+ strcmp(PQgetvalue(result, 0, 0), "t")==0 ? "unique " : "",
+ PQgetvalue(result, 0, 2)
+ );
+ if (strcmp(PQgetvalue(result, 0, 1), "t")==0)
+ strcat(footers[0], " (primary key)");
+ footers[1] = NULL;
+ }
}
/* Information about the view */
else if (tableinfo.relkind == 'r' && view_def)
/* Information about the table */
else if (tableinfo.relkind == 'r')
{
- PGresult *result1=NULL, *result2=NULL, *result3=NULL, *result4=NULL;
- int index_count=0, constr_count=0, rule_count=0, trigger_count=0;
- int count_footers=0;
+ PGresult *result1=NULL, *result2=NULL, *result3=NULL, *result4=NULL;
+ int index_count=0, constr_count=0, rule_count=0, trigger_count=0;
+ int count_footers=0;
/* count indices */
- if (!error && tableinfo.hasindex)
- {
- sprintf(buf, "SELECT c2.relname\n"
- "FROM pg_class c, pg_class c2, pg_index i\n"
- "WHERE c.relname = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
- "ORDER BY c2.relname",
- name);
- result1 = PSQLexec(buf);
- if (!result1)
- error = true;
- else
- index_count = PQntuples(result1);
- }
-
- /* count table (and column) constraints */
- if (!error && tableinfo.checks)
- {
- sprintf(buf, "SELECT rcsrc\n"
- "FROM pg_relcheck r, pg_class c\n"
- "WHERE c.relname='%s' AND c.oid = r.rcrelid",
- name);
- result2 = PSQLexec(buf);
- if (!result2)
- error = true;
- else
- constr_count = PQntuples(result2);
- }
-
- /* count rules */
- if (!error && tableinfo.hasrules)
- {
- sprintf(buf,
- "SELECT r.rulename\n"
- "FROM pg_rewrite r, pg_class c\n"
- "WHERE c.relname='%s' AND c.oid = r.ev_class",
- name);
- result3 = PSQLexec(buf);
- if (!result3)
- error = true;
- else
- rule_count = PQntuples(result3);
- }
-
- /* count triggers */
- if (!error && tableinfo.hasrules)
- {
- sprintf(buf,
- "SELECT t.tgname\n"
- "FROM pg_trigger t, pg_class c\n"
- "WHERE c.relname='%s' AND c.oid = t.tgrelid",
- name);
- result4 = PSQLexec(buf);
- if (!result4)
- error = true;
- else
- trigger_count = PQntuples(result4);
- }
-
- footers = xmalloc((index_count + constr_count + rule_count + trigger_count + 1) * sizeof(*footers));
-
- /* print indices */
- for (i = 0; i < index_count; i++)
- {
- sprintf(buf, "%s %s",
- index_count==1 ? "Index:" : (i==0 ? "Indices:" : " "),
- PQgetvalue(result1, i, 0)
- );
- if (i < index_count-1)
- strcat(buf, ",");
-
- footers[count_footers++] = xstrdup(buf);
- }
-
- /* print contraints */
- for (i = 0; i < constr_count; i++)
- {
- sprintf(buf, "%s %s",
- constr_count==1 ? "Constraint:" : (i==0 ? "Constraints:" : " "),
- PQgetvalue(result2, i, 0)
- );
- footers[count_footers++] = xstrdup(buf);
- }
-
- /* print rules */
- for (i = 0; i < rule_count; i++)
- {
- sprintf(buf, "%s %s",
- rule_count==1 ? "Rule:" : (i==0 ? "Rules:" : " "),
- PQgetvalue(result3, i, 0)
- );
- if (i < rule_count-1)
- strcat(buf, ",");
-
- footers[count_footers++] = xstrdup(buf);
- }
-
- /* print triggers */
- for (i = 0; i < trigger_count; i++)
- {
- sprintf(buf, "%s %s",
- trigger_count==1 ? "Trigger:" : (i==0 ? "Triggers:" : " "),
- PQgetvalue(result4, i, 0)
- );
- if (i < trigger_count-1)
- strcat(buf, ",");
-
- footers[count_footers++] = xstrdup(buf);
- }
-
- /* end of list marker */
- footers[count_footers] = NULL;
-
- PQclear(result1);
- PQclear(result2);
- PQclear(result3);
- PQclear(result4);
+ if (!error && tableinfo.hasindex)
+ {
+ sprintf(buf, "SELECT c2.relname\n"
+ "FROM pg_class c, pg_class c2, pg_index i\n"
+ "WHERE c.relname = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
+ "ORDER BY c2.relname",
+ name);
+ result1 = PSQLexec(buf);
+ if (!result1)
+ error = true;
+ else
+ index_count = PQntuples(result1);
+ }
+
+ /* count table (and column) constraints */
+ if (!error && tableinfo.checks)
+ {
+ sprintf(buf, "SELECT rcsrc\n"
+ "FROM pg_relcheck r, pg_class c\n"
+ "WHERE c.relname='%s' AND c.oid = r.rcrelid",
+ name);
+ result2 = PSQLexec(buf);
+ if (!result2)
+ error = true;
+ else
+ constr_count = PQntuples(result2);
+ }
+
+ /* count rules */
+ if (!error && tableinfo.hasrules)
+ {
+ sprintf(buf,
+ "SELECT r.rulename\n"
+ "FROM pg_rewrite r, pg_class c\n"
+ "WHERE c.relname='%s' AND c.oid = r.ev_class",
+ name);
+ result3 = PSQLexec(buf);
+ if (!result3)
+ error = true;
+ else
+ rule_count = PQntuples(result3);
+ }
+
+ /* count triggers */
+ if (!error && tableinfo.hasrules)
+ {
+ sprintf(buf,
+ "SELECT t.tgname\n"
+ "FROM pg_trigger t, pg_class c\n"
+ "WHERE c.relname='%s' AND c.oid = t.tgrelid",
+ name);
+ result4 = PSQLexec(buf);
+ if (!result4)
+ error = true;
+ else
+ trigger_count = PQntuples(result4);
+ }
+
+ footers = xmalloc((index_count + constr_count + rule_count + trigger_count + 1)
+ * sizeof(*footers));
+
+ /* print indices */
+ for (i = 0; i < index_count; i++)
+ {
+ sprintf(buf, "%s %s",
+ index_count==1 ? "Index:" : (i==0 ? "Indices:" : " "),
+ PQgetvalue(result1, i, 0)
+ );
+ if (i < index_count-1)
+ strcat(buf, ",");
+
+ footers[count_footers++] = xstrdup(buf);
+ }
+
+ /* print contraints */
+ for (i = 0; i < constr_count; i++)
+ {
+ sprintf(buf, "%s %s",
+ constr_count==1 ? "Constraint:" : (i==0 ? "Constraints:" : " "),
+ PQgetvalue(result2, i, 0)
+ );
+ footers[count_footers++] = xstrdup(buf);
+ }
+
+ /* print rules */
+ for (i = 0; i < rule_count; i++)
+ {
+ sprintf(buf, "%s %s",
+ rule_count==1 ? "Rule:" : (i==0 ? "Rules:" : " "),
+ PQgetvalue(result3, i, 0)
+ );
+ if (i < rule_count-1)
+ strcat(buf, ",");
+
+ footers[count_footers++] = xstrdup(buf);
+ }
+
+ /* print triggers */
+ for (i = 0; i < trigger_count; i++)
+ {
+ sprintf(buf, "%s %s",
+ trigger_count==1 ? "Trigger:" : (i==0 ? "Triggers:" : " "),
+ PQgetvalue(result4, i, 0)
+ );
+ if (i < trigger_count-1)
+ strcat(buf, ",");
+
+ footers[count_footers++] = xstrdup(buf);
+ }
+
+ /* end of list marker */
+ footers[count_footers] = NULL;
+
+ PQclear(result1);
+ PQclear(result2);
+ PQclear(result3);
+ PQclear(result4);
}
if (!error)
- printTable(title, headers, (const char**)cells, (const char**)footers, "llll", &myopt, pset.queryFout);
+ printTable(title, headers,
+ (const char**)cells, (const char**)footers,
+ "llll", &myopt, pset.queryFout);
/* clean up */
free(title);
for (i = 0; i < PQntuples(res); i++)
{
free(cells[i * cols + 1]);
- if (tableinfo.relkind == 'r' || tableinfo.relkind == 's')
- free(cells[i * cols + 2]);
+ if (tableinfo.relkind == 'r')
+ free(cells[i * cols + 2]);
}
free(cells);
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.6 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.7 2000/01/29 16:58:48 petere Exp $
*/
#ifndef DESCRIBE_H
#define DESCRIBE_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.14 2000/01/26 16:10:01 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.15 2000/01/29 16:58:48 petere Exp $
*/
#include
#include "help.h"
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.4 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.5 2000/01/29 16:58:48 petere Exp $
*/
#ifndef HELP_H
#define HELP_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.7 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.8 2000/01/29 16:58:48 petere Exp $
*/
#include
#include "input.h"
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.5 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.6 2000/01/29 16:58:48 petere Exp $
*/
#ifndef INPUT_H
#define INPUT_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.6 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.7 2000/01/29 16:58:48 petere Exp $
*/
#include
#include "large_obj.h"
if (notice[0])
{
- if ((!commit && strcmp(notice, "NOTICE: UserAbortTransactionBlock and not in in-progress state\n") != 0) ||
- (commit && strcmp(notice, "NOTICE: EndTransactionBlock and not inprogress/abort state\n") != 0))
+ if ((!commit && strcmp(notice, "NOTICE: ROLLBACK: no transaction in progress\n") != 0) ||
+ (commit && strcmp(notice, "NOTICE: COMMIT: no transaction in progress\n") != 0))
fputs(notice, stderr);
}
else if (!QUIET())
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.h,v 1.6 2000/01/18 23:30:23 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.h,v 1.7 2000/01/29 16:58:49 petere Exp $
*/
#ifndef LARGE_OBJ_H
#define LARGE_OBJ_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.h,v 1.5 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.h,v 1.6 2000/01/29 16:58:49 petere Exp $
*/
#ifndef MAINLOOP_H
#define MAINLOOP_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.8 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.9 2000/01/29 16:58:49 petere Exp $
*/
#include
#include "print.h"
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.5 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.6 2000/01/29 16:58:49 petere Exp $
*/
#ifndef PRINT_H
#define PRINT_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.6 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.7 2000/01/29 16:58:49 petere Exp $
*/
#include
#include "prompt.h"
* %n - database user name
* %/ - current database
* %~ - like %/ but "~" when database name equals user name
- * %# - "#" if the username is postgres, ">" otherwise
+ * %# - "#" if superuser, ">" otherwise
* %R - in prompt1 normally =, or ^ if single line mode,
* or a ! if session is not connected to a database;
* in prompt2 -, *, ', or ";
case '#':
{
- if (pset.db && strcmp(PQuser(pset.db), "postgres") == 0)
+ if (pset.issuper)
buf[0] = '#';
else
buf[0] = '>';
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/prompt.h,v 1.4 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.h,v 1.5 2000/01/29 16:58:49 petere Exp $
*/
#ifndef PROMPT_H
#define PROMPT_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/settings.h,v 1.7 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/settings.h,v 1.8 2000/01/29 16:58:49 petere Exp $
*/
#ifndef SETTINGS_H
#define SETTINGS_H
char *progname; /* in case you renamed psql */
char *inputfile; /* for error reporting */
unsigned lineno; /* also for error reporting */
+
+ bool issuper; /* is the current user a superuser?
+ (used to form the prompt) */
} PsqlSettings;
extern PsqlSettings pset;
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.19 2000/01/27 05:33:51 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.20 2000/01/29 16:58:49 petere Exp $
*/
#include
if (PQstatus(pset.db) == CONNECTION_BAD)
{
- fprintf(stderr, "%s: connection to database \"%s\" failed - %s",
- pset.progname, PQdb(pset.db), PQerrorMessage(pset.db));
+ fprintf(stderr, "%s: %s",
+ pset.progname, PQerrorMessage(pset.db));
PQfinish(pset.db);
exit(EXIT_BADCONN);
}
SetVariable(pset.vars, "HOST", PQhost(pset.db));
SetVariable(pset.vars, "PORT", PQport(pset.db));
+ pset.issuper = test_superuser(PQuser(pset.db));
+
if (!QUIET() && !pset.notty && !options.action)
{
printf("Welcome to %s, the PostgreSQL interactive terminal.\n\n"
pset.getPassword = true;
break;
case '?':
- if (strcmp(argv[optind-1], "-?")==0)
+ /* Actual help option given */
+ if (strcmp(argv[optind-1], "-?")==0 || strcmp(argv[optind-1], "--help")==0)
{
usage();
exit(EXIT_SUCCESS);
}
+ /* unknown option reported by getopt */
else
{
fputs("Try -? for help.\n", stderr);
/*
- * Load /etc/psqlrc or .psqlrc file, if found.
+ * Load .psqlrc file, if found.
*/
static void
process_psqlrc(void)
#define R_OK 0
#endif
- /* System-wide startup file */
- if (access("/etc/psqlrc-" PG_RELEASE "." PG_VERSION "." PG_SUBVERSION, R_OK) == 0)
- process_file("/etc/psqlrc-" PG_RELEASE "." PG_VERSION "." PG_SUBVERSION);
- else if (access("/etc/psqlrc", R_OK) == 0)
- process_file("/etc/psqlrc");
-
/* Look for one in the home dir */
home = getenv("HOME");
puts("Portions Copyright (c) 1996-2000, PostgreSQL, Inc");
puts("Portions Copyright (C) 1996 Regents of the University of California");
- puts("Read the file COPYING or use the command \\copyright to see the");
+ puts("Read the file COPYRIGHT or use the command \\copyright to see the");
puts("usage and distribution terms.");
}
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.22 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.23 2000/01/29 16:58:49 petere Exp $
*/
#include
#include "stringutils.h"
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.h,v 1.12 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.h,v 1.13 2000/01/29 16:58:49 petere Exp $
*/
#ifndef STRINGUTILS_H
#define STRINGUTILS_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.8 2000/01/21 23:32:36 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.9 2000/01/29 16:58:49 petere Exp $
*/
/*-----------
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.h,v 1.2 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.h,v 1.3 2000/01/29 16:58:49 petere Exp $
*/
#ifndef TAB_COMPLETE_H
#define TAB_COMPLETE_H
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/variables.c,v 1.4 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/variables.c,v 1.5 2000/01/29 16:58:49 petere Exp $
*/
#include
#include "variables.h"
/*
* psql - the PostgreSQL interactive terminal
*
- * Copyright 2000 by PostgreSQL Global Development Team
+ * Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/variables.h,v 1.4 2000/01/18 23:30:24 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/variables.h,v 1.5 2000/01/29 16:58:49 petere Exp $
*/
/*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.8 1999/10/13 16:46:28 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.9 2000/01/29 16:58:52 petere Exp $
*
*-------------------------------------------------------------------------
*/
memset(&po,0,sizeof(po));
- po.align = (pqbool)fillAlign;
+ po.align = fillAlign;
po.fieldSep = (char *)fieldSep;
- po.header = (pqbool)printHeader;
+ po.header = printHeader;
PQprint(out,pgResult,&po);
}
memset(&po,0,sizeof(po));
- po.align = (pqbool)width;
+ po.align = width;
if(terseOutput) po.fieldSep = strdup("|");
else po.fieldSep = "";
- po.header = (pqbool)printAttName;
+ po.header = printAttName;
PQprint(out,pgResult,&po);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.37 2000/01/26 05:58:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.38 2000/01/29 16:58:51 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include "libpq-int.h"
#include "pqsignal.h"
+#ifdef MULTIBYTE
+#include "miscadmin.h"
+#include "mb/pg_wchar.h"
+#endif
+
#define DONOTICE(conn,message) \
((*(conn)->noticeHook) ((conn)->noticeArg, (message)))
return 0;
}
+
+
+
+/*
+ * A couple of "miscellaneous" multibyte related functions. They used
+ * to be in fe-print.c but that file is doomed.
+ */
+
+#ifdef MULTIBYTE
+/*
+ * returns the byte length of the word beginning s, using the
+ * specified encoding.
+ */
+int
+PQmblen(const unsigned char *s, int encoding)
+{
+ return (pg_encoding_mblen(encoding, s));
+}
+
+/*
+ * Get encoding id from environment variable PGCLIENTENCODING.
+ */
+int
+PQenv2encoding(void)
+{
+ char *str;
+ int encoding = SQL_ASCII;
+
+ str = getenv("PGCLIENTENCODING");
+ if (str && *str != '\0')
+ encoding = pg_char_to_encoding(str);
+ return(encoding);
+}
+
+#else
+
+/* Provide a default definition in case someone calls it anyway */
+int
+PQmblen(const unsigned char *s, int encoding)
+{
+ return 1;
+}
+int
+PQenv2encoding(void)
+{
+ return 0;
+}
+
+#endif /* MULTIBYTE */
* didn't really belong there.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.32 2000/01/26 05:58:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.33 2000/01/29 16:58:51 petere Exp $
*
*-------------------------------------------------------------------------
*/
-#include <signal.h>
+#include <postgres.h>
-#include "postgres.h"
+#include
#include "libpq-fe.h"
#include "libpq-int.h"
#include "pqsignal.h"
#endif
#endif
-#ifdef MULTIBYTE
-#include "miscadmin.h"
-#include "mb/pg_wchar.h"
-#endif
-
#ifdef TIOCGWINSZ
static struct winsize screen_size;
-
#else
static struct winsize
{
int ws_row;
int ws_col;
} screen_size;
-
#endif
static void output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
unsigned char *fieldNotNum, int *fieldMax, char *border,
const int row_index);
-static void fill(int length, int max, char filler, FILE *fp);
/*
* various flags and options. consult libpq-fe.h for
* details
*
- * Obsoletes PQprintTuples.
+ * This function should probably be removed sometime since psql
+ * doesn't use it anymore. It is unclear to what extend this is used
+ * by external clients, however.
*/
void
}
-/*
- * PQdisplayTuples()
- * kept for backward compatibility
- */
-
-void
-PQdisplayTuples(const PGresult *res,
- FILE *fp, /* where to send the output */
- int fillAlign, /* pad the fields with spaces */
- const char *fieldSep, /* field separator */
- int printHeader,/* display headers? */
- int quiet
-)
-{
-#define DEFAULT_FIELD_SEP " "
-
- int i,
- j;
- int nFields;
- int nTuples;
- int *fLength = NULL;
-
- if (fieldSep == NULL)
- fieldSep = DEFAULT_FIELD_SEP;
-
- /* Get some useful info about the results */
- nFields = PQnfields(res);
- nTuples = PQntuples(res);
-
- if (fp == NULL)
- fp = stdout;
-
- /* Figure the field lengths to align to */
- /* will be somewhat time consuming for very large results */
- if (fillAlign)
- {
- fLength = (int *) malloc(nFields * sizeof(int));
- for (j = 0; j < nFields; j++)
- {
- fLength[j] = strlen(PQfname(res, j));
- for (i = 0; i < nTuples; i++)
- {
- int flen = PQgetlength(res, i, j);
- if (flen > fLength[j])
- fLength[j] = flen;
- }
- }
- }
-
- if (printHeader)
- {
- /* first, print out the attribute names */
- for (i = 0; i < nFields; i++)
- {
- fputs(PQfname(res, i), fp);
- if (fillAlign)
- fill(strlen(PQfname(res, i)), fLength[i], ' ', fp);
- fputs(fieldSep, fp);
- }
- fprintf(fp, "\n");
-
- /* Underline the attribute names */
- for (i = 0; i < nFields; i++)
- {
- if (fillAlign)
- fill(0, fLength[i], '-', fp);
- fputs(fieldSep, fp);
- }
- fprintf(fp, "\n");
- }
-
- /* next, print out the instances */
- for (i = 0; i < nTuples; i++)
- {
- for (j = 0; j < nFields; j++)
- {
- fprintf(fp, "%s", PQgetvalue(res, i, j));
- if (fillAlign)
- fill(strlen(PQgetvalue(res, i, j)), fLength[j], ' ', fp);
- fputs(fieldSep, fp);
- }
- fprintf(fp, "\n");
- }
-
- if (!quiet)
- fprintf(fp, "\nQuery returned %d row%s.\n", PQntuples(res),
- (PQntuples(res) == 1) ? "" : "s");
-
- fflush(fp);
-
- if (fLength)
- free(fLength);
-}
-
-
-
-/*
- * PQprintTuples()
- *
- * kept for backward compatibility
- *
- */
-void
-PQprintTuples(const PGresult *res,
- FILE *fout, /* output stream */
- int PrintAttNames,/* print attribute names or not */
- int TerseOutput, /* delimiter bars or not? */
- int colWidth /* width of column, if 0, use variable
- * width */
-)
-{
- int nFields;
- int nTups;
- int i,
- j;
- char formatString[80];
-
- char *tborder = NULL;
-
- nFields = PQnfields(res);
- nTups = PQntuples(res);
-
- if (colWidth > 0)
- sprintf(formatString, "%%s %%-%ds", colWidth);
- else
- sprintf(formatString, "%%s %%s");
-
- if (nFields > 0)
- { /* only print rows with at least 1 field. */
-
- if (!TerseOutput)
- {
- int width;
-
- width = nFields * 14;
- tborder = malloc(width + 1);
- for (i = 0; i <= width; i++)
- tborder[i] = '-';
- tborder[i] = '\0';
- fprintf(fout, "%s\n", tborder);
- }
-
- for (i = 0; i < nFields; i++)
- {
- if (PrintAttNames)
- {
- fprintf(fout, formatString,
- TerseOutput ? "" : "|",
- PQfname(res, i));
- }
- }
-
- if (PrintAttNames)
- {
- if (TerseOutput)
- fprintf(fout, "\n");
- else
- fprintf(fout, "|\n%s\n", tborder);
- }
-
- for (i = 0; i < nTups; i++)
- {
- for (j = 0; j < nFields; j++)
- {
- const char *pval = PQgetvalue(res, i, j);
-
- fprintf(fout, formatString,
- TerseOutput ? "" : "|",
- pval ? pval : "");
- }
- if (TerseOutput)
- fprintf(fout, "\n");
- else
- fprintf(fout, "|\n%s\n", tborder);
- }
- }
-}
-
-#ifdef MULTIBYTE
-/*
- * returns the byte length of the word beginning s.
- * Client side encoding is determined by the environment variable
- * "PGCLIENTENCODING".
- * if this variable is not defined, the same encoding as
- * the backend is assumed.
- */
-int
-PQmblen(const unsigned char *s, int encoding)
-{
- return (pg_encoding_mblen(encoding, s));
-}
-
-/*
- * Get encoding id from environment variable PGCLIENTENCODING.
- */
-int
-PQenv2encoding(void)
-{
- char *str;
- int encoding = SQL_ASCII;
-
- str = getenv("PGCLIENTENCODING");
- if (str && *str != '\0')
- encoding = pg_char_to_encoding(str);
- return(encoding);
-}
-
-#else
-
-/* Provide a default definition in case someone calls it anyway */
-int
-PQmblen(const unsigned char *s, int encoding)
-{
- return 1;
-}
-int
-PQenv2encoding(void)
-{
- return 0;
-}
-
-#endif /* MULTIBYTE */
-
static void
do_field(const PQprintOpt *po, const PGresult *res,
const int i, const int j, const int fs_len,
}
-/* simply send out max-length number of filler characters to fp */
-static void
-fill(int length, int max, char filler, FILE *fp)
+#if 0
+/*
+ * really old printing routines
+ */
+
+void
+PQdisplayTuples(const PGresult *res,
+ FILE *fp, /* where to send the output */
+ int fillAlign, /* pad the fields with spaces */
+ const char *fieldSep, /* field separator */
+ int printHeader,/* display headers? */
+ int quiet
+)
+{
+#define DEFAULT_FIELD_SEP " "
+
+ int i,
+ j;
+ int nFields;
+ int nTuples;
+ int *fLength = NULL;
+
+ if (fieldSep == NULL)
+ fieldSep = DEFAULT_FIELD_SEP;
+
+ /* Get some useful info about the results */
+ nFields = PQnfields(res);
+ nTuples = PQntuples(res);
+
+ if (fp == NULL)
+ fp = stdout;
+
+ /* Figure the field lengths to align to */
+ /* will be somewhat time consuming for very large results */
+ if (fillAlign)
+ {
+ fLength = (int *) malloc(nFields * sizeof(int));
+ for (j = 0; j < nFields; j++)
+ {
+ fLength[j] = strlen(PQfname(res, j));
+ for (i = 0; i < nTuples; i++)
+ {
+ int flen = PQgetlength(res, i, j);
+ if (flen > fLength[j])
+ fLength[j] = flen;
+ }
+ }
+ }
+
+ if (printHeader)
+ {
+ /* first, print out the attribute names */
+ for (i = 0; i < nFields; i++)
+ {
+ fputs(PQfname(res, i), fp);
+ if (fillAlign)
+ fill(strlen(PQfname(res, i)), fLength[i], ' ', fp);
+ fputs(fieldSep, fp);
+ }
+ fprintf(fp, "\n");
+
+ /* Underline the attribute names */
+ for (i = 0; i < nFields; i++)
+ {
+ if (fillAlign)
+ fill(0, fLength[i], '-', fp);
+ fputs(fieldSep, fp);
+ }
+ fprintf(fp, "\n");
+ }
+
+ /* next, print out the instances */
+ for (i = 0; i < nTuples; i++)
+ {
+ for (j = 0; j < nFields; j++)
+ {
+ fprintf(fp, "%s", PQgetvalue(res, i, j));
+ if (fillAlign)
+ fill(strlen(PQgetvalue(res, i, j)), fLength[j], ' ', fp);
+ fputs(fieldSep, fp);
+ }
+ fprintf(fp, "\n");
+ }
+
+ if (!quiet)
+ fprintf(fp, "\nQuery returned %d row%s.\n", PQntuples(res),
+ (PQntuples(res) == 1) ? "" : "s");
+
+ fflush(fp);
+
+ if (fLength)
+ free(fLength);
+}
+
+
+
+void
+PQprintTuples(const PGresult *res,
+ FILE *fout, /* output stream */
+ int PrintAttNames,/* print attribute names or not */
+ int TerseOutput, /* delimiter bars or not? */
+ int colWidth /* width of column, if 0, use variable
+ * width */
+)
{
- int count;
+ int nFields;
+ int nTups;
+ int i,
+ j;
+ char formatString[80];
+
+ char *tborder = NULL;
+
+ nFields = PQnfields(res);
+ nTups = PQntuples(res);
+
+ if (colWidth > 0)
+ sprintf(formatString, "%%s %%-%ds", colWidth);
+ else
+ sprintf(formatString, "%%s %%s");
+
+ if (nFields > 0)
+ { /* only print rows with at least 1 field. */
+
+ if (!TerseOutput)
+ {
+ int width;
+
+ width = nFields * 14;
+ tborder = malloc(width + 1);
+ for (i = 0; i <= width; i++)
+ tborder[i] = '-';
+ tborder[i] = '\0';
+ fprintf(fout, "%s\n", tborder);
+ }
+
+ for (i = 0; i < nFields; i++)
+ {
+ if (PrintAttNames)
+ {
+ fprintf(fout, formatString,
+ TerseOutput ? "" : "|",
+ PQfname(res, i));
+ }
+ }
+
+ if (PrintAttNames)
+ {
+ if (TerseOutput)
+ fprintf(fout, "\n");
+ else
+ fprintf(fout, "|\n%s\n", tborder);
+ }
+
+ for (i = 0; i < nTups; i++)
+ {
+ for (j = 0; j < nFields; j++)
+ {
+ const char *pval = PQgetvalue(res, i, j);
- count = max - length;
- while (count-- >= 0)
- putc(filler, fp);
+ fprintf(fout, formatString,
+ TerseOutput ? "" : "|",
+ pval ? pval : "");
+ }
+ if (TerseOutput)
+ fprintf(fout, "\n");
+ else
+ fprintf(fout, "|\n%s\n", tborder);
+ }
+ }
}
+#endif
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-fe.h,v 1.57 2000/01/26 05:58:46 momjian Exp $
+ * $Id: libpq-fe.h,v 1.58 2000/01/29 16:58:51 petere Exp $
*
*-------------------------------------------------------------------------
*/
/* Print options for PQprint() */
- /*
- * We can't use the conventional "bool", because we are designed to be
- * included in a user's program, and user may already have that type
- * defined. Pqbool, on the other hand, is unlikely to be used.
- */
- typedef char pqbool;
-
typedef struct _PQprintOpt
{
- pqbool header; /* print output field headings and row
+ int header; /* print output field headings and row
* count */
- pqbool align; /* fill align the fields */
- pqbool standard; /* old brain dead format */
- pqbool html3; /* output html tables */
- pqbool expanded; /* expand tables */
- pqbool pager; /* use pager for output if needed */
+ int align; /* fill align the fields */
+ int standard; /* old brain dead format */
+ int html3; /* output html tables */
+ int expanded; /* expand tables */
+ int pager; /* use pager for output if needed */
char *fieldSep; /* field separator */
char *tableOpt; /* insert to HTML
*/
char *caption; /* HTML
*/
extern int PQfsize(const PGresult *res, int field_num);
extern int PQfmod(const PGresult *res, int field_num);
extern const char *PQcmdStatus(const PGresult *res);
- extern const char *PQoidStatus(const PGresult *res); /* old and ugly */
- extern Oid PQoidValue(const PGresult *res); /* new and improved */
+ extern const char *PQoidStatus(const PGresult *res); /* old and ugly */
+ extern Oid PQoidValue(const PGresult *res); /* new and improved */
extern const char *PQcmdTuples(const PGresult *res);
extern const char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
const PGresult *res,
const PQprintOpt *ps); /* option structure */
- /*
- * PQdisplayTuples() is a better version of PQprintTuples(), but both
- * are obsoleted by PQprint().
- */
- extern void PQdisplayTuples(const PGresult *res,
- FILE *fp, /* where to send the
- * output */
- int fillAlign, /* pad the fields with
- * spaces */
- const char *fieldSep, /* field separator */
- int printHeader, /* display headers? */
- int quiet);
-
- extern void PQprintTuples(const PGresult *res,
- FILE *fout, /* output stream */
- int printAttName, /* print attribute names
- * or not */
- int terseOutput, /* delimiter bars or
- * not? */
- int width); /* width of column, if
- * 0, use variable width */
-
- /* Determine length of multibyte encoded char at *s */
- extern int PQmblen(const unsigned char *s, int encoding);
-
- /* Get encoding id from environment variable PGCLIENTENCODING */
- int PQenv2encoding(void);
+#if 0
+ /*
+ * really old printing routines
+ */
+ extern void PQdisplayTuples(const PGresult *res,
+ FILE *fp, /* where to send the output */
+ int fillAlign, /* pad the fields with spaces */
+ const char *fieldSep, /* field separator */
+ int printHeader, /* display headers? */
+ int quiet);
+
+ extern void PQprintTuples(const PGresult *res,
+ FILE *fout, /* output stream */
+ int printAttName, /* print attribute names */
+ int terseOutput, /* delimiter bars */
+ int width); /* width of column, if
+ * 0, use variable width */
+#endif
/* === in fe-lobj.c === */
extern Oid lo_import(PGconn *conn, const char *filename);
extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
+/* === in fe-misc.c === */
+
+ /* Determine length of multibyte encoded char at *s */
+ extern int PQmblen(const unsigned char *s, int encoding);
+
+ /* Get encoding id from environment variable PGCLIENTENCODING */
+ extern int PQenv2encoding(void);
+
#ifdef __cplusplus
};
-- not in a xact
abort;
-NOTICE: UserAbortTransactionBlock and not in in-progress state
+NOTICE: ROLLBACK: no transaction in progress
-- not in a xact
end;
-NOTICE: EndTransactionBlock and not inprogress/abort state
+NOTICE: COMMIT: no transaction in progress
--
-- DEFINE AGGREGATE