*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.173 1999/03/24 06:55:14 ishii Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.174 1999/03/30 05:00:42 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#ifdef MULTIBYTE
/* flag to indicate if PGCLIENTENCODING has been set by a user */
-static int has_client_encoding;
+static char *has_client_encoding = 0;
#endif
/* This prompt string is assumed to have at least 3 characters by code in MainLoop().
bool notty; /* input or output is not a tty */
bool pipe; /* queryFout is from a popen() */
bool echoQuery; /* echo the query before sending it */
+ bool echoAllQueries; /* echo all queries before sending it*/
bool quiet; /* run quietly, no messages, no promt */
bool singleStep; /* prompt before for each query */
bool singleLineMode; /* query terminated by newline */
static int MainLoop(PsqlSettings *pset, char *query, FILE *source);
static FILE *setFout(PsqlSettings *pset, char *fname);
+static char *selectVersion(PsqlSettings *pset);
+
/*
* usage print out usage for command line arguments
*/
fprintf(stderr, "\t -c query run single query (slash commands too)\n");
fprintf(stderr, "\t -d dbName specify database name\n");
fprintf(stderr, "\t -e echo the query sent to the backend\n");
+ fprintf(stderr, "\t -E echo all queries sent to the backend\n");
fprintf(stderr, "\t -f filename use file as a source of queries\n");
fprintf(stderr, "\t -F sep set the field separator (default is '|')\n");
fprintf(stderr, "\t -h host set database server host\n");
if (pset->notty == 0 &&
(pagerenv = getenv("PAGER")) &&
(pagerenv[0] != '\0') &&
- screen_size.ws_row <= 28 &&
+ screen_size.ws_row <= 35 &&
(fout = popen(pagerenv, "w")))
{
usePipe = 1;
{
PGresult *res;
+ if (pset->echoAllQueries)
+ {
+ fprintf(stderr, "QUERY: %s\n", query);
+ fprintf(stderr, "\n");
+ fflush(stderr);
+ }
+
res = PQexec(pset->db, query);
if (!res)
fputs(PQerrorMessage(pset->db), stderr);
{
/* Display the information */
- fprintf(fout, "\nDatabase = %s\n", PQdb(pset->db));
+ fprintf(fout, "Database = %s\n", PQdb(pset->db));
fprintf(fout, " +------------------+----------------------------------+----------+\n");
fprintf(fout, " | Owner | Relation | Type |\n");
fprintf(fout, " +------------------+----------------------------------+----------+\n");
fprintf(fout, "\n");
}
fprintf(fout, " +------------------+----------------------------------+----------+\n");
+ fprintf(fout, "\n") ;
PQclear(res);
}
if (usePipe)
/* Display the information */
- fprintf(fout, "\nDatabase = %s\n", PQdb(pset->db));
+ fprintf(fout, "Database = %s\n", PQdb(pset->db));
fprintf(fout, " +");
emitNtimes(fout, "-", maxCol1Len+2);
fprintf(fout, "+");
if(PQntuples(res2)) {
/*
* display the query.
- * -Ryan 2/14/99
+o * -Ryan 2/14/99
*/
- fprintf(fout, "\nView = %s\n", table);
+ fprintf(fout, "View = %s\n", table);
fprintf(fout, "Query = %s\n", PQgetvalue(res2, 0, 1));
} else {
- fprintf(fout, "\nTable = %s\n", table);
+ fprintf(fout, "Table = %s\n", table);
}
PQclear(res2);
fprintf(fout, "%s\n", PQgetvalue(res, i, 0));
else
fprintf(fout, " %s\n", PQgetvalue(res, i, 0));
+ fprintf(fout, "\n");
}
PQclear(res);
}
int c;
char *home = NULL; /* Used to store $HOME */
+ char *version = NULL; /* PostgreSQL version */
MemSet(&settings, 0, sizeof settings);
settings.opt.align = 1;
has_client_encoding = getenv("PGCLIENTENCODING");
#endif
- while ((c = getopt(argc, argv, "Aa:c:d:ef:F:lh:Hnso:p:qStT:ux")) != EOF)
+ while ((c = getopt(argc, argv, "Aa:c:d:eEf:F:lh:Hnso:p:qStT:ux")) != EOF)
{
switch (c)
{
case 'e':
settings.echoQuery = 1;
break;
+ case 'E':
+ settings.echoAllQueries = 1;
+ settings.echoQuery = 1;
+ break;
case 'f':
qfilename = optarg;
break;
{
printf("Welcome to the POSTGRESQL interactive sql monitor:\n");
printf(" Please read the file COPYRIGHT for copyright terms "
- "of POSTGRESQL\n\n");
+ "of POSTGRESQL\n");
+
+ if ( (version = selectVersion(&settings)) != NULL )
+ printf("[%s]\n", version);
+
+ printf("\n");
printf(" type \\? for help on slash commands\n");
printf(" type \\q to quit\n");
printf(" type \\g or terminate with semicolon to execute query\n");
printf("\n\n");
}
+
+static char *
+selectVersion(PsqlSettings *pset)
+{
+#define PGVERSIONBUFSZ 128
+ static char version[PGVERSIONBUFSZ+1];
+ PGresult *res;
+ char *query = "select version();";
+
+ if (!(res = PQexec(pset->db, query))) return(NULL);
+
+ if (PQresultStatus(res) == PGRES_COMMAND_OK ||
+ PQresultStatus(res) == PGRES_TUPLES_OK )
+ {
+ strncpy(version, PQgetvalue(res,0,0), PGVERSIONBUFSZ);
+ version[PGVERSIONBUFSZ] = '\0';
+ PQclear(res);
+ return(version);
+ }
+ else
+ {
+ PQclear(res);
+ return(NULL);
+ }
+}