On Tue, Dec 14, 2010 at 17:56, Massa, Harald Armin <c...@ghum.de> wrote:
>>> My question: Which way is available to query the linked libpq version?
>
>> But it does outline that fact that it wouldn't suck to have a >function  in 
>> libpq returning the version so that application can >check this at  runtime 
>> - clearly it would also be useful when >being linked "through" something 
>> like psycopg2.
>
> did there something happen?

Stuck in a local git branch. I've rebased on current and added docs,
see attachment.

(moving to hackers as well)

-- 
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/
*** a/doc/src/sgml/libpq.sgml
--- b/doc/src/sgml/libpq.sgml
***************
*** 5359,5364 **** void *PQresultAlloc(PGresult *res, size_t nBytes);
--- 5359,5399 ----
      </listitem>
     </varlistentry>
  
+    <varlistentry id="libpq-pqlibversion">
+     <term>
+      <function>PQlibVersion</function>
+      <indexterm>
+       <primary>PQlibVersion</primary>
+       <seealso>PQserverVersion</seealso>
+      </indexterm>
+     </term>
+ 
+     <listitem>
+      <para>
+       Return the version of <productname>libpq</> that is being used.
+ <synopsis>
+ int PQlibVersion(void);
+ </synopsis>
+      </para>
+ 
+      <para>
+       The result value of this function can be used to determine if
+       a specific function is available in the currently used version
+       of libpq.
+      </para>
+ 
+      <note>
+       <para>
+        This function appeared in <productname>PostgreSQL</> version 9.1, so
+        it cannot be used to detect required functions in earlier version.
+        Usage of this function will make the application require version
+        9.1 or newer even if no actual funcionality from this version
+        is required.
+       </para>
+      </note>
+     </listitem>
+    </varlistentry>
+ 
    </variablelist>
  
   </sect1>
*** a/src/interfaces/libpq/exports.txt
--- b/src/interfaces/libpq/exports.txt
***************
*** 159,161 **** PQconnectdbParams         156
--- 159,162 ----
  PQconnectStartParams      157
  PQping                    158
  PQpingParams              159
+ PQlibVersion              160
*** a/src/interfaces/libpq/fe-misc.c
--- b/src/interfaces/libpq/fe-misc.c
***************
*** 66,71 **** static int pqSocketCheck(PGconn *conn, int forRead, int forWrite,
--- 66,85 ----
  			  time_t end_time);
  static int	pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time);
  
+ /*
+  * PQlibVersion: return the libpq version number
+  */
+ int
+ PQlibVersion(void)
+ {
+ 	/*
+ 	 * This number is updated by tools/version_stamp.pl, do not
+ 	 * edit manually.
+ 	 */
+ #define LOCAL_PG_VERSION_NUM 90100
+ 	return LOCAL_PG_VERSION_NUM;
+ #undef LOCAL_PG_VERSION_NUM
+ }
  
  /*
   * fputnbytes: print exactly N bytes to a file
*** a/src/interfaces/libpq/libpq-fe.h
--- b/src/interfaces/libpq/libpq-fe.h
***************
*** 547,552 **** extern int	lo_export(PGconn *conn, Oid lobjId, const char *filename);
--- 547,555 ----
  
  /* === in fe-misc.c === */
  
+ /* Get the version of the libpq library in use */
+ extern int	PQlibVersion(void);
+ 
  /* Determine length of multibyte encoded char at *s */
  extern int	PQmblen(const char *s, int encoding);
  
*** a/src/tools/version_stamp.pl
--- b/src/tools/version_stamp.pl
***************
*** 88,93 **** sed_file("src/include/pg_config.h.win32",
--- 88,96 ----
  	 "-e 's/#define PG_VERSION \".*\"/#define PG_VERSION \"$fullversion\"/' " .
  	 "-e 's/#define PG_VERSION_NUM .*/#define PG_VERSION_NUM $padnumericversion/'");
  
+ sed_file("src/interfaces/libpq/fe-misc.c",
+ 	 "-e 's/#define LOCAL_PG_VERSION_NUM .*/#define LOCAL_PG_VERSION_NUM $padnumericversion/'");
+ 
  sed_file("src/interfaces/libpq/libpq.rc.in",
  	 "-e 's/FILEVERSION [0-9]*,[0-9]*,[0-9]*,0/FILEVERSION $major1,$major2,$numericminor,0/' " .
  	 "-e 's/PRODUCTVERSION [0-9]*,[0-9]*,[0-9]*,0/PRODUCTVERSION $major1,$major2,$numericminor,0/' " .
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to