Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sqlexpression.php
1
<?php
9
namespace
Bitrix\Main\DB
;
10
11
use
Bitrix\Main\Application
;
12
18
class
SqlExpression
19
{
21
protected
$expression
;
22
24
protected
$args
= array();
25
26
protected
$pattern
=
'/([^\\\\]|^)(\?[#sifv]?)/'
;
27
28
protected
$i
;
29
31
protected
$connection
;
32
39
public
function
__construct
()
40
{
41
$args
= func_get_args();
42
43
if
(!isset(
$args
[0]))
44
{
45
throw
new \Bitrix\Main\ArgumentException(
'No pattern has been found for SqlExpression'
);
46
}
47
48
$this->expression =
$args
[0];
49
50
for
(
$i
= 1, $n = count(
$args
);
$i
< $n;
$i
++)
51
{
52
$this->args[] =
$args
[
$i
];
53
}
54
}
55
61
public
function
compile
()
62
{
63
$this->i = -1;
64
65
if
(strpos($this->expression,
'\\'
) ===
false
)
66
{
67
// regular case
68
return
preg_replace_callback($this->pattern, array($this,
'execPlaceholders'
), $this->expression);
69
}
70
else
71
{
72
// handle escaping \ and \\
73
$parts = explode('\\\\', $this->expression);
74
75
foreach
($parts as &$part)
76
{
77
if
(!empty($part))
78
{
79
$part = preg_replace_callback($this->pattern, array($this,
'execPlaceholders'
), $part);
80
}
81
}
82
83
$parts = str_replace(
'\\?'
,
'?'
, $parts);
84
85
return
implode(
'\\\\'
, $parts);
86
}
87
}
88
96
protected
function
execPlaceholders
($matches)
97
{
98
$sqlHelper = $this->
getConnection
()->getSqlHelper();
99
100
$this->i++;
101
102
$pre = $matches[1];
103
$ph = $matches[2];
104
105
if
(array_key_exists($this->i, $this->args))
106
{
107
$value = $this->args[
$this->i
];
108
109
if
($value ===
null
&& $ph !==
'?#'
)
110
{
111
$value =
'NULL'
;
112
}
113
elseif ($ph ==
'?'
|| $ph ==
'?s'
)
114
{
115
$value =
"'"
. $sqlHelper->forSql($value) .
"'"
;
116
}
117
elseif ($ph ==
'?#'
)
118
{
119
$value = $sqlHelper->quote($value);
120
}
121
elseif ($ph ==
'?v'
)
122
{
123
$value = $sqlHelper->values($value);
124
}
125
elseif ($ph ==
'?i'
)
126
{
127
$value = (int) $value;
128
}
129
elseif ($ph ==
'?f'
)
130
{
131
$value = (float) $value;
132
}
133
134
return
$pre . $value;
135
}
136
137
return
$matches[0];
138
}
139
140
public
function
__toString
()
141
{
142
return
$this->
compile
();
143
}
144
148
public
function
getConnection
()
149
{
150
if
($this->connection ===
null
)
151
{
152
$this->connection =
Application::getConnection
();
153
}
154
155
return
$this->connection
;
156
}
157
161
public
function
setConnection
(
$connection
)
162
{
163
$this->connection =
$connection
;
164
}
165
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\DB\SqlExpression
Definition
sqlexpression.php:19
Bitrix\Main\DB\SqlExpression\__construct
__construct()
Definition
sqlexpression.php:39
Bitrix\Main\DB\SqlExpression\$connection
$connection
Definition
sqlexpression.php:31
Bitrix\Main\DB\SqlExpression\compile
compile()
Definition
sqlexpression.php:61
Bitrix\Main\DB\SqlExpression\$expression
$expression
Definition
sqlexpression.php:21
Bitrix\Main\DB\SqlExpression\setConnection
setConnection($connection)
Definition
sqlexpression.php:161
Bitrix\Main\DB\SqlExpression\$args
$args
Definition
sqlexpression.php:24
Bitrix\Main\DB\SqlExpression\__toString
__toString()
Definition
sqlexpression.php:140
Bitrix\Main\DB\SqlExpression\$i
$i
Definition
sqlexpression.php:28
Bitrix\Main\DB\SqlExpression\execPlaceholders
execPlaceholders($matches)
Definition
sqlexpression.php:96
Bitrix\Main\DB\SqlExpression\getConnection
getConnection()
Definition
sqlexpression.php:148
Bitrix\Main\DB\SqlExpression\$pattern
$pattern
Definition
sqlexpression.php:26
Bitrix\Main\DB
Definition
arrayresult.php:2
modules
main
lib
db
sqlexpression.php
Создано системой
1.10.0