@param $value
@param string $type

@throws \Doctrine\DBAL\DBALException

@return mixed
187225
protected function castToType($value, string $type)
    {
        $platform = $this->connection->getDatabasePlatform();

        return Type::getType($type)->convertToDatabaseValue($value, $platform);
    }
381987
public function bindValue($parameter, $value, $type = null)
    {
        return $this->bindParam($parameter, $value, $type);
    }
1274909
protected function getTypeByProperty($type, $property, $value)
    {
        foreach($this[$type] as $item) {
            if (true === isset($item[$property]) && $value === $item[$property]) {
                return $item;
            }
        }

        throw new \RuntimeException(sprintf("Unknown %s item with %s '%s'", $type, $property, $value), 404);
    }
136989
private function parseDate(string $type, $value)
    {
        try {
            switch ($type) {
                case 'datetime':
                    $datetime = DateTime::createFromFormat('Y-m-d\TH:i:s', $value);
                    break;

                case 'date':
                    $datetime = Date::createFromFormat('Y-m-d', $value);
                    break;

                case 'time':
                    $datetime = Time::createFromFormat('H:i:s', $value);
                    break;

                default:
                    throw new \InvalidArgumentException(sprintf("Invalid parse date type '%s'", $type));
            }
        } catch (\Exception $exception) {
            return null;
        }

        return $datetime;
    }
786262
public static function fromValue($value) : Type
    {
        switch (gettype($value)) {
            case 'string':
                return Text::long();

            case 'integer':
                return Integer::big();

            case 'double':
                return new Decimal(30, 15);

            case 'boolean':
                return new Boolean();

            case $value instanceof \DateTimeInterface:
                return new DateTime();

            default:
                throw InvalidArgumentException::format(
                        'Invalid call to %s: unknown value type \'%s\' given',
                        __METHOD__, gettype($value)
                );
        }
    }
792722
public function prepareValue($value, $datatype)
     {
        if ($value === null) {
            return 'NULL';
        }
        switch ($datatype) {
            case Column::TYPE_INTEGER:
                // Filter explicitly because some DBAL silently convert/truncate to integer
                $filtered = filter_var($value, FILTER_VALIDATE_INT);
                if ($filtered === false) {
                    throw new \InvalidArgumentException('Not an integer: '. $value);
                }
                return $filtered; // No quotes necessary
            case Column::TYPE_FLOAT:
            case Column::TYPE_DECIMAL:
                // Filter explicitly because some DBAL silently convert/truncate to float
                $filtered = filter_var($value, FILTER_VALIDATE_FLOAT);
                if ($filtered === false) {
                    throw new \InvalidArgumentException('Not a number: '. $value);
                }
                return $filtered; // No quotes necessary
            case Column::TYPE_BOOL:
                if (is_bool($value)) { // filter_var() does not work with real booleans
                    $filtered = $value;
                } else {
                    $filtered = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
                }
                if ($filtered === null) {
                    throw new \InvalidArgumentException('Not a boolean: ' . $value);
                }
                return (integer)$filtered; // Convert to 0/1 for compatibility with emulated booleans
            case Column::TYPE_BLOB:
                // Handled differently across DBMS and abstraction layers - refuse by default.
                throw new \InvalidArgumentException('Cannot prepare BLOB values');
            default:
                return $this->_link->quoteValue($value, $datatype);
        }
     }
318613
protected function _convertToDBDate($value, $fieldType)
    {
        $convertedObject = new \OxidEsales\Eshop\Core\Field();
        $convertedObject->setValue($value);
        if ($fieldType == "datetime") {
            if (strlen($value) == 10 || strlen($value) == 22 || (strlen($value) == 19 && !stripos($value, "m"))) {
                \OxidEsales\Eshop\Core\Registry::getUtilsDate()->convertDBDateTime($convertedObject, true);
            } else {
                if (strlen($value) > 10) {
                    return $this->_convertTime($value);
                } else {
                    return $this->_convertDate($value);
                }
            }
        } elseif ($fieldType == "date") {
            if (strlen($value) == 10) {
                \OxidEsales\Eshop\Core\Registry::getUtilsDate()->convertDBDate($convertedObject, true);
            } else {
                return $this->_convertDate($value);
            }
        }

        return $convertedObject->value;
    }
