1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
commonhelper.php
См. документацию.
1<?php
13
14namespace Bitrix\Sale\Location\DB;
15
16use Bitrix\Main;
17
18abstract class CommonHelper
19{
20 public static function getSqlForDataType($type, $len = 0)
21 {
22 if($type == 'int')
23 return 'int';
24
25 if($type == 'varchar')
26 return 'varchar('.(intval($len) ? intval($len) : '1').')';
27
28 if($type == 'char')
29 return 'char('.(intval($len) ? intval($len) : '1').')';
30
31 return '';
32 }
33
34 public static function getBatchInsertHead($tableName, $fields = array())
35 {
36 $map = array();
37
39 $dbHelper = $dbConnection->getSqlHelper();
40
41 if(is_array($fields))
42 {
43 foreach($fields as $fld)
44 $map[] = $dbHelper->forSql($fld);
45 }
46
47 return 'INSERT ' . ($dbConnection->getType() === 'pgsql' ? '' : 'IGNORE ') . 'INTO '.$dbHelper->forSql($tableName).' ('.implode(',', $map).') values ';
48 }
49
50 public static function getBatchInsertTail()
51 {
53
54 return $dbConnection->getType() === 'pgsql' ? ' ON CONFLICT DO NOTHING' : '';
55 }
56
57 public static function getBatchInsertSeparator()
58 {
59 return ', ';
60 }
61
62 public static function getBatchInsertValues($row, $tableName, $fields, $map)
63 {
64 return static::prepareSql($row, $fields, $map);
65 }
66
67 public static function getMaxTransferUnit()
68 {
69 return PHP_INT_MAX;
70 }
71
72 protected static function prepareSql($row, $fields, $map)
73 {
74 if (!is_array($row) || empty($row) || !is_array($fields) || empty($fields) || !is_array($map) || empty($map))
75 {
76 return '';
77 }
78
80 $sqlHelper = $connection->getSqlHelper();
81 unset($connection);
82
83 $sql = [];
84 foreach ($fields as $fld => $none)
85 {
86 $val = $row[$fld];
87
88 // only numeric and literal fields supported at the moment
89 if (
90 isset($map[$fld]['data_type'])
91 && $map[$fld]['data_type'] == 'integer'
92 )
93 {
94 $sql[] = (int)$val;
95 }
96 else
97 {
98 $sql[] = "'" . $sqlHelper->forSql($val) . "'";
99 }
100 }
101
102 return '(' . implode(',', $sql) . ')';
103 }
104
105 // makes sense only for mssql
106 public static function dropAutoIncrementRestrictions($tableName)
107 {
108 return false;
109 }
110
111 // same
112 public static function restoreAutoIncrementRestrictions($tableName)
113 {
114 return false;
115 }
116
117 // makes sense only for oracle
118 public static function incrementSequenceForTable($tableName)
119 {
120 return false;
121 }
122
123 // makes sense only for oracle
124 protected static function checkSequenceExistsForTable($tableName)
125 {
126 return false;
127 }
128
129 /*
130 public static function addPrimaryKey($tableName, $columns = array())
131 {
132 if(!strlen($tableName) || !is_array($columns) || empty($columns))
133 return false;
134
135 $dbConnection = Main\HttpApplication::getConnection();
136 $dbHelper = $dbConnection->getSqlHelper();
137
138 $tableName = $dbHelper->forSql($tableName);
139 $columns = static::escapeArray($columns);
140
141 $dbConnection->query("ALTER TABLE ".$tableName." ADD CONSTRAINT PK_".ToUpper($tableName)." PRIMARY KEY (".implode(', ', $columns).")");
142
143 return true;
144 }
145 */
146
147 // do nothing but for oracle
148 public static function addAutoIncrement()
149 {
150 return false;
151 }
152
153 public static function createIndex($tableName, $ixNamePostfix, $columns = array(), $unique = false)
154 {
155 if(!mb_strlen($tableName) || !mb_strlen($ixNamePostfix) || !is_array($columns) || empty($columns))
156 return false;
157
158 $dbConnection = Main\HttpApplication::getConnection();
159 $dbHelper = $dbConnection->getSqlHelper();
160
161 $tableName = $dbHelper->forSql($tableName);
162 $ixNamePostfix = $dbHelper->forSql($ixNamePostfix);
163 $columns = static::escapeArray($columns);
164
165 $ixName = static::getIndexName($tableName, $ixNamePostfix, $columns);
166
167 if(mb_strlen($ixName) > 30)
168 return false;
169
170 if(!static::checkIndexNameExists($ixName, $tableName))
171 {
172 $dbConnection->query("CREATE ".($unique ? "UNIQUE" : "")." INDEX ".$ixName." ON ".$tableName." (".implode(', ', $columns).")");
173 return true;
174 }
175
176 return false;
177 }
178
179 protected static function getIndexName($tableName, $ixNamePostfix, $columns = array())
180 {
181 return 'IX_'.preg_replace('#^B_#', '', mb_strtoupper($tableName))."_".mb_strtoupper($ixNamePostfix);
182 }
183
184 protected static function escapeArray($columns)
185 {
186 foreach($columns as &$col)
187 $col = Main\HttpApplication::getConnection()->getSqlHelper()->forSql($col);
188
189 return $columns;
190 }
191
192 public static function dropTable($tableName)
193 {
194 $dbConnection = Main\HttpApplication::getConnection();
195
196 $tableName = $dbConnection->getSqlHelper()->forSql($tableName);
197
198 if($dbConnection->isTableExists($tableName))
199 Main\HttpApplication::getConnection()->query('drop table '.$tableName);
200 }
201
202 public static function checkTableExists($tableName)
203 {
204 return Main\HttpApplication::getConnection()->isTableExists($tableName);
205 }
206
207 public static function truncateTable($tableName)
208 {
209 $dbConnection = Main\HttpApplication::getConnection();
210
211 $tableName = $dbConnection->getSqlHelper()->forSql($tableName);
212
213 if($dbConnection->isTableExists($tableName))
214 Main\HttpApplication::getConnection()->query('truncate table '.$tableName);
215 }
216
217 public static function getQuerySeparatorSql()
218 {
219 }
220
222 {
223 return true;
224 }
225}
$connection
Определения actionsdefinitions.php:38
$type
Определения options.php:106
static getConnection($name="")
Определения application.php:638
static prepareSql($row, $fields, $map)
Определения commonhelper.php:72
static getSqlForDataType($type, $len=0)
Определения commonhelper.php:20
static escapeArray($columns)
Определения commonhelper.php:184
static getBatchInsertHead($tableName, $fields=array())
Определения commonhelper.php:34
static needSelectFieldsInOrderByWhenDistinct()
Определения commonhelper.php:221
static incrementSequenceForTable($tableName)
Определения commonhelper.php:118
static checkSequenceExistsForTable($tableName)
Определения commonhelper.php:124
static getBatchInsertValues($row, $tableName, $fields, $map)
Определения commonhelper.php:62
static restoreAutoIncrementRestrictions($tableName)
Определения commonhelper.php:112
static createIndex($tableName, $ixNamePostfix, $columns=array(), $unique=false)
Определения commonhelper.php:153
static getMaxTransferUnit()
Определения commonhelper.php:67
static dropTable($tableName)
Определения commonhelper.php:192
static truncateTable($tableName)
Определения commonhelper.php:207
static getBatchInsertTail()
Определения commonhelper.php:50
static getQuerySeparatorSql()
Определения commonhelper.php:217
static dropAutoIncrementRestrictions($tableName)
Определения commonhelper.php:106
static getBatchInsertSeparator()
Определения commonhelper.php:57
static checkTableExists($tableName)
Определения commonhelper.php:202
static getIndexName($tableName, $ixNamePostfix, $columns=array())
Определения commonhelper.php:179
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$map
Определения config.php:5
$val
Определения options.php:1793
$fields
Определения yandex_run.php:501