(non-PHPdoc).

@see core/model/fieldtypes/DBField#prepValueForDB($value)
556528
public function prepValueForDB($value)
    {
        if ($value instanceof MultiValueField) {
            $value = $value->getValue();
        }
        if (is_object($value) || is_array($value)) {
            $value = json_encode($value);
        }

        return parent::prepValueForDB($value);
    }
1207237
public function prepend($value, $key = null)
    {
        if (is_null($key)) {
            array_unshift($this->items, $value);
        }
        else {
            $this->items = [$key => $value] + $this->items;
        }

        return $this;
    }
1042268
protected function _setFieldValue($field, $value)
    {
        // ignore setting versioning fields
        if (static::isVersioned()) {
            if (array_key_exists($field, static::$versioningFields)) {
                return false;
            }
        }

        if (!static::fieldExists($field)) {
            return false;
        }
        $fieldOptions = static::$_classFields[get_called_class()][$field];

        // no overriding autoincrements
        if ($fieldOptions['autoincrement']) {
            return false;
        }

        // pre-process value
        $forceDirty = false;
        switch ($fieldOptions['type']) {
            case 'clob':
            case 'string':
            {
                $value = $this->_setStringValue($fieldOptions, $value);
                break;
            }

            case 'boolean':
            {
                $value = $this->_setBooleanValue($value);
                break;
            }

            case 'decimal':
            {
                $value = $this->_setDecimalValue($value);
                break;
            }

            case 'int':
            case 'uint':
            case 'integer':
            {
                $value = $this->_setIntegerValue($fieldOptions, $value);
                break;
            }

            case 'timestamp':
            {
                $value = $this->_setTimestampValue($value);
                break;
            }

            case 'date':
            {
                $value = $this->_setDateValue($value);
                break;
            }

            // these types are converted to strings from another PHP type on save
            case 'serialized':
            {
                $this->_convertedValues[$field] = $value;
                $value = $this->_setSerializedValue($value);
                break;
            }
            case 'enum':
            {
                $value = $this->_setEnumValue($fieldOptions, $value);
                break;
            }
            case 'set':
            case 'list':
            {
                $value = $this->_setListValue($fieldOptions, $value);
                $this->_convertedValues[$field] = $value;
                $forceDirty = true;
                break;
            }
        }

        if ($forceDirty || (empty($this->_record[$field]) && isset($value)) || ($this->_record[$field] !== $value)) {
            $columnName = static::_cn($field);
            if (isset($this->_record[$columnName])) {
                $this->_originalValues[$field] = $this->_record[$columnName];
            }
            $this->_record[$columnName] = $value;
            $this->_isDirty = true;

            // unset invalidated relationships
            if (!empty($fieldOptions['relationships']) && static::isRelational()) {
                foreach ($fieldOptions['relationships'] as $relationship => $isCached) {
                    if ($isCached) {
                        unset($this->_relatedObjects[$relationship]);
                    }
                }
            }
            return true;
        } else {
            return false;
        }
    }
1106703
public function prepareValue(&$value, $type)
    {
        if ($value === null) {
            return $value = 'NULL';
        }

        if (is_array($value)) {
            foreach ($value as &$v) {
                $this->prepareValue($v, $type);
            }

            return '(' . implode(', ', $value) . ')';
        }

        switch (strtolower($type)) {
            case 'timestamp':
                $value = is_int($value)
                    ?
                    '\'' . date(static::DATETIME_FORMAT, $value) . '\''
                    :
                    ($value instanceof \DateTime
                        ?
                        '\'' . $value->format(static::DATETIME_FORMAT) . '\''
                        :
                        '\'' . $this->connection->escape($value) . '\''
                    );
                break;

            case 'bit':
                $value = (int)intval($value);
                break;

            case 'dec':
            case 'decimal':
            case 'tinyint':
            case 'smallint':
            case 'bigint':
            case 'int':
                $value = (int)intval($value);
                break;
            case 'double':
            case 'float':
                $value = (float)floatval($value);
                break;

            default:
                $value = '\'' . $this->connection->escape($value) . '\'';
        }

        return $value;
    }
1314258
public function setValueAttribute($value)
    {
        if (!$this->isValid($value)) {
            throw new InvalidValueException("The value in the field '" . get_class($this) . "' is invalid");
        }

        $this->attributes['value'] = $this->prepareValue($value);
    }
