Fix a bug where "LIMIT ?" in queries was omitted in the generated query

The LIMIT clause was only honored when followed by a constant integer.  When
followed by a placeholder "?" it wasn't included in the generated database
query.

This could cause performance issues when selecting a few rows from a large
table like, for example, when paging through merged changes in Gerrit UI. In
this case, for every page, most of the closed changes would be selected from
the Changes table in order to display the next 26 changes. On one of our
productive Gerrit servers, running on the 2.7 release, it took often more than
20 seconds to show a next page. With this fix the time is reduced to several
milliseconds.

Change-Id: Ie18898242d9c590eeb4f3eae895d955cd04e1d66
4 files changed