Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

bool.c File Reference

#include "postgres.h"
#include <ctype.h>
#include "libpq/pqformat.h"
#include "utils/builtins.h"
Include dependency graph for bool.c:

Go to the source code of this file.

Functions

bool parse_bool (const char *value, bool *result)
bool parse_bool_with_len (const char *value, size_t len, bool *result)
Datum boolin (PG_FUNCTION_ARGS)
Datum boolout (PG_FUNCTION_ARGS)
Datum boolrecv (PG_FUNCTION_ARGS)
Datum boolsend (PG_FUNCTION_ARGS)
Datum booltext (PG_FUNCTION_ARGS)
Datum booleq (PG_FUNCTION_ARGS)
Datum boolne (PG_FUNCTION_ARGS)
Datum boollt (PG_FUNCTION_ARGS)
Datum boolgt (PG_FUNCTION_ARGS)
Datum boolle (PG_FUNCTION_ARGS)
Datum boolge (PG_FUNCTION_ARGS)
Datum booland_statefunc (PG_FUNCTION_ARGS)
Datum boolor_statefunc (PG_FUNCTION_ARGS)

Function Documentation

Datum booland_statefunc ( PG_FUNCTION_ARGS   ) 

Definition at line 290 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

Datum booleq ( PG_FUNCTION_ARGS   ) 

Definition at line 229 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

{
    bool        arg1 = PG_GETARG_BOOL(0);
    bool        arg2 = PG_GETARG_BOOL(1);

    PG_RETURN_BOOL(arg1 == arg2);
}

Datum boolge ( PG_FUNCTION_ARGS   ) 

Definition at line 274 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

{
    bool        arg1 = PG_GETARG_BOOL(0);
    bool        arg2 = PG_GETARG_BOOL(1);

    PG_RETURN_BOOL(arg1 >= arg2);
}

Datum boolgt ( PG_FUNCTION_ARGS   ) 

Definition at line 256 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

{
    bool        arg1 = PG_GETARG_BOOL(0);
    bool        arg2 = PG_GETARG_BOOL(1);

    PG_RETURN_BOOL(arg1 > arg2);
}

Datum boolin ( PG_FUNCTION_ARGS   ) 

Definition at line 130 of file bool.c.

References ereport, errcode(), errmsg(), ERROR, parse_bool_with_len(), PG_GETARG_CSTRING, and PG_RETURN_BOOL.

{
    const char *in_str = PG_GETARG_CSTRING(0);
    const char *str;
    size_t      len;
    bool        result;

    /*
     * Skip leading and trailing whitespace
     */
    str = in_str;
    while (isspace((unsigned char) *str))
        str++;

    len = strlen(str);
    while (len > 0 && isspace((unsigned char) str[len - 1]))
        len--;

    if (parse_bool_with_len(str, len, &result))
        PG_RETURN_BOOL(result);

    ereport(ERROR,
            (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
           errmsg("invalid input syntax for type boolean: \"%s\"", in_str)));

    /* not reached */
    PG_RETURN_BOOL(false);
}

Datum boolle ( PG_FUNCTION_ARGS   ) 

Definition at line 265 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

{
    bool        arg1 = PG_GETARG_BOOL(0);
    bool        arg2 = PG_GETARG_BOOL(1);

    PG_RETURN_BOOL(arg1 <= arg2);
}

Datum boollt ( PG_FUNCTION_ARGS   ) 

Definition at line 247 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

{
    bool        arg1 = PG_GETARG_BOOL(0);
    bool        arg2 = PG_GETARG_BOOL(1);

    PG_RETURN_BOOL(arg1 < arg2);
}

Datum boolne ( PG_FUNCTION_ARGS   ) 

Definition at line 238 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

{
    bool        arg1 = PG_GETARG_BOOL(0);
    bool        arg2 = PG_GETARG_BOOL(1);

    PG_RETURN_BOOL(arg1 != arg2);
}

Datum boolor_statefunc ( PG_FUNCTION_ARGS   ) 

Definition at line 299 of file bool.c.

References PG_GETARG_BOOL, and PG_RETURN_BOOL.

Datum boolout ( PG_FUNCTION_ARGS   ) 

Definition at line 163 of file bool.c.

References palloc(), PG_GETARG_BOOL, and PG_RETURN_CSTRING.

{
    bool        b = PG_GETARG_BOOL(0);
    char       *result = (char *) palloc(2);

    result[0] = (b) ? 't' : 'f';
    result[1] = '\0';
    PG_RETURN_CSTRING(result);
}

Datum boolrecv ( PG_FUNCTION_ARGS   ) 

Definition at line 180 of file bool.c.

References buf, PG_GETARG_POINTER, PG_RETURN_BOOL, and pq_getmsgbyte().

{
    StringInfo  buf = (StringInfo) PG_GETARG_POINTER(0);
    int         ext;

    ext = pq_getmsgbyte(buf);
    PG_RETURN_BOOL((ext != 0) ? true : false);
}

Datum boolsend ( PG_FUNCTION_ARGS   ) 

Definition at line 193 of file bool.c.

References buf, PG_GETARG_BOOL, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendbyte().

{
    bool        arg1 = PG_GETARG_BOOL(0);
    StringInfoData buf;

    pq_begintypsend(&buf);
    pq_sendbyte(&buf, arg1 ? 1 : 0);
    PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}

Datum booltext ( PG_FUNCTION_ARGS   ) 

Definition at line 210 of file bool.c.

References cstring_to_text(), PG_GETARG_BOOL, and PG_RETURN_TEXT_P.

{
    bool        arg1 = PG_GETARG_BOOL(0);
    const char *str;

    if (arg1)
        str = "true";
    else
        str = "false";

    PG_RETURN_TEXT_P(cstring_to_text(str));
}

bool parse_bool ( const char *  value,
bool result 
)
bool parse_bool_with_len ( const char *  value,
size_t  len,
bool result 
)

Definition at line 36 of file bool.c.

References pg_strncasecmp().

Referenced by boolin(), and parse_bool().

{
    switch (*value)
    {
        case 't':
        case 'T':
            if (pg_strncasecmp(value, "true", len) == 0)
            {
                if (result)
                    *result = true;
                return true;
            }
            break;
        case 'f':
        case 'F':
            if (pg_strncasecmp(value, "false", len) == 0)
            {
                if (result)
                    *result = false;
                return true;
            }
            break;
        case 'y':
        case 'Y':
            if (pg_strncasecmp(value, "yes", len) == 0)
            {
                if (result)
                    *result = true;
                return true;
            }
            break;
        case 'n':
        case 'N':
            if (pg_strncasecmp(value, "no", len) == 0)
            {
                if (result)
                    *result = false;
                return true;
            }
            break;
        case 'o':
        case 'O':
            /* 'o' is not unique enough */
            if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
            {
                if (result)
                    *result = true;
                return true;
            }
            else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
            {
                if (result)
                    *result = false;
                return true;
            }
            break;
        case '1':
            if (len == 1)
            {
                if (result)
                    *result = true;
                return true;
            }
            break;
        case '0':
            if (len == 1)
            {
                if (result)
                    *result = false;
                return true;
            }
            break;
        default:
            break;
    }

    if (result)
        *result = false;        /* suppress compiler warning */
    return false;
}