209 foreach ($tableFields as $columnName => $tableField)
211 if (isset($fields[$columnName]) && !($fields[$columnName] instanceof
SqlExpression))
213 if ($tableField instanceof ORM\Fields\
TextField && $fields[$columnName] <>
'')
215 $binds[$columnName] = $fields[$columnName];
331 elseif ($field instanceof ORM\Fields\
FloatField)
333 $scale = $field->getScale();
334 return 'number'.($scale !==
null?
"(*,".$scale.
")":
"");
340 elseif ($field instanceof ORM\Fields\
DateField)
344 elseif ($field instanceof ORM\Fields\
TextField)
350 $values = $field->getValues();
352 if (preg_match(
'/^[0-9]+$/', $values[0]) && preg_match(
'/^[0-9]+$/', $values[1]))
358 return 'varchar2('.max(mb_strlen($values[0]), mb_strlen($values[1])).
' char)';
361 elseif ($field instanceof ORM\Fields\
EnumField)
363 return 'varchar2('.max(array_map(
'strlen', $field->getValues())).
' char)';
368 $defaultLength =
false;
371 if ($validator instanceof ORM\Fields\Validators\LengthValidator)
373 if ($defaultLength ===
false || $defaultLength > $validator->getMax())
375 $defaultLength = $validator->getMax();
379 return 'varchar2('.($defaultLength > 0? $defaultLength: 255).
' char)';
441 $offset = intval($offset);
442 $limit = intval($limit);
444 if ($offset > 0 && $limit <= 0)
445 throw new \Bitrix\Main\ArgumentException(
"Limit must be set if offset is set");
455 "WHERE ROWNUM <= ".$limit;
462 " SELECT rownum_query_alias.*, ROWNUM rownum_alias ".
463 " FROM (".$sql.
") rownum_query_alias ".
464 " WHERE ROWNUM <= ".($offset + $limit).
" ".
466 "WHERE rownum_alias >= ".($offset + 1);
491 public function prepareMerge($tableName, array $primaryFields, array $insertFields, array $updateFields)
495 $updateColumns = array();
496 $sourceSelectColumns = array();
497 $targetConnectColumns = array();
498 $tableFields = $this->connection->getTableFields($tableName);
499 foreach($tableFields as $columnName => $tableField)
501 $quotedName = $this->
quote($columnName);
502 if (in_array($columnName, $primaryFields))
504 $sourceSelectColumns[] = $this->
convertToDb($insertFields[$columnName], $tableField).
" AS ".$quotedName;
505 if($insertFields[$columnName] ===
null)
508 $targetConnectColumns[] =
"(source.".$quotedName.
" IS NULL AND target.".$quotedName.
" IS NULL)";
512 $targetConnectColumns[] =
"(source.".$quotedName.
" = target.".$quotedName.
")";
516 if (isset($updateFields[$columnName]) || array_key_exists($columnName, $updateFields))
518 $updateColumns[] =
"target.".$quotedName.
' = '.$this->
convertToDb($updateFields[$columnName], $tableField);
523 $insert && $insert[0] !=
"" && $insert[1] !=
""
525 && $sourceSelectColumns && $targetConnectColumns
529 MERGE INTO ".$this->quote($tableName).
" target USING (
530 SELECT ".implode(
", ", $sourceSelectColumns).
" FROM dual
534 ".implode(
" AND ", $targetConnectColumns).
"
537 UPDATE SET ".implode(
", ", $updateColumns).
"
538 WHEN NOT MATCHED THEN
539 INSERT (".$insert[0].
")
540 VALUES (".$insert[1].
")