Index: pykota/branches/1.26_fixes/pykota/storages/pgstorage.py
===================================================================
--- pykota/branches/1.26_fixes/pykota/storages/pgstorage.py (revision 3184)
+++ pykota/branches/1.26_fixes/pykota/storages/pgstorage.py (revision 3500)
@@ -14,5 +14,5 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
@@ -33,12 +33,12 @@
 try :
     import pg
-except ImportError :    
+except ImportError :
     import sys
     # TODO : to translate or not to translate ?
     raise PyKotaStorageError, "This python version (%s) doesn't seem to have the PygreSQL module installed correctly." % sys.version.split()[0]
-else :    
+else :
     try :
         PGError = pg.Error
-    except AttributeError :    
+    except AttributeError :
         PGError = pg.error
 
@@ -50,21 +50,25 @@
             (host, port) = host.split(":")
             port = int(port)
-        except ValueError :    
+        except ValueError :
             port = 5432         # Use PostgreSQL's default tcp/ip port (5432).
-        
+
         self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." % (host, port, dbname, user))
         try :
-            self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd)
-        except PGError, msg :    
+            self.database = pg.DB(host=host, port=port, dbname=dbname, user=user, passwd=passwd)
+        except PGError, msg :
             msg = "%(msg)s --- the most probable cause of your problem is that PostgreSQL is down, or doesn't accept incoming connections because you didn't configure it as explained in PyKota's documentation." % locals()
             raise PGError, msg
         self.closed = 0
         try :
+            self.quote = self.database._quote
+        except AttributeError : # pg <v4.x
+            self.quote = pg._quote
+        try :
             self.database.query("SET CLIENT_ENCODING TO 'UTF-8';")
-        except PGError, msg :    
+        except PGError, msg :
             self.tool.logdebug("Impossible to set database client encoding to UTF-8 : %s" % msg)
         self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user))
-            
-    def close(self) :    
+
+    def close(self) :
         """Closes the database connection."""
         if not self.closed :
@@ -72,12 +76,12 @@
             self.closed = 1
             self.tool.logdebug("Database closed.")
-        
-    def beginTransaction(self) :    
+
+    def beginTransaction(self) :
         """Starts a transaction."""
         self.before = time.time()
         self.database.query("BEGIN;")
         self.tool.logdebug("Transaction begins...")
-        
-    def commitTransaction(self) :    
+
+    def commitTransaction(self) :
         """Commits a transaction."""
         self.database.query("COMMIT;")
@@ -85,6 +89,6 @@
         self.tool.logdebug("Transaction committed.")
         #self.tool.logdebug("Transaction duration : %.4f seconds" % (after - self.before))
-        
-    def rollbackTransaction(self) :     
+
+    def rollbackTransaction(self) :
         """Rollbacks a transaction."""
         self.database.query("ROLLBACK;")
@@ -92,9 +96,9 @@
         self.tool.logdebug("Transaction aborted.")
         #self.tool.logdebug("Transaction duration : %.4f seconds" % (after - self.before))
-        
+
     def doRawSearch(self, query) :
         """Does a raw search query."""
-        query = query.strip()    
-        if not query.endswith(';') :    
+        query = query.strip()
+        if not query.endswith(';') :
             query += ';'
         try :
@@ -102,21 +106,21 @@
             self.tool.logdebug("QUERY : %s" % query)
             result = self.database.query(query)
-        except PGError, msg :    
+        except PGError, msg :
             raise PyKotaStorageError, str(msg)
-        else :    
+        else :
             after = time.time()
             #self.tool.logdebug("Query Duration : %.4f seconds" % (after - before))
             return result
-            
-    def doSearch(self, query) :        
+
+    def doSearch(self, query) :
         """Does a search query."""
         result = self.doRawSearch(query)
-        if (result is not None) and (result.ntuples() > 0) : 
+        if (result is not None) and (result.ntuples() > 0) :
             return result.dictresult()
-        
+
     def doModify(self, query) :
         """Does a (possibly multiple) modify query."""
-        query = query.strip()    
-        if not query.endswith(';') :    
+        query = query.strip()
+        if not query.endswith(';') :
             query += ';'
         try :
@@ -124,24 +128,24 @@
             self.tool.logdebug("QUERY : %s" % query)
             result = self.database.query(query)
-        except PGError, msg :    
+        except PGError, msg :
             self.tool.logdebug("Query failed : %s" % repr(msg))
             raise PyKotaStorageError, str(msg)
-        else :    
+        else :
             after = time.time()
             #self.tool.logdebug("Query Duration : %.4f seconds" % (after - before))
             return result
-            
+
     def doQuote(self, field) :
         """Quotes a field for use as a string in SQL queries."""
-        if type(field) == type(0.0) : 
+        if type(field) == type(0.0) :
             typ = "decimal"
-        elif type(field) == type(0) :    
+        elif type(field) == type(0) :
             typ = "int"
-        elif type(field) == type(0L) :    
+        elif type(field) == type(0L) :
             typ = "int"
-        else :    
+        else :
             typ = "text"
-        return pg._quote(field, typ)
-        
+        return self.quote(field, typ)
+
     def prepareRawResult(self, result) :
         """Prepares a raw result by including the headers."""
@@ -155,6 +159,6 @@
                     field = fields[j]
                     if type(field) == StringType :
-                        fields[j] = self.databaseToUserCharset(field) 
-                entries[i] = tuple(fields)    
+                        fields[j] = self.databaseToUserCharset(field)
+                entries[i] = tuple(fields)
             return entries
-        
+
