blob: 8b84020703127050a4712c13103112a5df1c1139 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<?php
/**
* TSqliteCommandBuilder class file.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2014 PradoSoft
* @license http://www.pradosoft.com/license/
* @package Prado\Data\Common\Sqlite
*/
namespace Prado\Data\Common\Sqlite;
use Prado\Data\Common\TDbCommandBuilder;
use Prado\Prado;
Prado::using('System.Data.Common.TDbCommandBuilder');
/**
* TSqliteCommandBuilder provides specifics methods to create limit/offset query commands
* for Sqlite database.
*
* @author Wei Zhuo <weizho[at]gmail[dot]com>
* @package Prado\Data\Common\Sqlite
* @since 3.1
*/
class TSqliteCommandBuilder extends TDbCommandBuilder
{
/**
* Alters the sql to apply $limit and $offset.
* @param string SQL query string.
* @param integer maximum number of rows, -1 to ignore limit.
* @param integer row offset, -1 to ignore offset.
* @return string SQL with limit and offset.
*/
public function applyLimitOffset($sql, $limit=-1, $offset=-1)
{
$limit = $limit!==null ? intval($limit) : -1;
$offset = $offset!==null ? intval($offset) : -1;
if($limit > 0 || $offset > 0)
{
$limitStr = ' LIMIT '.$limit;
$offsetStr = $offset >= 0 ? ' OFFSET '.$offset : '';
return $sql.$limitStr.$offsetStr;
}
else
return $sql;
}
}
|