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