Changeset 700

Show
Ignore:
Timestamp:
02/05/03 23:28:38 (22 years ago)
Author:
jalet
Message:

More robust storage

Location:
pykota/trunk/pykota/storages
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/postgresql.py

    r695 r700  
    1515# 
    1616# $Log$ 
     17# Revision 1.2  2003/02/05 22:28:38  jalet 
     18# More robust storage 
     19# 
    1720# Revision 1.1  2003/02/05 21:28:17  jalet 
    1821# Initial import into CVS 
     
    5861         
    5962    def doParseResult(self, result) : 
    60         """Returns the result as a Python dictionnary.""" 
    61         try : 
    62             return result.dictresult()[0] 
    63         except IndexError :     
    64             return None # not found 
     63        """Returns the result as a list of Python mappings.""" 
     64        if result.ntuples() > 0 : 
     65            return result.dictresult() 
    6566         
  • pykota/trunk/pykota/storages/sql.py

    r695 r700  
    1515# 
    1616# $Log$ 
     17# Revision 1.2  2003/02/05 22:28:38  jalet 
     18# More robust storage 
     19# 
    1720# Revision 1.1  2003/02/05 21:28:17  jalet 
    1821# Initial import into CVS 
     
    2629    def getUserId(self, username) : 
    2730        result = self.doQuery("SELECT id FROM users WHERE username=%s;" % self.doQuote(username)) 
    28         return self.doParseResult(result)["id"] 
     31        try : 
     32            return self.doParseResult(result)[0]["id"] 
     33        except TypeError :      # Not found 
     34            return 
    2935             
    3036    def getPrinterId(self, printername) :         
    3137        result = self.doQuery("SELECT id FROM printers WHERE printername=%s;" % self.doQuote(printername)) 
    32         return self.doParseResult(result)["id"] 
     38        try : 
     39            return self.doParseResult(result)[0]["id"] 
     40        except TypeError :      # Not found     
     41            return 
    3342             
    3443    def getPrinterPageCounter(self, printername) : 
    3544        result = self.doQuery("SELECT pagecounter, lastusername FROM printers WHERE printername=%s;" % self.doQuote(printername)) 
    36         return self.doParseResult(result) 
     45        try : 
     46            return self.doParseResult(result)[0] 
     47        except TypeError :      # Not found 
     48            return 
    3749         
    3850    def updatePrinterPageCounter(self, printername, username, pagecount) : 
     
    5365    def getUserPQuota(self, username, printername) : 
    5466        result = self.doQuery("SELECT pagecounter, softlimit, hardlimit, datelimit FROM userpquota WHERE userid=%s AND printerid=%s;" % (self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername)))) 
    55         return self.doParseResult(result) 
     67        try : 
     68            return self.doParseResult(result)[0] 
     69        except TypeError :      # Not found     
     70            return 
    5671         
    5772    def setUserPQuota(self, username, printername, softlimit, hardlimit) :