Index: pykota/trunk/pykota/storages/sql.py
===================================================================
--- pykota/trunk/pykota/storages/sql.py (revision 2653)
+++ pykota/trunk/pykota/storages/sql.py (revision 2654)
@@ -198,9 +198,10 @@
         """Extracts user information given its name."""
         user = StorageUser(self, username)
+        username = self.userCharsetToDatabase(username)
         result = self.doSearch("SELECT * FROM users WHERE username=%s LIMIT 1" % self.doQuote(username))
         if result :
             fields = result[0]
             user.ident = fields.get("id")
-            user.Name = fields.get("username", username)
+            user.Name = self.databaseToUserCharset(fields.get("username", username))
             user.LimitBy = fields.get("limitby") or "quota"
             user.AccountBalance = fields.get("balance")
@@ -214,9 +215,10 @@
         """Extracts group information given its name."""
         group = StorageGroup(self, groupname)
+        groupname = self.userCharsetToDatabase(groupname)
         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))
         if result :
             fields = result[0]
             group.ident = fields.get("id")
-            group.Name = fields.get("groupname", groupname)
+            group.Name = self.databaseToUserCharset(fields.get("groupname", groupname))
             group.LimitBy = fields.get("limitby") or "quota"
             group.AccountBalance = fields.get("balance")
@@ -228,9 +230,10 @@
         """Extracts printer information given its name."""
         printer = StoragePrinter(self, printername)
+        printername = self.userCharsetToDatabase(printername)
         result = self.doSearch("SELECT * FROM printers WHERE printername=%s LIMIT 1" % self.doQuote(printername))
         if result :
             fields = result[0]
             printer.ident = fields.get("id")
-            printer.Name = fields.get("printername", printername)
+            printer.Name = self.databaseToUserCharset(fields.get("printername", printername))
             printer.PricePerJob = fields.get("priceperjob") or 0.0
             printer.PricePerPage = fields.get("priceperpage") or 0.0
@@ -303,5 +306,5 @@
             lastjob.ident = fields.get("id")
             lastjob.JobId = fields.get("jobid")
-            lastjob.UserName = fields.get("username")
+            lastjob.UserName = self.databaseToUserCharset(fields.get("username"))
             lastjob.PrinterPageCounter = fields.get("pagecounter")
             lastjob.JobSize = fields.get("jobsize")
@@ -331,5 +334,5 @@
         if result :
             for record in result :
-                user = StorageUser(self, record.get("username"))
+                user = StorageUser(self, self.databaseToUserCharset(record.get("username")))
                 user.ident = record.get("userid")
                 user.LimitBy = record.get("limitby") or "quota"
@@ -349,5 +352,5 @@
         if result :
             for record in result :
-                groups.append(self.getGroup(record.get("groupname")))
+                groups.append(self.getGroup(self.databaseToUserCharset(record.get("groupname"))))
         return groups        
         
@@ -359,5 +362,5 @@
             for record in result :
                 if record["groupid"] != printer.ident : # in case of integrity violation
-                    parentprinter = self.getPrinter(record.get("printername"))
+                    parentprinter = self.getPrinter(self.databaseToUserCharset(record.get("printername")))
                     if parentprinter.Exists :
                         pgroups.append(parentprinter)
@@ -373,6 +376,7 @@
         if result :
             for record in result :
-                if self.tool.matchString(record["printername"], printerpattern.split(",")) :
-                    printer = StoragePrinter(self, record["printername"])
+                pname = self.databaseToUserCharset(record["printername"])
+                if self.tool.matchString(pname, printerpattern.split(",")) :
+                    printer = StoragePrinter(self, pname)
                     printer.ident = record.get("id")
                     printer.PricePerJob = record.get("priceperjob") or 0.0
@@ -414,6 +418,7 @@
         if result :
             for record in result :
-                if self.tool.matchString(record.get("username"), names) :
-                    user = StorageUser(self, record.get("username"))
+                uname = self.databaseToUserCharset(record.get("username"))
+                if self.tool.matchString(uname, names) :
+                    user = StorageUser(self, uname)
                     user.ident = record.get("uid")
                     user.LimitBy = record.get("limitby") or "quota"
@@ -443,6 +448,7 @@
         if result :
             for record in result :
-                if self.tool.matchString(record.get("groupname"), names) :
-                    group = self.getGroup(record.get("groupname"))
+                gname = self.databaseToUserCharset(record.get("groupname"))
+                if self.tool.matchString(gname, names) :
+                    group = self.getGroup(gname)
                     grouppquota = self.getGroupPQuota(group, printer)
                     groupsandquotas.append((group, grouppquota))
@@ -451,5 +457,5 @@
     def addPrinter(self, printername) :        
         """Adds a printer to the quota storage, returns it."""
-        self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(printername))
+        self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(self.userCharsetToDatabase(printername)))
         return self.getPrinter(printername)
         
@@ -461,10 +467,12 @@
     def addUser(self, user) :        
         """Adds a user to the quota storage, returns it."""
-        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)))
+        self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % \
+                                         (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)))
         return self.getUser(user.Name)
         
     def addGroup(self, group) :        
         """Adds a group to the quota storage, returns it."""
-        self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % (self.doQuote(group.Name), self.doQuote(group.LimitBy or "quota")))
+        self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % \
+                                          (self.doQuote(self.userCharsetToDatabase(group.Name)), self.doQuote(group.LimitBy or "quota")))
         return self.getGroup(group.Name)
 
@@ -559,5 +567,5 @@
     def writeNewPayment(self, user, amount, comment="") :
         """Adds a new payment to the payments history."""
-        self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(comment)))
+        self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment))))
         
     def writeLastJobSize(self, lastjob, jobsize, jobprice) :        
@@ -657,6 +665,6 @@
                 job.PrecomputedJobSize = fields.get("precomputedjobsize")
                 job.PrecomputedJobPrice = fields.get("precomputedjobprice")
-                job.UserName = fields.get("username")
-                job.PrinterName = fields.get("printername")
+                job.UserName = self.databaseToUserCharset(fields.get("username"))
+                job.PrinterName = self.databaseToUserCharset(fields.get("printername"))
                 if job.JobTitle == job.JobFileName == job.JobOptions == "hidden" :
                     (job.JobTitle, job.JobFileName, job.JobOptions) = (_("Hidden because of privacy concerns"),) * 3
