1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
6
|
|
|
* @package MW |
7
|
|
|
* @subpackage Common |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\MW\Criteria\Expression\Compare; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* PostgreSQL implementation for comparing objects |
16
|
|
|
* |
17
|
|
|
* @package MW |
18
|
|
|
* @subpackage Common |
19
|
|
|
*/ |
20
|
|
|
class PgSQL extends \Aimeos\MW\Criteria\Expression\Compare\SQL |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Escapes the value so it can be inserted into a SQL statement |
24
|
|
|
* |
25
|
|
|
* @param string $operator Operator used for the expression |
26
|
|
|
* @param integer $type Type constant |
27
|
|
|
* @param mixed $value Value that the variable or column should be compared to |
28
|
|
|
* @return double|string|integer Escaped value |
29
|
|
|
*/ |
30
|
|
|
protected function escape( $operator, $type, $value ) |
31
|
|
|
{ |
32
|
|
|
$value = $this->translateValue( $this->getName(), $value ); |
33
|
|
|
|
34
|
|
|
switch( $type ) |
35
|
|
|
{ |
36
|
|
|
case \Aimeos\MW\DB\Statement\Base::PARAM_NULL: |
37
|
|
|
$value = 'null'; break; |
38
|
|
|
case \Aimeos\MW\DB\Statement\Base::PARAM_BOOL: |
39
|
|
|
$value = ( $value ? "'t'" : "'f'" ); break; |
40
|
|
|
case \Aimeos\MW\DB\Statement\Base::PARAM_INT: |
41
|
|
|
$value = (int) $value; break; |
42
|
|
|
case \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT: |
43
|
|
|
$value = (double) $value; break; |
44
|
|
|
case \Aimeos\MW\DB\Statement\Base::PARAM_STR: |
45
|
|
|
if( $operator === '~=' ) { |
46
|
|
|
$value = '\'%' . str_replace( ['#', '%', '_', '['], ['##', '#%', '#_', '#['], $this->getConnection()->escape( $value ) ) . '%\''; break; |
47
|
|
|
} |
48
|
|
|
if( $operator === '=~' ) { |
|
|
|
|
49
|
|
|
$value = '\'' . str_replace( ['#', '%', '_', '['], ['##', '#%', '#_', '#['], $this->getConnection()->escape( $value ) ) . '%\''; break; |
50
|
|
|
} |
51
|
|
|
default: |
52
|
|
|
$value = '\'' . $this->getConnection()->escape( $value ) . '\''; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $value; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|