Edgewall Software

Ticket #5049 (closed enhancement: fixed)

Opened 20 months ago

Last modified 20 months ago

[PATCH] TicketQuery Limit Query Results

Reported by: Karmadude <karmadude@…> Owned by: cboos
Priority: normal Milestone: 0.11
Component: ticket system Version:
Severity: minor Keywords: tracquery limit
Cc:

Description

Added functionality to limit number of records in query via the query string

Example

[[TicketQuery(version=1.0|2.0&resolution=duplicate&limit=5)]]

Attachments

ticketquery_limit.patch (1.4 KB) - added by karmadude@… 20 months ago.
TracQuery Limit Patch
ticketquery_limit2.patch (1.9 KB) - added by karmadude@… 20 months ago.

Change History

Changed 20 months ago by karmadude@…

TracQuery Limit Patch

Changed 20 months ago by cboos

  • owner changed from jonas to cboos
  • severity changed from normal to minor
  • milestone set to 0.11

Nice little patch ;-) However, the self.limit should be appended to the args list, in order to protect against SQL injections issues.

Changed 20 months ago by karmadude@…

I have added an updated patch, I changed the code to match closely to how order argument is handled. Also I had to update the query call in process_request function to use the limit arg.

cobos, I am not very familiar with the Trac code, this was my first stab at a solution, and I just followed how the order arg was being handled. As for SQL injections, we have a internal deployment of Trac, and so I did not give that much thought. If you have some suggestions as to how to improve the code, I can take a stab at improving the patch.

Changed 20 months ago by cboos

Usually what we do is simply to dissociate the SQL statement from the arguments:

if self.limit:
    sql.append("\nLIMIT %s")
    args.append(self.limit)

and later call cursor.execute(sql, args), which takes care of using the args as arguments; otherwise you could pass arbitrary SQL in the limit query parameter.

Changed 20 months ago by karmadude@…

Changed 20 months ago by karmadude@…

cboos, thanks for explaining that to me, it all makes sense now. I have updated the patch.

Changed 20 months ago by cboos

  • status changed from new to closed
  • resolution set to fixed

Implemented in [5149:5150]. Thanks for the patch!

Add/Change #5049 ([PATCH] TicketQuery Limit Query Results)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from cboos. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.