• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/db/mysqlisqlhelper.php
  • Класс: BitrixMainDBMysqliSqlHelper
  • Вызов: MysqliSqlHelper::prepareMergeMultiple
public function prepareMergeMultiple($tableName, array $primaryFields, array $insertRows)
{
	$result = [];
	$head = '';
	$maxBodySize = 1024*1024; //1 Mb
	$body = [];
	$bodySize = 0;
	foreach ($insertRows as $insertFields)
	{
		$insert = $this->prepareInsert($tableName, $insertFields);
		if (!$head && $insert && $insert[0])
		{
			$head = 'REPLACE INTO ' . $this->quote($tableName) . ' (' . $insert[0] . ') VALUES ';
		}
		if ($insert && $insert[1])
		{
			$values = '(' . $insert[1] . ')';
			$bodySize += mb_strlen($values) + 4;
			$body[] = $values;
			if ($bodySize > $maxBodySize)
			{
				$result[] = $head.implode(', ', $body);
				$body = [];
				$bodySize = 0;
			}
		}
	}
	if ($body)
	{
		$result[] = $head.implode(', ', $body);
	}

	return $result;
}