• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Bug in postgres DAO?

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I had a probem with JForum 2.1.4 in which it was impossible to view posts pending approval from a moderator because of the way the postgres dao was implemented. Postgres requires a "LIMIT X OFFSET Y" clause at the end of a query to get at most X rows starting at row number Y. This corresponds to the LIMIT clause in MySql, except that there, there is no OFFSET keyword, but something like it is inferred by a comma-seperated tuple, i.e., "LIMIT Y, X" is the equivilent (note the parameters meaning are in a different order). It follows that the postgres dao classes need to override methods which query for a subset, and flip the order of the start and count parameters (in addition to providing their own versions of the SELECT sql). Inexplicably, in 2.1.4, the postgres implementation of ModerationModel did this:

instead of this:

In 2.1.6, ModerationModel no longer constrains the query to a range, so this oddity is gone, however, in checking all the LIMIT OFFSET queries in 2.1.6, I found all were handled correctly except one in PostgresqlUserDAO, where this:

appears instead of this:

start > 0 ? start + count : 0 will work correctly if start == 0, but if it is anything else, the wrong range will be returned. For example, if start = 10 and count = 10, it will return rows 20 through 29 (if they exist), rather than rows 10 through 19.

Unless I totally misunderstand postgres sql, this is a bug.

Dave
[originally posted on jforum.net by Anonymous]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fixed, thanks for the tip

Rafael
[originally posted on jforum.net by Rafael Steil]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic