Header And Logo

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

Functions

quote.c File Reference

#include "postgres.h"
#include "utils/builtins.h"
Include dependency graph for quote.c:

Go to the source code of this file.

Functions

Datum quote_ident (PG_FUNCTION_ARGS)
static size_t quote_literal_internal (char *dst, const char *src, size_t len)
Datum quote_literal (PG_FUNCTION_ARGS)
char * quote_literal_cstr (const char *rawstr)
Datum quote_nullable (PG_FUNCTION_ARGS)

Function Documentation

Datum quote_ident ( PG_FUNCTION_ARGS   ) 

Definition at line 24 of file quote.c.

References cstring_to_text(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, quote_identifier(), and text_to_cstring().

Referenced by quote_ident_cstr().

{
    text       *t = PG_GETARG_TEXT_PP(0);
    const char *qstr;
    char       *str;

    str = text_to_cstring(t);
    qstr = quote_identifier(str);
    PG_RETURN_TEXT_P(cstring_to_text(qstr));
}

Datum quote_literal ( PG_FUNCTION_ARGS   ) 

Definition at line 77 of file quote.c.

References palloc(), PG_GETARG_TEXT_P, PG_RETURN_TEXT_P, quote_literal_internal(), SET_VARSIZE, VARDATA, VARHDRSZ, and VARSIZE.

Referenced by quote_nullable().

{
    text       *t = PG_GETARG_TEXT_P(0);
    text       *result;
    char       *cp1;
    char       *cp2;
    int         len;

    len = VARSIZE(t) - VARHDRSZ;
    /* We make a worst-case result area; wasting a little space is OK */
    result = (text *) palloc(len * 2 + 3 + VARHDRSZ);

    cp1 = VARDATA(t);
    cp2 = VARDATA(result);

    SET_VARSIZE(result, VARHDRSZ + quote_literal_internal(cp2, cp1, len));

    PG_RETURN_TEXT_P(result);
}

char* quote_literal_cstr ( const char *  rawstr  ) 

Definition at line 102 of file quote.c.

References palloc(), and quote_literal_internal().

Referenced by build_tuplestore_recursively(), get_sql_delete(), get_sql_insert(), get_sql_update(), get_tuple_of_interest(), PLy_quote_literal(), PLy_quote_nullable(), and text_format_string_conversion().

{
    char       *result;
    int         len;
    int         newlen;

    len = strlen(rawstr);
    /* We make a worst-case result area; wasting a little space is OK */
    result = palloc(len * 2 + 3);

    newlen = quote_literal_internal(result, rawstr, len);
    result[newlen] = '\0';

    return result;
}

static size_t quote_literal_internal ( char *  dst,
const char *  src,
size_t  len 
) [static]

Definition at line 46 of file quote.c.

References SQL_STR_DOUBLE.

Referenced by quote_literal(), and quote_literal_cstr().

{
    const char *s;
    char       *savedst = dst;

    for (s = src; s < src + len; s++)
    {
        if (*s == '\\')
        {
            *dst++ = ESCAPE_STRING_SYNTAX;
            break;
        }
    }

    *dst++ = '\'';
    while (len-- > 0)
    {
        if (SQL_STR_DOUBLE(*src, true))
            *dst++ = *src;
        *dst++ = *src++;
    }
    *dst++ = '\'';

    return dst - savedst;
}

Datum quote_nullable ( PG_FUNCTION_ARGS   )