Changeset 2654
- Timestamp:
- 02/08/06 13:48:53 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/sql.py
r2653 r2654 198 198 """Extracts user information given its name.""" 199 199 user = StorageUser(self, username) 200 username = self.userCharsetToDatabase(username) 200 201 result = self.doSearch("SELECT * FROM users WHERE username=%s LIMIT 1" % self.doQuote(username)) 201 202 if result : 202 203 fields = result[0] 203 204 user.ident = fields.get("id") 204 user.Name = fields.get("username", username)205 user.Name = self.databaseToUserCharset(fields.get("username", username)) 205 206 user.LimitBy = fields.get("limitby") or "quota" 206 207 user.AccountBalance = fields.get("balance") … … 214 215 """Extracts group information given its name.""" 215 216 group = StorageGroup(self, groupname) 217 groupname = self.userCharsetToDatabase(groupname) 216 218 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,groups.description LIMIT 1" % self.doQuote(groupname)) 217 219 if result : 218 220 fields = result[0] 219 221 group.ident = fields.get("id") 220 group.Name = fields.get("groupname", groupname)222 group.Name = self.databaseToUserCharset(fields.get("groupname", groupname)) 221 223 group.LimitBy = fields.get("limitby") or "quota" 222 224 group.AccountBalance = fields.get("balance") … … 228 230 """Extracts printer information given its name.""" 229 231 printer = StoragePrinter(self, printername) 232 printername = self.userCharsetToDatabase(printername) 230 233 result = self.doSearch("SELECT * FROM printers WHERE printername=%s LIMIT 1" % self.doQuote(printername)) 231 234 if result : 232 235 fields = result[0] 233 236 printer.ident = fields.get("id") 234 printer.Name = fields.get("printername", printername)237 printer.Name = self.databaseToUserCharset(fields.get("printername", printername)) 235 238 printer.PricePerJob = fields.get("priceperjob") or 0.0 236 239 printer.PricePerPage = fields.get("priceperpage") or 0.0 … … 303 306 lastjob.ident = fields.get("id") 304 307 lastjob.JobId = fields.get("jobid") 305 lastjob.UserName = fields.get("username")308 lastjob.UserName = self.databaseToUserCharset(fields.get("username")) 306 309 lastjob.PrinterPageCounter = fields.get("pagecounter") 307 310 lastjob.JobSize = fields.get("jobsize") … … 331 334 if result : 332 335 for record in result : 333 user = StorageUser(self, record.get("username"))336 user = StorageUser(self, self.databaseToUserCharset(record.get("username"))) 334 337 user.ident = record.get("userid") 335 338 user.LimitBy = record.get("limitby") or "quota" … … 349 352 if result : 350 353 for record in result : 351 groups.append(self.getGroup( record.get("groupname")))354 groups.append(self.getGroup(self.databaseToUserCharset(record.get("groupname")))) 352 355 return groups 353 356 … … 359 362 for record in result : 360 363 if record["groupid"] != printer.ident : # in case of integrity violation 361 parentprinter = self.getPrinter( record.get("printername"))364 parentprinter = self.getPrinter(self.databaseToUserCharset(record.get("printername"))) 362 365 if parentprinter.Exists : 363 366 pgroups.append(parentprinter) … … 373 376 if result : 374 377 for record in result : 375 if self.tool.matchString(record["printername"], printerpattern.split(",")) : 376 printer = StoragePrinter(self, record["printername"]) 378 pname = self.databaseToUserCharset(record["printername"]) 379 if self.tool.matchString(pname, printerpattern.split(",")) : 380 printer = StoragePrinter(self, pname) 377 381 printer.ident = record.get("id") 378 382 printer.PricePerJob = record.get("priceperjob") or 0.0 … … 414 418 if result : 415 419 for record in result : 416 if self.tool.matchString(record.get("username"), names) : 417 user = StorageUser(self, record.get("username")) 420 uname = self.databaseToUserCharset(record.get("username")) 421 if self.tool.matchString(uname, names) : 422 user = StorageUser(self, uname) 418 423 user.ident = record.get("uid") 419 424 user.LimitBy = record.get("limitby") or "quota" … … 443 448 if result : 444 449 for record in result : 445 if self.tool.matchString(record.get("groupname"), names) : 446 group = self.getGroup(record.get("groupname")) 450 gname = self.databaseToUserCharset(record.get("groupname")) 451 if self.tool.matchString(gname, names) : 452 group = self.getGroup(gname) 447 453 grouppquota = self.getGroupPQuota(group, printer) 448 454 groupsandquotas.append((group, grouppquota)) … … 451 457 def addPrinter(self, printername) : 452 458 """Adds a printer to the quota storage, returns it.""" 453 self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote( printername))459 self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(self.userCharsetToDatabase(printername))) 454 460 return self.getPrinter(printername) 455 461 … … 461 467 def addUser(self, user) : 462 468 """Adds a user to the quota storage, returns it.""" 463 self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email), self.doQuote(user.OverCharge))) 469 self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % \ 470 (self.doQuote(self.userCharsetToDatabase(user.Name)), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email), self.doQuote(user.OverCharge))) 464 471 return self.getUser(user.Name) 465 472 466 473 def addGroup(self, group) : 467 474 """Adds a group to the quota storage, returns it.""" 468 self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % (self.doQuote(group.Name), self.doQuote(group.LimitBy or "quota"))) 475 self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % \ 476 (self.doQuote(self.userCharsetToDatabase(group.Name)), self.doQuote(group.LimitBy or "quota"))) 469 477 return self.getGroup(group.Name) 470 478 … … 559 567 def writeNewPayment(self, user, amount, comment="") : 560 568 """Adds a new payment to the payments history.""" 561 self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote( comment)))569 self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) 562 570 563 571 def writeLastJobSize(self, lastjob, jobsize, jobprice) : … … 657 665 job.PrecomputedJobSize = fields.get("precomputedjobsize") 658 666 job.PrecomputedJobPrice = fields.get("precomputedjobprice") 659 job.UserName = fields.get("username")660 job.PrinterName = fields.get("printername")667 job.UserName = self.databaseToUserCharset(fields.get("username")) 668 job.PrinterName = self.databaseToUserCharset(fields.get("printername")) 661 669 if job.JobTitle == job.JobFileName == job.JobOptions == "hidden" : 662 670 (job.JobTitle, job.JobFileName, job.JobOptions) = (_("Hidden because of privacy concerns"),) * 3