summaryrefslogtreecommitdiff
path: root/src/bin/psql/common.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-10-03 17:09:42 +0000
committerBruce Momjian <bruce@momjian.us>2002-10-03 17:09:42 +0000
commita0bf2503ea0d9a1a2208dd3cf74727bcda7e69d2 (patch)
treeaa3d6727dc94d4a0c4741077184e7cfcf5cdf709 /src/bin/psql/common.c
parentd4eae72513d919522c8711b55894511f4fb49443 (diff)
downloadpostgresql-a0bf2503ea0d9a1a2208dd3cf74727bcda7e69d2.tar.gz
The attached patch fixes a number of issues related to compiling the
client utilities (libpq.dll and psql.exe) for win32 (missing defines, adjustments to includes, pedantic casting, non-existent functions) per: http://developer.postgresql.org/docs/postgres/install-win32.html. It compiles cleanly under Windows 2000 using Visual Studio .net. Also compiles clean and passes all regression tests (regular and contrib) under Linux. In addition to a review by the usual suspects, it would be very desirable for someone well versed in the peculiarities of win32 to take a look. Joe Conway
Diffstat (limited to 'src/bin/psql/common.c')
-rw-r--r--src/bin/psql/common.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index a636372b02..c451640ee0 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.45 2002/09/14 19:46:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.46 2002/10/03 17:09:41 momjian Exp $
*/
#include "postgres_fe.h"
@@ -11,17 +11,18 @@
#include <errno.h>
#include <stdarg.h>
-#include <sys/time.h>
#ifndef HAVE_STRDUP
#include <strdup.h>
#endif
#include <signal.h>
#ifndef WIN32
+#include <sys/time.h>
#include <unistd.h> /* for write() */
#include <setjmp.h>
#else
#include <io.h> /* for _write() */
#include <win32.h>
+#include <sys/timeb.h> /* for _ftime() */
#endif
#include "libpq-fe.h"
@@ -295,9 +296,13 @@ SendQuery(const char *query)
bool success = false;
PGresult *results;
PGnotify *notify;
+#ifndef WIN32
struct timeval before,
after;
- struct timezone tz;
+#else
+ struct _timeb before,
+ after;
+#endif
if (!pset.db)
{
@@ -327,11 +332,21 @@ SendQuery(const char *query)
}
cancelConn = pset.db;
+
+#ifndef WIN32
+ if (pset.timing)
+ gettimeofday(&before, NULL);
+ results = PQexec(pset.db, query);
+ if (pset.timing)
+ gettimeofday(&after, NULL);
+#else
if (pset.timing)
- gettimeofday(&before, &tz);
+ _ftime(&before);
results = PQexec(pset.db, query);
if (pset.timing)
- gettimeofday(&after, &tz);
+ _ftime(&after);
+#endif
+
if (PQresultStatus(results) == PGRES_COPY_IN)
copy_in_state = true;
/* keep cancel connection for copy out state */
@@ -463,8 +478,13 @@ SendQuery(const char *query)
/* Possible microtiming output */
if (pset.timing && success)
+#ifndef WIN32
printf(gettext("Time: %.2f ms\n"),
((after.tv_sec - before.tv_sec) * 1000000.0 + after.tv_usec - before.tv_usec) / 1000.0);
+#else
+ printf(gettext("Time: %.2f ms\n"),
+ ((after.time - before.time) * 1000.0 + after.millitm - before.millitm));
+#endif
return success;
}