Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LimitExpression.php
Go to the documentation of this file.
1 <?php
7 
12 {
16  protected $sql;
17 
21  protected $count;
22 
26  protected $offset;
27 
33  public function __construct(
34  $sql,
35  $count,
36  $offset = 0
37  ) {
38  $this->sql = $sql;
39  $this->count = $count;
40  $this->offset = $offset;
41  }
42 
46  public function __toString()
47  {
48  $sql = $this->sql;
49  $count = intval($this->count);
50  if ($count <= 0) {
52  #require_once 'Zend/Db/Adapter/Exception.php';
53  throw new \Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
54  }
55 
56  $offset = intval($this->offset);
57  if ($offset < 0) {
59  #require_once 'Zend/Db/Adapter/Exception.php';
60  throw new \Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
61  }
62 
63  $sql .= " LIMIT $count";
64  if ($offset > 0) {
65  $sql .= " OFFSET $offset";
66  }
67  return trim($sql);
68  }
69 }