1037765
public function appendFieldValue($value, Buffer $buffer)
    {
        if (is_string($value)) {
            $buffer->appendUint8(Constants::FIELD_LONG_STRING);
            $buffer->appendUint32(strlen($value));
            $buffer->append($value);

        } elseif (is_int($value)) {
            $buffer->appendUint8(Constants::FIELD_LONG_INT);
            $buffer->appendInt32($value);

        } elseif (is_bool($value)) {
            $buffer->appendUint8(Constants::FIELD_BOOLEAN);
            $buffer->appendUint8(intval($value));

        } elseif (is_float($value)) {
            $buffer->appendUint8(Constants::FIELD_DOUBLE);
            $buffer->appendDouble($value);

        } elseif (is_array($value)) {
            if (array_keys($value) === range(0, count($value) - 1)) { // sequential array
                $buffer->appendUint8(Constants::FIELD_ARRAY);
                $this->appendArray($value, $buffer);
            } else {
                $buffer->appendUint8(Constants::FIELD_TABLE);
                $this->appendTable($value, $buffer);
            }

        } elseif (is_null($value)) {
            $buffer->appendUint8(Constants::FIELD_NULL);

        } elseif ($value instanceof \DateTime) {
            $buffer->appendUint8(Constants::FIELD_TIMESTAMP);
            $this->appendTimestamp($value, $buffer);

        } else {
            throw new ProtocolException(
                "Unhandled value type '" . gettype($value) . "' " .
                (is_object($value) ? "(class " . get_class($value) . ")" : "") .
                "."
            );
        }
    }
276467
function setValue($value) {
        $values = (array) $value;
        foreach ($values as $onevalue) {
            if (($this->tags || $this->ajax) &&
                    (!$this->optionExists($onevalue)) &&
                    ($onevalue !== '_qf__force_multiselect_submission')) {
                $this->addOption($onevalue, $onevalue);
            }
        }
        return parent::setValue($value);
    }
1071808
public static function prepParamValue(&$value, &$operator): bool
    {

        if (is_array($value)) {
            return true;
        } else {
            self::normalizeEmptyValue($value);
            $operator = self::parseParamOperator($value);

            if (is_numeric($value)) {
                return true;
            } else {
                $value = StringHelper::toLowerCase($value);

                if ($value !== ':empty:' || $value !== 'not :empty:') {
                    // Trim any whitespace from the value
                    $value = StringHelper::trim($value);

                    return false;
                }
            }
        }

        return true;
    }
1160233
protected function _prepareValue($value, SQL $SQL, $identifier = false){

		// Identifier should be string (purely a sanity-check, enforced elsewhere)

		assert('!(!is_string($value) && $identifier)');

		// String

		if(is_string($value)){

			// NULL

			if(strtoupper($value) == 'NULL'){

				$value = 'NULL';
			}

			// Identifier string

			elseif($identifier){

				/*
				 * Surround the identifier with "identifier quote characters"
				 * (either backtick or double quote, depending on SQL mode) and
				 * escape all further occurences of said character with itself.
				 */

				$quote = self::IDENTIFIER_QUOTE;
				$value = str_replace($quote, $quote . $quote, $value);

				$value = $quote . $value . $quote;
			}

			// Regular string

			else{

				$value = '\'' . $SQL->escapeString($value) . '\'';
			}
		}

		// Integer

		elseif(is_int($value)){

			$value = (string) $value;
		}

		// Floating-point

		elseif(is_float($value)){

			$value = (string) $value;

			// Ensure no (other) invalid characters are present

			assert('!preg_match(\'/[^\d.e+\-]/i\', $value)');
			$value = preg_replace('/[^\d.e+\-]/i', '', $value);
		}

		// Boolean (interpreted as INT(1))

		elseif(is_bool($value)){

			// Don't convert directly to string, (int) false === ''!

			$value = (string) ((int) $value);
		}

		// NULL

		elseif($value === null){

			$value = 'NULL';
		}

		// Array (interpret either as SET or as a list of ID's)

		elseif(is_array($value)){

			$is_string = null;

			$callback = function($value) use($SQL, &$is_string){

				// Values should be either string or integer

				assert('is_string($value) || is_int($value)');
				if(!is_int($value)) $value = (string) $value;

				// All values should be of the same type, no "mixed bags"

				assert('$is_string === null || is_string($value) === $is_string');

				if(is_string($value)) $is_string = true;

				return $SQL->escapeString($value);
			};

			array_map($callback, $value);

			$value = implode(',', $value);

			if($is_string) $value = "'{$value}'";
		}

		// Object

		elseif(is_object($value)){

			$value = '\'' . $SQL->escapeString(serialize($value)) . '\'';
		}

		// Invalid

		else{

			throw new QueryBuilderException('Data of type "' . gettype($value)
				. '" cannot be used in an SQL-query');
		}

		return $value;
	}
