Skip to content

Commit

Permalink
Release version 1.9.6
Browse files Browse the repository at this point in the history
  • Loading branch information
FaaPz committed Feb 3, 2016
1 parent b1b4579 commit 8dc5d55
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Changelog

##### v1.9.6
+ Updated `LimitClause` class with:
- Fixed `limit()` method

##### v1.9.5
+ Updated documentation
+ Added protected override allowed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "slim/pdo",
"description": "PDO database library for Slim Framework",
"version": "1.9.5",
"version": "1.9.6",
"type": "library",
"keywords": ["pdo", "database", "slim", "framework"],
"homepage": "https://github.com/FaaPz/Slim-PDO",
Expand Down
2 changes: 1 addition & 1 deletion src/PDO/Clause/LimitClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function limit($number, $offset = null)
{
if (is_int($number)) {
if (is_int($offset) && $offset >= 0) {
$this->limit = intval($number).' , '.intval($offset);
$this->limit = intval($offset).' , '.intval($number);
} elseif ($number >= 0) {
$this->limit = intval($number);
}
Expand Down

3 comments on commit 8dc5d55

@bmutinda
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey..good to see this library being used by alot of developers. I have used it on several API's.

I have a concern with this commit. I will use an example to raise my issue.
Lets say I want to fetch 5 records from 0, two times. Assuming its a paginated app. How will I pass the limits in your new limit method??

To my understanding, the number is the starting point while the offset is how many records I want.

This was my idea - from my pull request

limit(0, 5); // first page
limit(5, 10); // second page 

but with your commit

limit(5, 0); 
limit(10, 5); 

Probably you can make it clear if I am confusing myself.
Thanks.

@FaaPz
Copy link
Owner Author

@FaaPz FaaPz commented on 8dc5d55 Feb 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but Slim-PDO is made as query builder for the SQL syntax. According to the MySQL documentation for example, offset (if given) comes first:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

So that's why I changed it. 😅

@nirleka
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FaaPz can the parameter also support string?
IMO, it is a PITA if i need to casting every time I call limit:

$stmt->limit( (int) $offset, (int) $top); 

Since I get the offset and limit from query param (used in pagination).
In my experience, other library is allow numeric string in limit parameters.
So, I need to read the source before I realized the parameter need to be integer.
I think using is_numeric in limit is more appropriate:

public function limit($number, $offset = null)
{
    if (is_numeric($number)) {
        if (is_numeric($offset) && $offset >= 0) {
            $this->limit = intval($offset).' , '.intval($number);
        } elseif ($number >= 0) {
            $this->limit = intval($number);
        }
    }
}

Please sign in to comment.