Update of /usr/cvs/Public/pygresql/module
In directory druid.net:/tmp/cvs-serv21387/module

Modified Files:
        pg.py pgmodule.c 
Log Message:
Added methods for determining the protocol and server version.
To see the diffs for this commit:
   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/pg.py.diff?r1=1.68&r2=1.69

Index: pg.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/pg.py,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- pg.py       2 Dec 2008 16:50:54 -0000       1.68
+++ pg.py       2 Dec 2008 22:39:56 -0000       1.69
@@ -5,7 +5,7 @@
 # Written by D'Arcy J.M. Cain
 # Improved by Christoph Zwerschke
 #
-# $Id: pg.py,v 1.68 2008/12/02 16:50:54 darcy Exp $
+# $Id: pg.py,v 1.69 2008/12/02 22:39:56 cito Exp $
 #
 
 """PyGreSQL classic interface.
@@ -249,6 +249,22 @@
     # so we define unescape_bytea as a method as well
     unescape_bytea = staticmethod(unescape_bytea)
 
+    def server_version(self):
+        """Return an integer representing the backend version."""
+        try:
+            return self._server_version
+        except AttributeError:
+            self._server_version = self.db.server_version()
+            return self._server_version
+
+    def protocol_version(self):
+        """Interrogate the frontend/backend protocol being used."""
+        try:
+            return self._protocol_version
+        except AttributeError:
+            self._protocol_version = self.db.protocol_version()
+            return self._protocol_version
+
     def close(self):
         """Close the database connection."""
         # Wraps shared library function so we can track state.
@@ -259,6 +275,16 @@
             else:
                 raise InternalError('Connection already closed')
 
+    def reset(self):
+        """Reset connection with current parameters.
+
+        All derived queries and large objects derived from this connection
+        will not be usable after this call.
+
+        """
+        self.db.reset()
+        delattr(self, '_protocol_version')
+
     def reopen(self):
         """Reopen connection to the database.
 
@@ -272,6 +298,8 @@
             if self.db:
                 self.db.close()
             self.db = db
+            delattr(self, '_server_version')
+            delattr(self, '_protocol_version')
 
     def query(self, qstr):
         """Executes a SQL command string.

   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/pgmodule.c.diff?r1=1.88&r2=1.89

Index: pgmodule.c
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/pgmodule.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- pgmodule.c  23 Nov 2008 14:07:35 -0000      1.88
+++ pgmodule.c  2 Dec 2008 22:39:56 -0000       1.89
@@ -1,5 +1,5 @@
 /*
- * $Id: pgmodule.c,v 1.88 2008/11/23 14:07:35 cito Exp $
+ * $Id: pgmodule.c,v 1.89 2008/12/02 22:39:56 cito Exp $
  * PyGres, version 2.2 A Python interface for PostgreSQL database. Written by
  * D'Arcy J.M. Cain, ([EMAIL PROTECTED]).  Based heavily on code written by
  * Pascal Andre, [EMAIL PROTECTED] Copyright (c) 1995, Pascal Andre
@@ -98,8 +98,16 @@
 #define DEFAULT_VARS 1                 /* enables default variables use */
 #endif
 
+#ifndef PG_VERSION_NUM
+#ifdef PQnoPasswordSupplied
+#define PG_VERSION_NUM 80000
+#else
+#define PG_VERSION_NUM 70400
+#endif
+#endif
+
 /* Before 8.0, PQsetdbLogin was not thread-safe with kerberos. */
-#if defined(PQnoPasswordSupplied) || !(defined(KRB4) || defined(KRB5))
+#if PG_VERSION_NUM >= 80000 || !(defined(KRB4) || defined(KRB5))
 #define PQsetdbLoginIsThreadSafe 1
 #endif
 
@@ -1775,6 +1783,58 @@
 #endif
 }
 
+/* get protocol version */
+static char pg_protocol_version__doc__[] =
+"protocol_version() -- interrogate the frontend/backend protocol being used.";
+
+static PyObject *
+pg_protocol_version(pgobject * self, PyObject * args)
+{
+       if (!self->cnx)
+       {
+               PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
+               return NULL;
+       }
+
+       /* checks args */
+       if (!PyArg_ParseTuple(args, ""))
+       {
+               PyErr_SetString(PyExc_TypeError,
+                       "method server_version() takes no parameters.");
+               return NULL;
+       }
+
+       return PyInt_FromLong(PQprotocolVersion(self->cnx));
+}
+
+/* get backend version */
+static char pg_server_version__doc__[] =
+"server_version() -- return an integer representing the backend version.";
+
+static PyObject *
+pg_server_version(pgobject * self, PyObject * args)
+{
+       if (!self->cnx)
+       {
+               PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
+               return NULL;
+       }
+
+       /* checks args */
+       if (!PyArg_ParseTuple(args, ""))
+       {
+               PyErr_SetString(PyExc_TypeError,
+                       "method server_version() takes no parameters.");
+               return NULL;
+       }
+
+#if PG_VERSION_NUM < 80000
+       return PyInt_FromLong(PG_VERSION_NUM);
+#else
+       return PyInt_FromLong(PQserverVersion(self->cnx));
+#endif
+}
+
 /* get number of rows */
 static char pgquery_ntuples__doc__[] =
 "ntuples() -- returns number of tuples returned by query.";
@@ -2873,6 +2933,10 @@
        {"cancel", (PyCFunction) pg_cancel, METH_VARARGS, pg_cancel__doc__},
        {"close", (PyCFunction) pg_close, METH_VARARGS, pg_close__doc__},
        {"fileno", (PyCFunction) pg_fileno, METH_VARARGS, pg_fileno__doc__},
+       {"protocol_version", (PyCFunction) pg_protocol_version, METH_VARARGS,
+                       pg_protocol_version__doc__},
+       {"server_version", (PyCFunction) pg_server_version, METH_VARARGS,
+                       pg_server_version__doc__},
        {"getnotify", (PyCFunction) pg_getnotify, METH_VARARGS,
                        pg_getnotify__doc__},
        {"inserttable", (PyCFunction) pg_inserttable, METH_VARARGS,

_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to