Changeset 1502 for pykota/trunk/pykota/storages/sql.py
- Timestamp:
- 05/26/04 16:50:12 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/sql.py
r1451 r1502 22 22 # 23 23 # $Log$ 24 # Revision 1.39 2004/05/26 14:50:12 jalet 25 # First try at saving the job-originating-hostname in the database 26 # 24 27 # Revision 1.38 2004/05/06 12:37:47 jalet 25 28 # pkpgcounter : comments … … 143 146 """Extracts a printer's last job information.""" 144 147 lastjob = StorageLastJob(self, printer) 145 result = self.doSearch("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize, jobprice, filename, title, copies, options, jobdate FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printer.ident))148 result = self.doSearch("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize, jobprice, filename, title, copies, options, hostname, jobdate FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printer.ident)) 146 149 if result : 147 150 fields = result[0] … … 158 161 lastjob.JobOptions = fields.get("options") 159 162 lastjob.JobDate = fields.get("jobdate") 163 lastjob.JobHostName = fields.get("hostname") 160 164 lastjob.Exists = 1 161 165 return lastjob … … 335 339 self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 336 340 337 def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None ) :341 def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) : 338 342 """Adds a job in a printer's history.""" 339 343 if (not self.disablehistory) or (not printer.LastJob.Exists) : 340 344 if jobsize is not None : 341 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options)))345 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, hostname) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost))) 342 346 else : 343 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options)))347 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options, hostname) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost))) 344 348 else : 345 349 # here we explicitly want to reset jobsize to NULL if needed 346 self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(printer.LastJob.ident)))350 self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, hostname=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(printer.LastJob.ident))) 347 351 348 352 def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : … … 368 372 self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 369 373 370 def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :374 def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, limit=100) : 371 375 """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 372 376 query = "SELECT jobhistory.*,username,printername FROM jobhistory,users,printers WHERE users.id=userid AND printers.id=printerid" … … 376 380 if (printer is not None) and printer.Exists : 377 381 where.append("printerid=%s" % self.doQuote(printer.ident)) 382 if hostname is not None : 383 where.append("hostname=%s" % self.doQuote(hostname)) 378 384 if datelimit is not None : 379 385 where.append("jobdate<=%s" % self.doQuote(datelimit)) … … 399 405 job.JobOptions = fields.get("options") 400 406 job.JobDate = fields.get("jobdate") 407 job.JobHostName = fields.get("hostname") 401 408 job.UserName = fields.get("username") 402 409 job.PrinterName = fields.get("printername")