Changeset 2644
- Timestamp:
- 02/03/06 15:14:08 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/mysqlstorage.py
r2639 r2644 4 4 # PyKota : Print Quotas for CUPS and LPRng 5 5 # 6 # (c) 2003 -2004Jerome Alet <alet@librelogiciel.com>7 # (c) 2005 Matt Hyclak <hyclak@math.ohiou.edu>6 # (c) 2003, 2004, 2005, 2006 Jerome Alet <alet@librelogiciel.com> 7 # (c) 2005, 2006 Matt Hyclak <hyclak@math.ohiou.edu> 8 8 # This program is free software; you can redistribute it and/or modify 9 9 # it under the terms of the GNU General Public License as published by … … 42 42 port = int(port) 43 43 except ValueError : 44 port = -1 44 port = -1 # Use the default MySQL port 45 45 46 46 self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." % (host, port, dbname, user)) 47 47 self.database = MySQLdb.connect(host=host, port=port, db=dbname, user=user, passwd=passwd) 48 48 self.cursor = self.database.cursor() 49 49 self.closed = 0 50 50 self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user)) … … 53 53 """Closes the database connection.""" 54 54 if not self.closed : 55 55 self.cursor.close() 56 56 self.database.close() 57 57 self.closed = 1 … … 84 84 raise PyKotaStorageError, str(msg) 85 85 else : 86 86 # This returns a list of lists. Integers are returned as longs. 87 87 return self.cursor.fetchall() 88 88 … … 90 90 """Does a search query.""" 91 91 result = self.doRawSearch(query) 92 93 92 if result : 93 rows = [] 94 94 fields = {} 95 95 for i in range(len(self.cursor.description)) : 96 97 96 fields[i] = self.cursor.description[i][0] 97 for row in result : 98 98 rowdict = {} 99 99 for field in fields.keys() : 100 101 102 103 104 105 106 107 108 100 value = row[field] 101 try : 102 value = value.encode("UTF-8") 103 except: 104 pass 105 rowdict[fields[field]] = value 106 rows.append(rowdict) 107 # returns a list of dicts 108 return rows 109 109 110 110 def doModify(self, query) : … … 130 130 return (self.database.string_literal(field)).encode("UTF-8") 131 131 else : 132 132 self.tool.logdebug("WARNING: field has no type, returning NULL") 133 133 return "NULL" 134 134 … … 137 137 if result : 138 138 entries = [tuple([f[0] for f in self.cursor.description])] 139 139 for entry in result : 140 140 row = [] 141 141 for value in entry :