1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sqlexpression.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\DB;
10
11use Bitrix\Main\Application;
12use Bitrix\Main\Type\Date;
13use Bitrix\Main\Type\DateTime;
14
21{
23 protected $expression;
24
26 protected $args = array();
27
28 protected $pattern = '/([^\\\\]|^)(\?[#sifv]?)/';
29
30 protected $i;
31
33 protected $connection;
34
41 public function __construct()
42 {
43 $args = func_get_args();
44
45 if (!isset($args[0]))
46 {
47 throw new \Bitrix\Main\ArgumentException('No pattern has been found for SqlExpression');
48 }
49
50 $this->expression = $args[0];
51
52 for ($i = 1, $n = count($args); $i < $n; $i++)
53 {
54 $this->args[] = $args[$i];
55 }
56 }
57
63 public function compile()
64 {
65 $this->i = -1;
66
67 if (!str_contains($this->expression, '\\'))
68 {
69 // regular case
70 return preg_replace_callback($this->pattern, array($this, 'execPlaceholders'), $this->expression);
71 }
72 else
73 {
74 // handle escaping \ and \\
75 $parts = explode('\\\\', $this->expression);
76
77 foreach ($parts as &$part)
78 {
79 if (!empty($part))
80 {
81 $part = preg_replace_callback($this->pattern, array($this, 'execPlaceholders'), $part);
82 }
83 }
84
85 $parts = str_replace('\\?', '?', $parts);
86
87 return implode('\\\\', $parts);
88 }
89 }
90
98 protected function execPlaceholders($matches)
99 {
100 $sqlHelper = $this->getConnection()->getSqlHelper();
101
102 $this->i++;
103
104 $pre = $matches[1];
105 $ph = $matches[2];
106
107 if (array_key_exists($this->i, $this->args))
108 {
109 $value = $this->args[$this->i];
110
111 if ($value === null && $ph !== '?#')
112 {
113 $value = 'NULL';
114 }
115 elseif ($ph == '?')
116 {
117 if ($value instanceof DateTime)
118 {
119 $value = $sqlHelper->convertToDbDateTime($value);
120 }
121 elseif ($value instanceof Date)
122 {
123 $value = $sqlHelper->convertToDbDate($value);
124 }
125 else
126 {
127 $value = "'" . $sqlHelper->forSql($value) . "'";
128 }
129 }
130 elseif ($ph == '?s')
131 {
132 $value = "'" . $sqlHelper->forSql($value) . "'";
133 }
134 elseif ($ph == '?#')
135 {
136 $value = $sqlHelper->quote($value);
137 }
138 elseif ($ph == '?v')
139 {
140 $value = $sqlHelper->values($value);
141 }
142 elseif ($ph == '?i')
143 {
144 $value = (int) $value;
145 }
146 elseif ($ph == '?f')
147 {
148 $value = (float) $value;
149 }
150
151 return $pre . $value;
152 }
153
154 return $matches[0];
155 }
156
157 public function __toString()
158 {
159 return $this->compile();
160 }
161
165 public function getConnection()
166 {
167 if ($this->connection === null)
168 {
169 $this->connection = Application::getConnection();
170 }
171
172 return $this->connection;
173 }
174
178 public function setConnection($connection)
179 {
180 $this->connection = $connection;
181 }
182}
static getConnection($name="")
Определения application.php:638
setConnection($connection)
Определения sqlexpression.php:178
execPlaceholders($matches)
Определения sqlexpression.php:98
Определения date.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$matches
Определения index.php:22
$n
Определения update_log.php:107