Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2008, 11:19 AM
Junior Member
 
Join Date: May 2008
Posts: 5
Question A simple question on Sql LIMIT clause.

Here:
Zend Framework: Documentation .db.select.building.limit

And here:
Paging Data Sets With PEAR Pager EAR-Pager

It seems the two articles use different LIMIT clause syntax.
The manual is: LIMIT <limit>, [<skip>]
But the tutorial on Pager is:
LIMIT [<skip>,]<limit>

I am wondering, which is the correct one? or we can use both?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-23-2008, 12:58 AM
Junior Member
 
Join Date: May 2008
Posts: 10
Default

This is how MySQL (since 3.23, I believe), will allow you to do LIMIT clauses (:

Code:
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
That is, how you do it in a raw SQL query.
The cause of your confusion comes from the fact you are using Zend_Db_Select`s limit() method, which takes it`s arguments as ->limit($count, $offset).

So, technically both are correct. The latter being correct for ACTUAL SQL, and the former correct for Db_Select objects.

However, I HIGHLY recommend, if you are using Zend_Db_Select objects to build your queries, using the built in limitPage() method.

Its use is simple:
limitPage($pageNumber, $pageLength)

This saves you having to calculate your offset beforehand.

Last edited by jasonw : 05-23-2008 at 01:01 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-23-2008, 03:08 AM
Junior Member
 
Join Date: May 2008
Posts: 5
Default

Quote:
Originally Posted by jasonw View Post
This is how MySQL (since 3.23, I believe), will allow you to do LIMIT clauses (:

Code:
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
That is, how you do it in a raw SQL query.
The cause of your confusion comes from the fact you are using Zend_Db_Select`s limit() method, which takes it`s arguments as ->limit($count, $offset).

So, technically both are correct. The latter being correct for ACTUAL SQL, and the former correct for Db_Select objects.

However, I HIGHLY recommend, if you are using Zend_Db_Select objects to build your queries, using the built in limitPage() method.

Its use is simple:
limitPage($pageNumber, $pageLength)

This saves you having to calculate your offset beforehand.
Thanks very much. I just thought in the Manual on Zend_Db_Select's limit() method, the example's comment code seem say it is uses [LIMIT {row_count, [offset] | row_count OFFSET offset}]. I knew the format: LIMIT row_count OFFSET offset will always right in ACTUAL SQL.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:43 AM.