Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%if and %lmt dosn't work together #87

Closed
hrach opened this issue Apr 25, 2013 · 6 comments
Closed

%if and %lmt dosn't work together #87

hrach opened this issue Apr 25, 2013 · 6 comments

Comments

@hrach
Copy link
Contributor

hrach commented Apr 25, 2013

$limit = 0;
$connection->query('
SELECT * FROM foo
%if ', FALSE, ' %lmt ', $limit, ' %end
');

produces

SELECT * FROM foo /* */ LIMIT 0

same with offset.

@JanTvrdik
Copy link
Contributor

Why don't you just set $limit to NULL?

@hrach
Copy link
Contributor Author

hrach commented Apr 25, 2013

You are poiting out some irrelevant things. It's about the fact, the %lmt cluase is appended at the end without taking care of %if.

@hrach
Copy link
Contributor Author

hrach commented Apr 25, 2013

$limit = 0;
$connection->query('
SELECT * FROM foo
%if ', FALSE, ' LIMIT %i ', $limit, ' %end
');

works ok

@JanTvrdik
Copy link
Contributor

I'm pointing out that you should not use %if with %lmt as there exists better solution.

Try to modify

} elseif ($mod === 'lmt') { // apply limit
:

if ($this->args[$cursor] !== NULL && !$this->comment) $this->limit = (int) $this->args[$cursor];

@hrach
Copy link
Contributor Author

hrach commented Apr 25, 2013

I'm pointing out that using %if don't have to include only %lmt expression, it could include more. I've solved by %i modifier, the top limits don't borther me.

@himdel
Copy link
Contributor

himdel commented Aug 26, 2014

I've just hit the same issue, apparently affects both %ofs and %lmt:

\dibi::query([ 'SELECT * FROM foo', '%if', false, '%lmt', 3, '%ofs', 5, '%end' ]);

yields

SELECT * FROM foo /* */ LIMIT 3 OFFSET 5

Obviously settings the limit or offset to null works just fine as a workaround, but, well, what's the point of %if if not not to have to special case these things outside of SQL.

IMHO something like ...'%if', $paging_enabled, '%lmt'... is much more readable than some adhoc setting stuff to null.

@dg dg closed this as completed in d6826d6 Jan 13, 2015
jasir added a commit to jasir/dibi that referenced this issue Mar 2, 2015
* master: (37 commits)
  Released version 2.3.1
  removed version.txt
  dibi: named connections are allowed [Closes dg#161]
  Dibi: Dump now recognize MsSql2012 offset as keyword
  DibiPdoDriver: added support for MsSql2012 Offset
  Tracy\Panel: added vector icon
  added contributing.md
  Released version 2.3.0
  Postgre: added test for matching by %like
  Postgre: fixed %like escaping [Closes dg#159]
  Dibi: $defaultDriver changed to mysqli [Closes dg#156]
  Released 2.3.0-RC1
  removed bridge for Nette 2.0 (BC break)
  dibi: named connections and activate() are deprecated (BC break)
  DibiFluent: add `leftJoin` and `on` to phpdoc.
  DibiFirePhpLogger: save some header operations for sites with hundreds of sql queries.
  DibiFirePhpLogger: Allow user defined size of json stream chunks [Closes dg#148]
  DibiTranslator: respect %if blocks for %lmt and %ofs as well [Closes dg#145][Closes dg#87]
  DibiResult: float detection locale fix [Closes dg#154]
  DibiMySqliDriver.php: fixes for HHVM
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants