]> granicus.if.org Git - php/commitdiff
Added pg_version() which returns an associative array of client/protocol/server
authorMarcus Boerger <helly@php.net>
Tue, 22 Jul 2003 23:05:17 +0000 (23:05 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 22 Jul 2003 23:05:17 +0000 (23:05 +0000)
version.
@Added pg_version() function. (Marcus)

ext/pgsql/config.m4
ext/pgsql/pgsql.c
ext/pgsql/php_pgsql.h

index efccb17e94e7aec44482041effe851cadd7ad725..5793362ebd0bb7040b48c6e9e3dda4a50d01d41e 100644 (file)
@@ -57,6 +57,8 @@ if test "$PHP_PGSQL" != "no"; then
   AC_CHECK_LIB(pq, PQcmdTuples,AC_DEFINE(HAVE_PQCMDTUPLES,1,[Broken libpq under windows]))
   AC_CHECK_LIB(pq, PQoidValue,AC_DEFINE(HAVE_PQOIDVALUE,1,[Older PostgreSQL]))
   AC_CHECK_LIB(pq, PQclientEncoding,AC_DEFINE(HAVE_PQCLIENTENCODING,1,[PostgreSQL 7.0.x or later]))
+  AC_CHECK_LIB(pq, PQparameterStatus,AC_DEFINE(HAVE_PQPARAMETERSTATUS,1,[PostgreSQL 7.4 or later]))
+  AC_CHECK_LIB(pq, PQprotocolVersion,AC_DEFINE(HAVE_PQPROTOCOLVERSION,1,[PostgreSQL 7.4 or later]))
   AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibye]))
   LIBS=$old_LIBS
   LDFLAGS=$old_LDFLAGS
index da39607302f8862e84ac8d99d81fb70eb66d638a..1fa16651a5db10ce686a6c74bec13bff67b0da76 100644 (file)
@@ -88,6 +88,7 @@ function_entry pgsql_functions[] = {
        PHP_FE(pg_port,                 NULL)
        PHP_FE(pg_tty,                  NULL)
        PHP_FE(pg_options,              NULL)
+       PHP_FE(pg_version,              NULL)
        PHP_FE(pg_ping,                 NULL)
        /* query functions */
        PHP_FE(pg_query,                NULL)
@@ -782,6 +783,7 @@ PHP_FUNCTION(pg_close)
 #define PHP_PG_PORT 4
 #define PHP_PG_TTY 5
 #define PHP_PG_HOST 6
+#define PHP_PG_VERSION 7
 
 /* {{{ php_pgsql_get_link_info
  */
@@ -831,6 +833,18 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
                case PHP_PG_HOST:
                        Z_STRVAL_P(return_value) = PQhost(pgsql);
                        break;
+               case PHP_PG_VERSION:
+                       array_init(return_value);
+                       add_assoc_string(return_value, "client", PG_VERSION, 1);
+#if HAVE_PQPROTOCOLVERSION
+                       add_assoc_long(return_value, "protocol", PQprotocolVersion(pgsql));
+#if HAVE_PQPARAMETERSTATUS
+                       if (PQprotocolVersion(pgsql) >= 3) {
+                               add_assoc_string(return_value, "server", PQparameterStatus(pgsql, "server_version"), 1);
+                       }
+#endif
+#endif
+                       return;
                default:
                        RETURN_FALSE;
        }
@@ -893,6 +907,14 @@ PHP_FUNCTION(pg_host)
 }
 /* }}} */
 
+/* {{{ proto array pg_version([resource connection])
+   Returns an array with client, protocol and server version (when available) */
+PHP_FUNCTION(pg_version)
+{
+       php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_VERSION);
+}
+/* }}} */
+
 /* {{{ proto bool pg_ping(resource connection)
    Ping database. If connection is bad, try to reconnect. */
 PHP_FUNCTION(pg_ping)
index 1ce637ae31369080b513400a0f709bd7336b9625..b9bdb483e93a5d364f5decb7aa6918ec0a1f4006 100644 (file)
@@ -71,6 +71,7 @@ PHP_FUNCTION(pg_dbname);
 PHP_FUNCTION(pg_port);
 PHP_FUNCTION(pg_tty);
 PHP_FUNCTION(pg_options);
+PHP_FUNCTION(pg_version);
 PHP_FUNCTION(pg_ping);
 /* query functions */
 PHP_FUNCTION(pg_query);