From a647e30ba3d3d36c6a00909e7c7770adb1676e60 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 12 Jun 2003 08:02:57 +0000 Subject: [PATCH] New patch with corrected README attached. Also quickly added mention that it may be a qualified schema name. Rod Taylor --- contrib/pgstattuple/README.pgstattuple | 11 ++++-- contrib/pgstattuple/pgstattuple.c | 50 +++++++++++++++++++++----- contrib/pgstattuple/pgstattuple.sql.in | 7 +++- src/backend/libpq/ip.c | 6 +++- src/backend/utils/mb/encnames.c | 4 ++- src/include/c.h | 4 +-- src/include/getaddrinfo.h | 4 ++- src/include/pg_config.h.win32 | 4 +++ src/include/port.h | 4 ++- src/interfaces/libpq/bcc32.mak | 18 +++++++--- src/interfaces/libpq/blibpqdll.def | 4 +-- src/interfaces/libpq/fe-connect.c | 6 +++- src/interfaces/libpq/fe-misc.c | 5 ++- src/interfaces/libpq/libpqdll.def | 2 +- src/interfaces/libpq/win32.mak | 33 +++++++++++++++++ src/port/crypt.c | 6 +++- src/port/getaddrinfo.c | 4 ++- src/port/inet_aton.c | 4 ++- 18 files changed, 146 insertions(+), 30 deletions(-) diff --git a/contrib/pgstattuple/README.pgstattuple b/contrib/pgstattuple/README.pgstattuple index 42a7fc2165..3e7facb80f 100644 --- a/contrib/pgstattuple/README.pgstattuple +++ b/contrib/pgstattuple/README.pgstattuple @@ -8,7 +8,7 @@ pgstattuple README 2002/08/29 Tatsuo Ishii test=# \x Expanded display is on. -test=# select * from pgstattuple('pg_proc'); +test=# select * from pgstattuple('pg_catalog.pg_proc'); -[ RECORD 1 ]------+------- table_len | 458752 tuple_count | 1470 @@ -45,9 +45,14 @@ free_percent -- free space in % CREATE OR REPLACE FUNCTION pgstattuple(text) RETURNS pgstattuple_type AS 'MODULE_PATHNAME', 'pgstattuple' - LANGUAGE 'c' WITH (isstrict); + LANGUAGE 'c' STRICT; - The argument is the table name. Note that pgstattuple only returns + CREATE OR REPLACE FUNCTION pgstattuple(oid) RETURNS pgstattuple_type + AS 'MODULE_PATHNAME', 'pgstattuplebyid' + LANGUAGE 'c' STRICT; + + The argument is the table name (optionally it may be qualified) + or the OID of the table. Note that pgstattuple only returns one row. 4. Notes diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c index 51cab46a1e..fb0d931615 100644 --- a/contrib/pgstattuple/pgstattuple.c +++ b/contrib/pgstattuple/pgstattuple.c @@ -1,5 +1,5 @@ /* - * $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.9 2002/09/04 20:31:08 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.10 2003/06/12 08:02:53 momjian Exp $ * * Copyright (c) 2001,2002 Tatsuo Ishii * @@ -33,8 +33,12 @@ PG_FUNCTION_INFO_V1(pgstattuple); +PG_FUNCTION_INFO_V1(pgstattuplebyid); extern Datum pgstattuple(PG_FUNCTION_ARGS); +extern Datum pgstattuplebyid(PG_FUNCTION_ARGS); + +static Datum pgstattuple_real(Relation rel); /* ---------- * pgstattuple: @@ -46,7 +50,7 @@ extern Datum pgstattuple(PG_FUNCTION_ARGS); * ---------- */ -#define DUMMY_TUPLE "pgstattuple_type" +#define DUMMY_TUPLE "public.pgstattuple_type" #define NCOLUMNS 9 #define NCHARS 32 @@ -56,6 +60,41 @@ pgstattuple(PG_FUNCTION_ARGS) text *relname = PG_GETARG_TEXT_P(0); RangeVar *relrv; Relation rel; + Datum result; + + /* open relation */ + relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname, + "pgstattuple")); + rel = heap_openrv(relrv, AccessShareLock); + + result = pgstattuple_real(rel); + + PG_RETURN_DATUM(result); +} + +Datum +pgstattuplebyid(PG_FUNCTION_ARGS) +{ + Oid relid = PG_GETARG_OID(0); + Relation rel; + Datum result; + + /* open relation */ + rel = heap_open(relid, AccessShareLock); + + result = pgstattuple_real(rel); + + PG_RETURN_DATUM(result); +} + +/* + * pgstattuple_real + * + * The real work occurs here + */ +static Datum +pgstattuple_real(Relation rel) +{ HeapScanDesc scan; HeapTuple tuple; BlockNumber nblocks; @@ -92,11 +131,6 @@ pgstattuple(PG_FUNCTION_ARGS) */ attinmeta = TupleDescGetAttInMetadata(tupdesc); - /* open relation */ - relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname, - "pgstattuple")); - rel = heap_openrv(relrv, AccessShareLock); - nblocks = RelationGetNumberOfBlocks(rel); scan = heap_beginscan(rel, SnapshotAny, 0, NULL); @@ -187,5 +221,5 @@ pgstattuple(PG_FUNCTION_ARGS) pfree(values[i]); pfree(values); - PG_RETURN_DATUM(result); + return(result); } diff --git a/contrib/pgstattuple/pgstattuple.sql.in b/contrib/pgstattuple/pgstattuple.sql.in index c32c00ba3f..b75c845159 100644 --- a/contrib/pgstattuple/pgstattuple.sql.in +++ b/contrib/pgstattuple/pgstattuple.sql.in @@ -17,4 +17,9 @@ CREATE TYPE pgstattuple_type AS ( CREATE OR REPLACE FUNCTION pgstattuple(text) RETURNS pgstattuple_type AS 'MODULE_PATHNAME', 'pgstattuple' -LANGUAGE 'C' WITH (isstrict); +LANGUAGE 'C' STRICT; + +CREATE OR REPLACE FUNCTION pgstattuple(oid) +RETURNS pgstattuple_type +AS 'MODULE_PATHNAME', 'pgstattuplebyid' +LANGUAGE 'C' STRICT; diff --git a/src/backend/libpq/ip.c b/src/backend/libpq/ip.c index 59bee56e21..d4290476c8 100644 --- a/src/backend/libpq/ip.c +++ b/src/backend/libpq/ip.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.12 2003/06/12 07:36:51 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.13 2003/06/12 08:02:53 momjian Exp $ * * This file and the IPV6 implementation were initially provided by * Nigel Kukard , Linux Based Systems Design @@ -20,6 +20,8 @@ /* This is intended to be used in both frontend and backend, so use c.h */ #include "c.h" +#if !defined(_MSC_VER) && !defined(__BORLANDC__) + #include #include #include @@ -33,6 +35,8 @@ #include #include +#endif + #include "libpq/ip.h" diff --git a/src/backend/utils/mb/encnames.c b/src/backend/utils/mb/encnames.c index fcb88f156c..33082dc698 100644 --- a/src/backend/utils/mb/encnames.c +++ b/src/backend/utils/mb/encnames.c @@ -2,7 +2,7 @@ * Encoding names and routines for work with it. All * in this file is shared bedween FE and BE. * - * $Id: encnames.c,v 1.13 2003/05/15 16:35:29 momjian Exp $ + * $Id: encnames.c,v 1.14 2003/06/12 08:02:53 momjian Exp $ */ #ifdef FRONTEND #include "postgres_fe.h" @@ -13,7 +13,9 @@ #include "utils/builtins.h" #endif +#if !defined(_MSC_VER) && !defined(__BORLANDC__) #include +#endif #include "mb/pg_wchar.h" #include diff --git a/src/include/c.h b/src/include/c.h index 6f3c690fbc..979ca5885b 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: c.h,v 1.147 2003/05/16 01:57:51 momjian Exp $ + * $Id: c.h,v 1.148 2003/06/12 08:02:56 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -73,7 +73,7 @@ #include #endif -#ifdef WIN32 +#if defined(WIN32) && !defined(_MSC_VER) && !defined(__BORLANDC__) /* We have to redefine some system functions after they are included above */ #include "pg_config_os.h" #endif diff --git a/src/include/getaddrinfo.h b/src/include/getaddrinfo.h index 416dc65fb1..ce329a9024 100644 --- a/src/include/getaddrinfo.h +++ b/src/include/getaddrinfo.h @@ -16,15 +16,17 @@ * * Copyright (c) 2003, PostgreSQL Global Development Group * - * $Id: getaddrinfo.h,v 1.3 2003/06/12 07:36:51 momjian Exp $ + * $Id: getaddrinfo.h,v 1.4 2003/06/12 08:02:56 momjian Exp $ * *------------------------------------------------------------------------- */ #ifndef GETADDRINFO_H #define GETADDRINFO_H +#if !defined(WIN32) || (!defined(_MSC_VER) && !defined(__BORLANDC__)) #include #include +#endif #ifndef HAVE_STRUCT_ADDRINFO diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32 index aaeecf5957..7835ef8d9f 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -21,6 +21,10 @@ #define HAVE_ATEXIT #define HAVE_MEMMOVE +#ifdef __BORLANDC__ +#define HAVE_RANDOM +#endif + /* use _snprintf instead of snprintf */ #define HAVE_DECL_SNPRINTF 1 #define snprintf _snprintf diff --git a/src/include/port.h b/src/include/port.h index f42067d29a..93d0122183 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: port.h,v 1.3 2003/05/16 04:59:22 momjian Exp $ + * $Id: port.h,v 1.4 2003/06/12 08:02:56 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -76,8 +76,10 @@ extern double rint(double x); #endif #ifndef HAVE_INET_ATON +#if !defined(WIN32) || (!defined(_MSC_VER) && !defined(__BORLANDC__)) # include # include +#endif extern int inet_aton(const char *cp, struct in_addr * addr); #endif diff --git a/src/interfaces/libpq/bcc32.mak b/src/interfaces/libpq/bcc32.mak index 985143ac87..74567d008a 100644 --- a/src/interfaces/libpq/bcc32.mak +++ b/src/interfaces/libpq/bcc32.mak @@ -4,7 +4,7 @@ # and a Win32 dynamic library libpq.dll with import library libpqdll.lib # Borland C++ base install directory goes here -BCB=d:\Borland\Bcc55 +# BCB=d:\Borland\Bcc55 !MESSAGE Building the Win32 DLL and Static Library... !MESSAGE @@ -63,8 +63,13 @@ LIB32=tlib.exe LIB32_FLAGS= LIB32_OBJS= \ "$(OUTDIR)\win32.obj" \ + "$(INTDIR)\getaddrinfo.obj" \ + "$(INTDIR)\inet_aton.obj" \ + "$(INTDIR)\crypt.obj" \ + "$(INTDIR)\path.obj" \ "$(INTDIR)\dllist.obj" \ "$(INTDIR)\md5.obj" \ + "$(INTDIR)\ip.obj" \ "$(INTDIR)\fe-auth.obj" \ "$(INTDIR)\fe-connect.obj" \ "$(INTDIR)\fe-exec.obj" \ @@ -77,7 +82,7 @@ LIB32_OBJS= \ "$(INTDIR)\encnames.obj" RSC=brcc32.exe -RSC_PROJ=/l 0x409 /fo"$(INTDIR)\libpq.res" +RSC_PROJ=-l 0x409 -i$(BCB)\include -fo"$(INTDIR)\libpq.res" LINK32=ilink32.exe LINK32_FLAGS = -Gn -L$(BCB)\lib;$(INTDIR); -x -Tpd -v @@ -86,15 +91,20 @@ LINK32_OBJS= "$(INTDIR)\libpqdll.obj" # --------------------------------------------------------------------------- .path.obj = $(INTDIR) -.path.c = .;..\..\backend\libpq;..\..\backend\lib;..\..\backend\utils\mb +.path.c = .;..\..\port;..\..\backend\libpq;..\..\backend\lib;..\..\backend\utils\mb # --------------------------------------------------------------------------- ALL: "$(OUTDIR)" "$(OUTDIR)\blibpq.dll" "$(OUTDIR)\blibpq.lib" CLEAN : + -@erase "$(INTDIR)\getaddrinfo.obj" + -@erase "$(INTDIR)\inet_aton.obj" + -@erase "$(INTDIR)\crypt.obj" + -@erase "$(INTDIR)\path.obj" -@erase "$(INTDIR)\dllist.obj" -@erase "$(INTDIR)\md5.obj" + -@erase "$(INTDIR)\ip.obj" -@erase "$(INTDIR)\fe-auth.obj" -@erase "$(INTDIR)\fe-connect.obj" -@erase "$(INTDIR)\fe-exec.obj" @@ -125,7 +135,7 @@ CLEAN : "$(OUTDIR)\blibpq.lib" import32.lib cw32mti.lib, + blibpqdll.def,"$(INTDIR)\libpq.res" ! - implib -a "$(OUTDIR)\blibpqdll.lib" blibpqdll.def $@ + implib -w "$(OUTDIR)\blibpqdll.lib" blibpqdll.def $@ "$(INTDIR)\libpq.res" : "$(INTDIR)" libpq.rc $(RSC) $(RSC_PROJ) libpq.rc diff --git a/src/interfaces/libpq/blibpqdll.def b/src/interfaces/libpq/blibpqdll.def index 77a996bfe5..8445a29b1b 100644 --- a/src/interfaces/libpq/blibpqdll.def +++ b/src/interfaces/libpq/blibpqdll.def @@ -96,7 +96,7 @@ EXPORTS _pg_encoding_to_char @ 92 _pg_utf_mblen @ 93 _PQunescapeBytea @ 94 - _PQfreeMem @ 95 + _PQfreemem @ 95 ; Aliases for MS compatible names PQconnectdb = _PQconnectdb @@ -193,5 +193,5 @@ EXPORTS pg_encoding_to_char = _pg_encoding_to_char pg_utf_mblen = _pg_utf_mblen PQunescapeBytea = _PQunescapeBytea - PQfreeMem = _PQfreeMem + PQfreemem = _PQfreemem diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 4445bd2178..49fbbb8c29 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.244 2003/06/12 07:36:51 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.245 2003/06/12 08:02:57 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,6 +49,10 @@ #include "libpq/ip.h" #include "mb/pg_wchar.h" +/* For FNCTL_NONBLOCK */ +#if defined(WIN32) || defined(__BEOS__) +long ioctlsocket_ret; +#endif #define PGPASSFILE ".pgpass" diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index 80c1c5a789..03f16ac437 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -23,7 +23,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.92 2003/06/08 17:43:00 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.93 2003/06/12 08:02:57 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -33,8 +33,11 @@ #include #include #include + +#if !defined(_MSC_VER) && !defined(__BORLANDC__) #include #include +#endif #ifdef WIN32 #include "win32.h" diff --git a/src/interfaces/libpq/libpqdll.def b/src/interfaces/libpq/libpqdll.def index e48959f086..f8432fc713 100644 --- a/src/interfaces/libpq/libpqdll.def +++ b/src/interfaces/libpq/libpqdll.def @@ -96,5 +96,5 @@ EXPORTS pg_encoding_to_char @ 92 pg_utf_mblen @ 93 PQunescapeBytea @ 94 - PQfreeMem @ 95 + PQfreemem @ 95 diff --git a/src/interfaces/libpq/win32.mak b/src/interfaces/libpq/win32.mak index 5563c9e9a3..9c198f1c9f 100644 --- a/src/interfaces/libpq/win32.mak +++ b/src/interfaces/libpq/win32.mak @@ -36,8 +36,13 @@ OutDir=.\Release ALL : "$(OUTDIR)\libpq.lib" "$(OUTDIR)\libpq.dll" CLEAN : + -@erase "$(INTDIR)\getaddrinfo.obj" + -@erase "$(INTDIR)\inet_aton.obj" + -@erase "$(INTDIR)\crypt.obj" + -@erase "$(INTDIR)\path.obj" -@erase "$(INTDIR)\dllist.obj" -@erase "$(INTDIR)\md5.obj" + -@erase "$(INTDIR)\ip.obj" -@erase "$(INTDIR)\fe-auth.obj" -@erase "$(INTDIR)\fe-connect.obj" -@erase "$(INTDIR)\fe-exec.obj" @@ -72,8 +77,13 @@ LIB32=link.exe -lib LIB32_FLAGS=$(LOPT) /nologo /out:"$(OUTDIR)\libpq.lib" LIB32_OBJS= \ "$(OUTDIR)\win32.obj" \ + "$(INTDIR)\getaddrinfo.obj" \ + "$(INTDIR)\inet_aton.obj" \ + "$(INTDIR)\crypt.obj" \ + "$(INTDIR)\path.obj" \ "$(INTDIR)\dllist.obj" \ "$(INTDIR)\md5.obj" \ + "$(INTDIR)\ip.obj" \ "$(INTDIR)\fe-auth.obj" \ "$(INTDIR)\fe-connect.obj" \ "$(INTDIR)\fe-exec.obj" \ @@ -112,6 +122,25 @@ LINK32_OBJS= \ $(LINK32_FLAGS) $(LINK32_OBJS) << +"$(OUTDIR)\getaddrinfo.obj" : ..\..\port\getaddrinfo.c + $(CPP) @<< + $(CPP_PROJ) ..\..\port\getaddrinfo.c +<< + +"$(OUTDIR)\inet_aton.obj" : ..\..\port\inet_aton.c + $(CPP) @<< + $(CPP_PROJ) ..\..\port\inet_aton.c +<< + +"$(OUTDIR)\crypt.obj" : ..\..\port\crypt.c + $(CPP) @<< + $(CPP_PROJ) ..\..\port\crypt.c +<< + +"$(OUTDIR)\path.obj" : ..\..\port\path.c + $(CPP) @<< + $(CPP_PROJ) ..\..\port\path.c +<< "$(OUTDIR)\dllist.obj" : ..\..\backend\lib\dllist.c $(CPP) @<< @@ -124,6 +153,10 @@ LINK32_OBJS= \ $(CPP_PROJ) ..\..\backend\libpq\md5.c << +"$(OUTDIR)\ip.obj" : ..\..\backend\libpq\ip.c + $(CPP) @<< + $(CPP_PROJ) ..\..\backend\libpq\ip.c +<< "$(INTDIR)\wchar.obj" : ..\..\backend\utils\mb\wchar.c $(CPP) @<< diff --git a/src/port/crypt.c b/src/port/crypt.c index dd3e7ecb2a..893e227fcf 100644 --- a/src/port/crypt.c +++ b/src/port/crypt.c @@ -50,8 +50,12 @@ __RCSID("$NetBSD: crypt.c,v 1.18 2001/03/01 14:37:35 wiz Exp $"); #include #include #include -#include + +#ifdef WIN32 #include +#else +#include +#endif static int des_setkey(const char *key); static int des_cipher(const char *in, char *out, long salt, int num_iter); diff --git a/src/port/getaddrinfo.c b/src/port/getaddrinfo.c index 409aef5e9c..3ceaa3e52b 100644 --- a/src/port/getaddrinfo.c +++ b/src/port/getaddrinfo.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/port/getaddrinfo.c,v 1.4 2003/06/12 07:36:51 momjian Exp $ + * $Header: /cvsroot/pgsql/src/port/getaddrinfo.c,v 1.5 2003/06/12 08:02:57 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -16,6 +16,7 @@ /* This is intended to be used in both frontend and backend, so use c.h */ #include "c.h" +#if !defined(_MSC_VER) && !defined(__BORLANDC__) #include #include #include @@ -24,6 +25,7 @@ #ifdef HAVE_UNIX_SOCKETS #include #endif +#endif #include "getaddrinfo.h" diff --git a/src/port/inet_aton.c b/src/port/inet_aton.c index c55ac4fa51..1f45e92f95 100644 --- a/src/port/inet_aton.c +++ b/src/port/inet_aton.c @@ -1,4 +1,4 @@ -/* $Id: inet_aton.c,v 1.2 2002/09/02 02:47:07 momjian Exp $ +/* $Id: inet_aton.c,v 1.3 2003/06/12 08:02:57 momjian Exp $ * * This inet_aton() function was taken from the GNU C library and * incorporated into Postgres for those systems which do not have this @@ -44,8 +44,10 @@ #include "c.h" +#if !defined(WIN32) || (!defined(_MSC_VER) && !defined(__BORLANDC__)) #include #include +#endif /* * Check whether "cp" is a valid ascii representation