| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TPgsqlCommandBuilder 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 |
* TPgsqlCommandBuilder provides specifics methods to create limit/offset query commands
|
|
|
17 |
* for Pgsql 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 TPgsqlCommandBuilder extends TDbCommandBuilder
|
|
|
25 |
{
|
|
|
26 |
/**
|
|
|
27 |
* Overrides parent implementation. Only column of type text or character (and its variants)
|
|
|
28 |
* accepts the LIKE criteria.
|
|
|
29 |
* @param array list of column id for potential search condition.
|
|
|
30 |
* @param string string of keywords
|
|
|
31 |
* @return string SQL search condition matching on a set of columns.
|
|
|
32 |
*/
|
|
|
33 |
public function getSearchExpression($fields, $keywords)
|
|
|
34 |
{
|
|
|
35 |
$columns = array();
|
|
|
36 |
foreach($fields as $field)
|
|
|
37 |
{
|
|
|
38 |
if($this->isSearchableColumn($this->getTableInfo()->getColumn($field)))
|
|
|
39 |
$columns[] = $field;
|
|
|
40 |
}
|
|
|
41 |
return parent::getSearchExpression($columns, $keywords);
|
|
|
42 |
}
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @return boolean true if column can be used for LIKE searching.
|
|
|
46 |
*/
|
|
|
47 |
protected function isSearchableColumn($column)
|
|
|
48 |
{
|
|
|
49 |
$type = strtolower($column->getDbType());
|
|
|
50 |
return $type === 'character varying' || $type === 'varchar' ||
|
|
|
51 |
$type === 'character' || $type === 'char' || $type === 'text';
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Overrides parent implementation to use PostgreSQL's ILIKE instead of LIKE (case-sensitive).
|
|
|
56 |
* @param string column name.
|
|
|
57 |
* @param array keywords
|
|
|
58 |
* @return string search condition for all words in one column.
|
|
|
59 |
*/
|
|
|
60 |
protected function getSearchCondition($column, $words)
|
|
|
61 |
{
|
|
|
62 |
$conditions=array();
|
|
|
63 |
foreach($words as $word)
|
|
|
64 |
$conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%');
|
|
|
65 |
return '('.implode(' AND ', $conditions).')';
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
}
|
|
|
69 |
|