564 | | """Adds a user to the quota storage, returns it.""" |
565 | | self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge, description) VALUES (%s, %s, %s, %s, %s, %s, %s)" % \ |
| 564 | """Adds a user to the quota storage, returns the old value if it already exists.""" |
| 565 | try : |
| 566 | self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge, description) VALUES (%s, %s, %s, %s, %s, %s, %s)" % \ |
573 | | return self.getUser(user.Name) |
| 574 | except PyKotaStorageError : |
| 575 | # TODO : check if this is an error different from a duplicate insert |
| 576 | # return the existing entry which has to be modified |
| 577 | return self.getUser(user.Name) |
| 578 | else : |
| 579 | if user.PaymentsBacklog : |
| 580 | for (value, comment) in user.PaymentsBacklog : |
| 581 | self.writeNewPayment(user, value, comment) |
| 582 | user.PaymentsBacklog = [] |
| 583 | user.isDirty = False |
| 584 | return None # the entry created doesn't need further modification |
576 | | """Adds a group to the quota storage, returns it.""" |
577 | | self.doModify("INSERT INTO groups (groupname, limitby, description) VALUES (%s, %s, %s)" % \ |
578 | | (self.doQuote(self.userCharsetToDatabase(group.Name)), \ |
579 | | self.doQuote(group.LimitBy or "quota"), \ |
580 | | self.doQuote(self.userCharsetToDatabase(group.Description)))) |
581 | | return self.getGroup(group.Name) |
| 587 | """Adds a group to the quota storage, returns the old value if it already exists.""" |
| 588 | try : |
| 589 | self.doModify("INSERT INTO groups (groupname, limitby, description) VALUES (%s, %s, %s)" % \ |
| 590 | (self.doQuote(self.userCharsetToDatabase(group.Name)), \ |
| 591 | self.doQuote(group.LimitBy or "quota"), \ |
| 592 | self.doQuote(self.userCharsetToDatabase(group.Description)))) |
| 593 | except PyKotaStorageError : |
| 594 | # TODO : check if this is an error different from a duplicate insert |
| 595 | # return the existing entry which has to be modified |
| 596 | return self.getGroup(group.Name) |
| 597 | else : |
| 598 | group.isDirty = False |
| 599 | return None # the entry created doesn't need further modification |
695 | | self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) |
| 713 | if user.ident is not None : |
| 714 | self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) |
| 715 | else : |
| 716 | self.doModify("INSERT INTO payments (userid, amount, description) VALUES ((SELECT id FROM users WHERE username=%s), %s, %s)" % (self.doQuote(self.userCharsetToDatabase(user.Name)), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) |