public function quote($value, $type = DB::PARAM_AUTO) {
        if (is_array($value))
            return sprintf('(%s)', implode(', ', array_map(function($v) use($this, $type) {
                                return $this->quote($v, $type);
                            }, $value)));
        $type = ($type == DB::PARAM_AUTO) ? $this->quotedType($value) : $type;
        switch ($type) {
            case DB::PARAM_STR:
                $value = $this->escapeString($value);
                break;
            case DB::PARAM_DATE:
            case DB::PARAM_TIME:
            case DB::PARAM_DATETIME:
                switch ($type) {
                    case DB::PARAM_DATE:
                        $format = 'Y-m-d';
                        break;
                    case DB::PARAM_TIME:
                        $format = 'H:i:s';
                        break;
                    default:
                        $format = 'Y-m-d H:i:s';
                }
                if (interface_exists('\\DateTimeInterface') and $value instanceof \DateTimeInterface or $value instanceof \DateTime)
                    $value = $value->format($format);
                else {
                    $dt = date_create($value);
                    if ($dt === false)
                        $dt = new \DateTime;
                    if (is_int($value))
                        $dt->setTimestamp($value);
                    $value = $dt->format($format);
                }
                break;
            case DB::PARAM_INT:
                $value = intval($value);
                break;
            case DB::PARAM_BOOL:
                $value = $value ? 1 : 0;
                break;
            case DB::PARAM_FLOAT:
                $value = floatval($value);
                break;
            case DB::PARAM_NULL:
                $value = 'NULL';
                break;
            default:
                throw new \UnexpectedValueException('Invalid parameter value');
        }
        return ($type & DB::PARAM_STR) ? "'$value'" : $value;
    }