393 $defaultPrecision = 18;
396 $precision = $field->getPrecision() > 0 ? $field->getPrecision() : $defaultPrecision;
397 $scale = $field->getScale() > 0 ? $field->getScale() : $defaultScale;
399 if ($scale >= $precision)
401 $precision = $defaultPrecision;
402 $scale = $defaultScale;
405 return "decimal($precision, $scale)";
407 elseif ($field instanceof ORM\Fields\
FloatField)
415 elseif ($field instanceof ORM\Fields\
DateField)
419 elseif ($field instanceof ORM\Fields\
TextField)
425 $values = $field->getValues();
427 if (preg_match(
'/^[0-9]+$/', $values[0]) && preg_match(
'/^[0-9]+$/', $values[1]))
433 return 'varchar('.max(mb_strlen($values[0]), mb_strlen($values[1])).
')';
436 elseif ($field instanceof ORM\Fields\
EnumField)
438 return 'varchar('.max(array_map(
'strlen', $field->getValues())).
')';
443 $defaultLength =
false;
446 if ($validator instanceof ORM\Fields\Validators\LengthValidator)
448 if ($defaultLength ===
false || $defaultLength > $validator->getMax())
450 $defaultLength = $validator->getMax();
454 return 'varchar('.($defaultLength > 0? $defaultLength: 255).
')';
472 $offset = intval($offset);
473 $limit = intval($limit);
475 if ($offset > 0 && $limit <= 0)
476 throw new \Bitrix\Main\ArgumentException(
"Limit must be set if offset is set");
480 $sql .=
"\nLIMIT ".$offset.
", ".$limit.
"\n";
496 public function prepareMerge($tableName, array $primaryFields, array $insertFields, array $updateFields)
502 $insert && $insert[0] !=
"" && $insert[1] !=
""
503 && $update && $update[1] !=
""
507 INSERT INTO ".$this->quote($tableName).
" (".$insert[0].
")
508 VALUES (".$insert[1].
")
509 ON DUPLICATE KEY UPDATE ".$update[0].
"