Changeset 1792 for pykota/trunk
- Timestamp:
- 10/10/04 12:12:21 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/sql.py
r1790 r1792 22 22 # 23 23 # $Log$ 24 # Revision 1.57 2004/10/10 10:12:21 jalet 25 # Improved SQL queries for groups. Same work has to be done for groups print quotas. 26 # 24 27 # Revision 1.56 2004/10/07 21:14:28 jalet 25 28 # Hopefully final fix for data encoding to and from the database … … 133 136 def extractGroups(self) : 134 137 """Extracts all group records.""" 135 result = self.doRawSearch("SELECT groups.*, sum(balance) AS balance, sum(lifetimepaid) as lifetimepaid FROM groups,users WHEREusers.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) GROUP BY groups.id,groups.groupname,groups.limitby ORDER BY groups.id ASC")138 result = self.doRawSearch("SELECT groups.*,COALESCE(SUM(balance), 0) AS balance, COALESCE(SUM(lifetimepaid), 0) as lifetimepaid FROM groups LEFT OUTER JOIN users ON users.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) GROUP BY groups.id,groups.groupname,groups.limitby ORDER BY groups.id ASC") 136 139 return self.prepareRawResult(result) 137 140 … … 148 151 def extractGpquotas(self) : 149 152 """Extracts all grouppquota records.""" 150 result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*, sum(pagecounter) AS pagecounter,sum(lifepagecounter) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,groups.groupname,printers.printername ORDER BY grouppquota.id")153 result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*,coalesce(sum(pagecounter), 0) AS pagecounter,coalesce(sum(lifepagecounter), 0) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,groups.groupname,printers.printername ORDER BY grouppquota.id") 151 154 return self.prepareRawResult(result) 152 155 … … 200 203 """Extracts group information given its name.""" 201 204 group = StorageGroup(self, groupname) 202 result = self.doSearch("SELECT * FROM groups WHERE groupname=%sLIMIT 1" % self.doQuote(groupname))205 result = self.doSearch("SELECT groups.*,COALESCE(SUM(balance), 0.0) AS balance, COALESCE(SUM(lifetimepaid), 0.0) AS lifetimepaid FROM groups LEFT OUTER JOIN users ON users.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) WHERE groupname=%s GROUP BY groups.id,groups.groupname,groups.limitby LIMIT 1" % self.doQuote(groupname)) 203 206 if result : 204 207 fields = result[0] … … 206 209 group.Name = fields.get("groupname", groupname) 207 210 group.LimitBy = fields.get("limitby") 208 result = self.doSearch("SELECT SUM(balance) AS balance, SUM(lifetimepaid) AS lifetimepaid FROM users WHERE id IN (SELECT userid FROM groupsmembers WHERE groupid=%s)" % self.doQuote(group.ident)) 209 if result : 210 fields = result[0] 211 group.AccountBalance = fields.get("balance") or 0.0 212 group.LifeTimePaid = fields.get("lifetimepaid") or 0.0 211 group.AccountBalance = fields.get("balance") 212 group.LifeTimePaid = fields.get("lifetimepaid") 213 213 group.Exists = 1 214 214 return group