Changeset 1269 for pykota/trunk/pykota/storages/pgstorage.py
- Timestamp:
- 01/10/04 10:44:02 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/pgstorage.py
r1259 r1269 22 22 # 23 23 # $Log$ 24 # Revision 1.31 2004/01/10 09:44:02 jalet 25 # Fixed potential accuracy problem if a user printed on several printers at 26 # the very same time. 27 # 24 28 # Revision 1.30 2004/01/08 16:33:27 jalet 25 29 # Additionnal check to not create a circular printers group. … … 213 217 """Extracts all user names.""" 214 218 usernames = [] 215 result = self.doSearch("SELECT username FROM users ;")219 result = self.doSearch("SELECT username FROM users") 216 220 if result : 217 221 usernames = [record["username"] for record in result] … … 221 225 """Extracts all group names.""" 222 226 groupnames = [] 223 result = self.doSearch("SELECT groupname FROM groups ;")227 result = self.doSearch("SELECT groupname FROM groups") 224 228 if result : 225 229 groupnames = [record["groupname"] for record in result] … … 354 358 """Get all the printer groups this printer is a member of.""" 355 359 pgroups = [] 356 result = self.doSearch("SELECT groupid,printername FROM printergroupsmembers JOIN printers ON groupid=id WHERE printerid=%s ;" % self.doQuote(printer.ident))360 result = self.doSearch("SELECT groupid,printername FROM printergroupsmembers JOIN printers ON groupid=id WHERE printerid=%s" % self.doQuote(printer.ident)) 357 361 if result : 358 362 for record in result : … … 477 481 self.doModify("UPDATE grouppquota SET datelimit=%s WHERE id=%s" % (self.doQuote(datelimit), self.doQuote(grouppquota.ident))) 478 482 483 def increaseUserPQuotaPagesCounters(self, userpquota, nbpages) : 484 """Increase page counters for a user print quota.""" 485 self.doModify("UPDATE userpquota SET pagecounter=pagecounter+%s,lifepagecounter=lifepagecounter+%s WHERE id=%s" % (self.doQuote(nbpages), self.doQuote(nbpages), self.doQuote(userpquota.ident))) 486 479 487 def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) : 480 """Sets the new page counters permanently for a user print quota.""" 481 self.doModify("UPDATE userpquota SET pagecounter=%s,lifepagecounter=%s WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident))) 488 """Sets the new page counters permanently for a user print quota.""" 489 self.doModify("UPDATE userpquota SET pagecounter=%s,lifepagecounter=%s WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident))) 490 491 def decreaseUserAccountBalance(self, user, amount) : 492 """Decreases user's account balance from an amount.""" 493 self.doModify("UPDATE users SET balance=balance-%s WHERE id=%s" % (self.doQuote(amount), self.doQuote(user.ident))) 482 494 483 495 def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) : 484 """Sets the new account balance and eventually new lifetime paid."""485 if newlifetimepaid is not None :486 self.doModify("UPDATE users SET balance=%s, lifetimepaid=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newlifetimepaid), self.doQuote(user.ident)))487 else :488 self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident)))496 """Sets the new account balance and eventually new lifetime paid.""" 497 if newlifetimepaid is not None : 498 self.doModify("UPDATE users SET balance=%s, lifetimepaid=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newlifetimepaid), self.doQuote(user.ident))) 499 else : 500 self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident))) 489 501 490 502 def writeLastJobSize(self, lastjob, jobsize, jobprice) : … … 501 513 else : 502 514 # here we explicitly want to reset jobsize to NULL if needed 503 self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, jobdate=now() WHERE id=%s ;" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(printer.LastJob.ident)))515 self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(printer.LastJob.ident))) 504 516 505 517 def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : … … 514 526 """Puts a printer into a printer group.""" 515 527 children = [] 516 result = self.doSearch("SELECT printerid FROM printergroupsmembers WHERE groupid=%s ;" % self.doQuote(pgroup.ident))528 result = self.doSearch("SELECT printerid FROM printergroupsmembers WHERE groupid=%s" % self.doQuote(pgroup.ident)) 517 529 if result : 518 530 for record in result : 519 531 children.append(record.get("printerid")) # TODO : put this into the database integrity rules 520 532 if printer.ident not in children : 521 self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s) ;" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident)))533 self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 522 534 523 535 def deleteUser(self, user) :