848862
public function setValue($value): FieldTypeInterface
    {
        parent::setValue($value);

        if ($this->getValue()) {
            // The value is only set on the field when it fails
            // or when the option "flush" is set to "false".
            // If true, let's automatically add the "checked" attribute.
            $this->options['attributes']['checked'] = 'checked';
        }

        return $this;
    }
461000
static function ensureValue($value)
    {
        if (!self::hasValue($value)) {
            throw new InvalidValueException(sprintf(
                'The value %s is not defined in enum class "%s", known values: %s',
                self::dumpValue($value),
                static::class,
                implode(', ', array_map([static::class, 'dumpValue'], self::getValues()))
            ));
        }
    }
46779
public function setValue($value)
    {
        $matches = $this->parseKeywordText($value);
        if(isset($matches['keywords']))
        {
            if(isset($matches['keywords'][1]))
            {
                $this->database = $matches['keywords'][0];
                $this->table = $matches['keywords'][1];
            }
            else if(isset($matches['keywords'][0]))
            {
                $this->database = null;
                $this->table = $matches['keywords'][0];
            }
            $this->alias = $matches['alias'];
        }
    }
28214
public function append($value)
    {
        if ($this->isValidType($value) === false) {
            throw new MWrongTypeException("\$value", $this->getType(), $value);
        }

        $this->list[] = $value;
    }
625122
final public static function byValue($value)
    {
        if (!isset(self::$constants[static::class])) {
            self::detectConstants(static::class);
        }

        $name = \array_search($value, self::$constants[static::class], true);
        if ($name === false) {
            throw new InvalidArgumentException(sprintf(
                'Unknown value %s for enumeration %s',
                \is_scalar($value)
                    ? \var_export($value, true)
                    : 'of type ' . (\is_object($value) ? \get_class($value) : \gettype($value)),
                static::class
            ));
        }

        if (!isset(self::$instances[static::class][$name])) {
            self::$instances[static::class][$name] = new static(self::$constants[static::class][$name]);
        }

        return self::$instances[static::class][$name];
    }
648046
public static function convertToDatabaseValue($value, QueryBuilder $qb)
    {
        if ($type = DBALTypesResolver::tryGetTypeForValue($value)) {
            return $type->convertToDatabaseValue(
                $value,
                $qb->getEntityManager()->getConnection()->getDatabasePlatform()
            );
        }

        return $value;
    }
858696
private function prepareLookupValue($value, $lookups, &$canReuse, $allowJoins = true)
    {
        $usedJoins = [];
        if (empty($lookups)) {
            $lookups = ['exact'];
        }

        // Interpret '__exact=null' as the sql 'is NULL'; otherwise, reject all
        // uses of null as a query value.
        if (is_null($value)) {
            if (!in_array(array_pop($lookups), ['exact'])) {
                throw new ValueError('Cannot use "null" as a query value');
            }

            return [true, ['isnull']];
        } elseif ($value instanceof ResolvableExpInterface) {
            $preJoins = $this->aliasRefCount;
            $value = $value->resolveExpression($this, $allowJoins, $canReuse);
            foreach ($this->aliasRefCount as $key => $count) {
                if ($count > ArrayHelper::getValue($preJoins, $key, 0)) {
                    $usedJoins[] = $key;
                }
            }
        }

        if (method_exists($value, '_prepareAsFilterValue')) {
            $value = $value->_prepareAsFilterValue();
        }

        if (is_object($value) && property_exists($value, 'query') &&
            method_exists($value->query, 'bumpPrefix')) {
            /** @var $value Queryset */
            $value = $value->_clone();
            $value->query->bumpPrefix($this);
        }
        // Subqueries need to use a different set of aliases than the
        // outer query. Call bumpPrefix to change aliases of the inner
        // query (the value).
        if (is_object($value) && method_exists($value, 'bumpPrefix')) {
            /** @var $value Query */
            $value = $value->deepClone();
            $value->bumpPrefix($this);
        }

        //todo if value is array
        return [$value, $lookups, $usedJoins];
    }
761673
public static final void appendValueToSql(StringBuilder sql, Object value) {
        if (value == null) {
            sql.append("NULL");
        } else if (value instanceof Boolean) {
            Boolean bool = (Boolean)value;
            if (bool) {
                sql.append('1');
            } else {
                sql.append('0');
            }
        } else {
            appendEscapedSQLString(sql, value.toString());
        }
    }