hasLimit = false;
$this->limit = 0;
$this->offset = 0;
parent::reset();
}
/**
* Returns SQL to create an alias
*
* This method can be used to create an alias for either a
* table or a column.
* Example:
*
* // this will make the table users have the alias employees
* // and the column user_id the alias employee_id
* $q->select( $q->aliAs( 'user_id', 'employee_id' )
* ->from( $q->aliAs( 'users', 'employees' ) );
*
*
* @returns string the query string "columnname as targetname
*/
public function aliAs( $name, $alias )
{
return "{$name} {$alias}";
}
/**
* Returns SQL that limits the result set.
*
* $limit controls the maximum number of rows that will be returned.
* $offset controls which row that will be the first in the result
* set from the total amount of matching rows.
*
* Example:
*
* $q->select( '*' )->from( 'table' )
* ->limit( 10, 0 );
*
*
* Oracle does not support the LIMIT keyword. A complete rewrite of the
* query is neccessary. Queries will be rewritten like this:
*
* Original query in MySQL syntax:
* SELECT * FROM table LIMIT 10, 5
* The corresponding Oracle query:
* SELECT * FROM (SELECT a.*, ROWNUM rn FROM (SELECT * FROM table) a WHERE rownum <= 15) WHERE rn >= 6;
*
* Even though the Oracle query is three times as long it performs about the same
* as mysql on small result sets and a bit better on large result sets.
*
* Note that you will not get a result if you call buildLimit() when using the oracle database.
*
* @param $limit integer expression
* @param $offset integer expression
* @returns string logical expression
*/
public function limit( $limit, $offset = 0 )
{
$this->hasLimit = true;
$this->limit = $limit;
$this->offset = $offset;
}
/**
* Returns a series of strings concatinated
*
* concat() accepts an arbitrary number of parameters. Each parameter
* must contain an expression or an array with expressions.
*
* @param string|array(string) strings that will be concatinated.
*/
public function concat()
{
$args = func_get_args();
$cols = self::arrayFlatten( $args );
if ( count( $cols ) < 1 )
{
throw new ezcDbAbstractionException( ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
}
return join( ' || ' , $cols );
}
/**
* Returns dummy table name 'dual'.
*
* @returns string
*/
static public function getDummyTableName()
{
return 'dual';
}
public function build()
{
$query = parent::build();
if( $this->hasLimit )
{
$min = $this->offset + 1;
$max = $this->offset + $this->limit;
$query = "SELECT * FROM( SELECT a.*, ROWNUM rn FROM( {$query} ) a WHERE rownum <= {$max} ) WHERE rn >= {$min}";
}
return $query;
}
// not possible
public function buildLimit()
{
throw new exception();
}
}
?>