1167406
public function getPDOConstantType($value)
    {

        switch (true) {
            case is_int($value):
                $type = PDO::PARAM_INT;
                break;
            case is_bool($value):
                $type = PDO::PARAM_BOOL;
                break;
            case (null === $value):
                $type = PDO::PARAM_NULL;
                break;
            default:
                $type = PDO::PARAM_STR;
        }
        return $type;
    }
319739
protected function query($value)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $query->select(sprintf('entity.%s', $this->getField()))
                ->from($this->getEntity(), 'entity')
                ->where(sprintf('entity.%s = :field', $this->getField()))
                ->setParameter(':field', $value);

        foreach ($this->getExclude() as $exclude => $value) {
            $query->andWhere(sprintf('entity.%s != :%s', $exclude, $exclude))
                    ->setParameter($exclude, $value);
        }

        foreach ($this->getInclude() as $include => $value) {
            $query->andWhere(sprintf('entity.%s = :%s', $include, $include))
                    ->setParameter($include, $value);
        }

        return $query->getQuery()->execute();
    }
51484
public function setParameter($key, $value, $type = null)
    {
        $this->_dbPending[] = [
            'name' => 'setParameter',
            'args' => [$key, $value, $type],
        ];

        return $this;
    }
211029
public static function TreatValueAs( $value, $type)
	{
		if ( $value instanceof Undefined )
		{
			return $value;
		}

		if ( is_null( $value ) )
		{
			$value = CoreFuncs::$False;
		}

		if ( $type->TypeCode == XmlTypeCode::None)
			throw XPath2Exception::withErrorCodeAndParams( "XPDY0050", Resources::XPDY0050,
				array(
					$type,
					"empty-sequence()"
				)
			);

		if ( Type::FromValue( $value ) != $type->ItemType && $type->ItemType != Types::$ObjectType )
		{
			if ( $type->ItemType == Types::$IntegerType )
			{
				return Integer::ToInteger( $value, null );
			}
			else if ( $type->ItemType == Types::$DecimalType )
			{
				return DecimalValue::FromValue( $value );
				return $value + 0.0;
			}
			throw XPath2Exception::withErrorCodeAndParams( "XPDY0050", Resources::XPDY0050,
				array(
					$type,
					SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $value ), XmlTypeCardinality::One ),
				)
			);
		}
		return $value;
	}
663814
protected function checkType($value, $type, $nullable = false)
    {
        if (gettype($value) === $type) {
            return true;
        }
        return $nullable && null === $value;
    }
29906
protected function convert($value, int $type)
    {
        switch ($type) {
            case FieldsInterface::TYPE_INT:
                $result = (int)$value;
                break;
            case FieldsInterface::TYPE_FLOAT:
                $result = (float)$value;
                break;
            case FieldsInterface::TYPE_BOOL:
                $result = is_numeric($value) ? (bool)$value : $value === 't';
                break;
            case FieldsInterface::TYPE_DATE:
                $result = strtotime($value);
                break;
            case FieldsInterface::TYPE_UNIXTIME:
                $result = new \DateTime();
                $result->setTimestamp((int)$value);
                break;
            case FieldsInterface::TYPE_STRING:
                $result = $value ?? '';
                break;
            case FieldsInterface::TYPE_ARRAY:
            default:
                $result = $value;
        }

        return $result;
    }
1232005
private function cast($value, $type)
    {
        switch ($type) {
            case 'bool':
                return boolval($value);
                break;
            case 'int':
                return intval($value);
                break;
            case 'float':
                return floatval($value);
                break;
            case 'string':
                return $value;
                break;
            case 'array':
                if (is_array($value)) {
                    return serialize($value);
                } else {
                    return unserialize($value);
                }
                break;
            default:
                return $value;
        }
    }
365590
protected function getContentByDataValue($type, $value)
    {
        $element = new $type($value);

        if (null !== $this->em) {
            $element = $this->em->getRepository($type)->load($element, $this->token);
        }

        return $element;
    }
1311103
protected function getTypeSwapValue($type, $value)
    {
        switch (strtolower($type)) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            default:
                return $value;
        }
    }
632350
public function set($key, $value, $type=null) {
		if($type === null)
			$res = serialize($value);
		else {
			$res = serialize(array(
				'_dataType' => $type,
				'input' => $this->types[$type][0]($value)
			));
		}
		$dal = $this->db->dal();
		if(!$dal->from($this->getTable())->where('key', $key)->update(array('value'=>$res)))
			$dal->into($this->getTable())->insert(array('key'=>$key, 'value'=>$res));
	}