Postgres::formatValue PHP Method

formatValue() public method

Formats a value or expression for sql purposes
public formatValue ( $type, $format, $value ) : The
$type The type of the field
$format VALUE or EXPRESSION
$value The actual value entered in the field. Can be NULL
return The suitably quoted and escaped value.
    function formatValue($type, $format, $value)
    {
        switch ($type) {
            case 'bool':
            case 'boolean':
                if ($value == 't') {
                    return 'TRUE';
                } elseif ($value == 'f') {
                    return 'FALSE';
                } elseif ($value == '') {
                    return 'NULL';
                } else {
                    return $value;
                }
                break;
            default:
                // Checking variable fields is difficult as there might be a size
                // attribute...
                if (strpos($type, 'time') === 0) {
                    // Assume it's one of the time types...
                    if ($value == '') {
                        return "''";
                    } elseif (strcasecmp($value, 'CURRENT_TIMESTAMP') == 0 || strcasecmp($value, 'CURRENT_TIME') == 0 || strcasecmp($value, 'CURRENT_DATE') == 0 || strcasecmp($value, 'LOCALTIME') == 0 || strcasecmp($value, 'LOCALTIMESTAMP') == 0) {
                        return $value;
                    } elseif ($format == 'EXPRESSION') {
                        return $value;
                    } else {
                        $this->clean($value);
                        return "'{$value}'";
                    }
                } else {
                    if ($format == 'VALUE') {
                        $this->clean($value);
                        return "'{$value}'";
                    }
                    return $value;
                }
        }
    }
Postgres