38 public function __construct($parameters = array())
40 $this->dbConnection = Main\HttpApplication::getConnection();
41 $this->dbHelper = $this->dbConnection->getSqlHelper();
44 $entityName = trim((
string)($parameters[
'entityName'] ??
''));
45 $tableName = trim((
string)($parameters[
'tableName'] ??
''));
46 if ($entityName !==
'' && is_a($entityName, Main\ORM\Data\DataManager::class,
true))
51 $this->tableName = $table::getTableName();
52 $this->tableMap = $table::getMap();
55 if (!empty($parameters[
'exactFields']) && is_array($parameters[
'exactFields']))
57 foreach($parameters[
'exactFields'] as $fld)
59 if(!isset($this->tableMap[$fld]))
61 throw new Main\SystemException(
'Field does not exist in ORM class, but present in "exactFields" parameter: '.$fld, 0, __FILE__, __LINE__);
65 $this->fldVector[$fld] =
true;
70 foreach($this->tableMap as $fld => $params)
73 $this->fldVector[$fld] =
true;
79 $this->tableName = $this->dbHelper->forSql($parameters[
'tableName']);
81 if (!empty($parameters[
'exactFields']) && is_array($parameters[
'exactFields']))
83 $this->tableMap = $parameters[
'exactFields'];
102 foreach($this->tableMap as $fld => $params)
105 $this->fldVector[$fld] =
true;
111 $autoIncrementFld = trim((
string)($parameters[
'parameters'][
'autoIncrementFld'] ??
''));
112 if ($autoIncrementFld !==
'')
114 $this->autoIncFld = $autoIncrementFld;
115 if (!isset($this->fldVector[$this->autoIncFld]))
120 'data_type' =>
'integer',
127 $this->dbType = Main\HttpApplication::getConnection()->getType();
129 $this->mtu = (int)($parameters[
'parameters'][
'mtu'] ?? 0);
141 isset($parameters[
'parameters'][
'CALLBACKS'][
'ON_BEFORE_FLUSH'])
142 && is_callable($parameters[
'parameters'][
'CALLBACKS'][
'ON_BEFORE_FLUSH'])
145 $this->callbacks[
'ON_BEFORE_FLUSH'] = $parameters[
'parameters'][
'CALLBACKS'][
'ON_BEFORE_FLUSH'];
157 $fld = $this->dbHelper->forSql($fld);
161 $res = $this->dbConnection->query($sql)->fetch();
162 $this->index = intval($res[
'VAL']);
182 if($this->autoIncFld ===
false)
190 if($this->autoIncFld ===
false)
203 if(!is_array($row) || empty($row))
209 if($this->autoIncFld !==
false)
222 $nextBuffer = (empty($this->buffer) ? $this->insertHead : $this->buffer.Helper::getBatchInsertSeparator()).$sql;
225 if(defined(SITE_CHARSET) && SITE_CHARSET ==
'UTF-8')
226 $len = mb_strlen($nextBuffer);
228 $len = mb_strlen($nextBuffer);
230 if(($this->mtu - (mb_strlen($nextBuffer) + 100)) < self::RED_LINE)
233 $this->buffer = $this->insertHead.$sql;
236 $this->buffer = $nextBuffer;
243 if($this->buffer ==
'')
246 if(isset($this->callbacks[
'ON_BEFORE_FLUSH']))
247 call_user_func($this->callbacks[
'ON_BEFORE_FLUSH']);
249 $this->buffer .=
' '.$this->insertTail;
253 Main\HttpApplication::getConnection()->query($this->buffer);
259 $this->bufferSize = 0;