Skip to content

Commit

Permalink
hot fix and sqlite compat
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeko committed Jun 25, 2014
1 parent df826e0 commit e3c70fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions Sum/DataTables/Engine/BaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ abstract class BaseEngine
private static $_remote = FALSE;
private static $_request = array();
protected $columns = array();
protected $limit = - 1;
protected $offset = 0;
protected $limit;
protected $offset;
protected $order = array();
protected $bound = array();
protected $search = array();
Expand All @@ -30,10 +30,10 @@ public static function setRequest($request)

protected function request($index, $default = NULL)
{
if (! is_array(self::$_request))
if (empty(self::$_request))
self::$_request = $_REQUEST;

if (! isset(self::$_request[$index]))
if (empty(self::$_request[$index]))
return $default;

return self::$_request[$index];
Expand Down Expand Up @@ -96,7 +96,7 @@ protected function handlePaging()
$this->output['draw'] = $this->request('draw', 0);

if (isset(self::$_request['start']) AND $this->request('length') != - 1) {
$this->offset = $this->request('start');
$this->offset = (string) $this->request('start');
$this->limit = $this->request('length');

return $this;
Expand Down
25 changes: 14 additions & 11 deletions Sum/DataTables/Engine/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Pdo extends BaseEngine
private $_having;
private $join = array();
private $_where;
private $_limited;
private $_query;
private $_requestQuery;

Expand Down Expand Up @@ -142,8 +143,8 @@ public function build()
if (! empty($this->search['column']))
$this->_requestQuery .= $glue . implode(' AND ', $this->search['column']);

empty($this->_groups) OR $this->_query .= " GROUP BY " . $this->_groups;
empty($this->_having) OR $this->_query .= " HAVING " . $this->_having;
empty($this->_groups) OR $this->_requestQuery .= " GROUP BY " . $this->_groups;
empty($this->_having) OR $this->_requestQuery .= " HAVING " . $this->_having;

if ($this->handleOrdering()) {
$this->_requestQuery .= " ORDER BY ";
Expand All @@ -152,7 +153,10 @@ public function build()
($dir !== end($this->order)) AND $this->_requestQuery .= ', ';
}
}
$this->handlePaging() AND $this->_requestQuery .= " LIMIT {$this->offset},{$this->limit}";
if($this->handlePaging()) {
$this->_limited = "LIMIT {$this->limit}";
$this->offset AND $this->_limited .= " OFFSET {$this->offset}";
}

return $this;
}
Expand All @@ -164,17 +168,16 @@ public function make($asArray = FALSE)
$this->_connection->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_NUM);

$data = $this->_connection->prepare(
"SELECT SQL_CALC_FOUND_ROWS {$this->_select} FROM {$this->_table} {$this->_requestQuery}"
"SELECT {$this->_select} FROM {$this->_table} {$this->_requestQuery} {$this->_limited}"
);

$resFilterLength = $this->_connection->prepare("SELECT FOUND_ROWS()");

$resTotalLength = $this->_connection->prepare("SELECT COUNT(1) FROM {$this->_table} {$this->_query}");
$resFilterLength = $this->_connection->prepare("SELECT count(*) FROM {$this->_table} {$this->_requestQuery}");
$resTotalLength = $this->_connection->prepare("SELECT COUNT(*) FROM {$this->_table} {$this->_query}");

$resFilterLength->execute();
$this->output['recordsFiltered'] = $resFilterLength->fetch()[0];
$resTotalLength->execute($this->bound);
$this->output['recordsTotal'] = $resTotalLength->fetch()[0];
$resFilterLength->execute($this->bound);
$this->output['recordsFiltered'] = $resFilterLength->fetchColumn();
$resTotalLength->execute();
$this->output['recordsTotal'] = $resTotalLength->fetchColumn();
$data->execute($this->bound);
$this->output['data'] = $data->fetchAll();
if ($asArray) {
Expand Down

0 comments on commit e3c70fc

Please sign in to comment.