Skip to content

Commit

Permalink
Rewrite for Mssql adapter; Oracle adapter added;
Browse files Browse the repository at this point in the history
Fixed empty ORDER BY; Massive comments review

Html rendering replaced with 'classic' version.
If you want previous 'document.write' version - change '$this->render_html' to 'js'.
  • Loading branch information
WR committed Jan 1, 2012
1 parent ee93be0 commit 4ab80f0
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 97 deletions.
36 changes: 19 additions & 17 deletions php/Adapter/Mssql.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
<?php
/**
* Mssql adapter for jqGrid
* Mssql adapter for jqGridPHP
*/

abstract class jqGrid_Adapter_Mssql extends jqGrid
{
protected $do_sort = false;
protected $do_limit = false;

protected $where_empty = '1=1';

protected function buildFields($cols)
{
return parent::buildFields($cols) . ', ROW_NUMBER() OVER (' . $this->buildOrderBy($this->sidx, $this->sord) . ') AS _row_number';
}

protected function buildOrderBy($sidx, $sord)
{
if(!$sidx) $sidx = $this->primary_key;
$fields = parent::buildFields($cols);
if($this->limit > -1)
{
$fields .= ', ROW_NUMBER() OVER (' . $this->buildOrderBy($this->sidx, $this->sord) . ') AS _rownum';
}

return parent::buildOrderBy($sidx, $sord);
return $fields;
}

protected function buildQueryRows($q)
{
$query = parent::buildQueryRows($q);

$offset_min = max($this->page * $this->limit - $this->limit, 0) + 1;
$offset_max = $offset_min + $this->limit;

$query = "
SELECT *
FROM ($query) a
WHERE _row_number BETWEEN $offset_min AND $offset_max
";
if($this->limit > -1)
{
$offset_min = max($this->page * $this->limit - $this->limit, 0) + 1;
$offset_max = $offset_min + $this->limit;

$query = "
SELECT *
FROM ($query) a
WHERE _rownum BETWEEN $offset_min AND $offset_max
";
}

return $query;
}
Expand Down
41 changes: 41 additions & 0 deletions php/Adapter/Oracle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Oracle adapter for jqGridPHP
*/

abstract class jqGrid_Adapter_Oracle extends jqGrid
{
protected $do_limit = false;
protected $where_empty = '1=1';

protected function buildFields($cols)
{
$fields = parent::buildFields($cols);

if($this->limit > -1)
{
$fields .= ', rownum AS _rownum';
}

return $fields;
}

protected function buildQueryRows($q)
{
$query = parent::buildQueryRows($q);

if($this->limit > -1)
{
$offset_min = max($this->page * $this->limit - $this->limit, 0) + 1;
$offset_max = $offset_min + $this->limit;

$query = "
SELECT *
FROM ($query) a
WHERE _rownum BETWEEN $offset_min AND $offset_max
";
}

return $query;
}
}
Loading

0 comments on commit 4ab80f0

Please sign in to comment.