PostgreSQL Source Code git master
quote.c File Reference
#include "postgres.h"
#include "utils/builtins.h"
#include "varatt.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

◆ quote_ident()

Datum quote_ident ( PG_FUNCTION_ARGS  )

Definition at line 25 of file quote.c.

26{
27 text *t = PG_GETARG_TEXT_PP(0);
28 const char *qstr;
29 char *str;
30
32 qstr = quote_identifier(str);
34}
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
const char * str
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:12940
Definition: c.h:644
text * cstring_to_text(const char *s)
Definition: varlena.c:184
char * text_to_cstring(const text *t)
Definition: varlena.c:217

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

Referenced by quote_ident_cstr().

◆ quote_literal()

Datum quote_literal ( PG_FUNCTION_ARGS  )

Definition at line 78 of file quote.c.

79{
80 text *t = PG_GETARG_TEXT_PP(0);
81 text *result;
82 char *cp1;
83 char *cp2;
84 int len;
85
87 /* We make a worst-case result area; wasting a little space is OK */
88 result = (text *) palloc(len * 2 + 3 + VARHDRSZ);
89
90 cp1 = VARDATA_ANY(t);
91 cp2 = VARDATA(result);
92
93 SET_VARSIZE(result, VARHDRSZ + quote_literal_internal(cp2, cp1, len));
94
95 PG_RETURN_TEXT_P(result);
96}
#define VARHDRSZ
Definition: c.h:649
void * palloc(Size size)
Definition: mcxt.c:1317
const void size_t len
static size_t quote_literal_internal(char *dst, const char *src, size_t len)
Definition: quote.c:47
#define VARDATA(PTR)
Definition: varatt.h:278
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

References len, palloc(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, quote_literal_internal(), SET_VARSIZE, VARDATA, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY_EXHDR.

Referenced by GetPublicationsStr(), and quote_nullable().

◆ quote_literal_cstr()

char * quote_literal_cstr ( const char *  rawstr)

Definition at line 103 of file quote.c.

104{
105 char *result;
106 int len;
107 int newlen;
108
109 len = strlen(rawstr);
110 /* We make a worst-case result area; wasting a little space is OK */
111 result = palloc(len * 2 + 3 + 1);
112
113 newlen = quote_literal_internal(result, rawstr, len);
114 result[newlen] = '\0';
115
116 return result;
117}

References len, palloc(), and quote_literal_internal().

Referenced by build_tuplestore_recursively(), fetch_remote_table_info(), get_sql_delete(), get_sql_insert(), get_sql_update(), get_tuple_of_interest(), GetPublicationsStr(), pg_decode_commit_prepared_txn(), pg_decode_prepare_txn(), pg_decode_rollback_prepared_txn(), pg_decode_stream_prepare(), PLy_quote_literal(), PLy_quote_nullable(), text_format_string_conversion(), and validate_remote_info().

◆ quote_literal_internal()

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

Definition at line 47 of file quote.c.

48{
49 const char *s;
50 char *savedst = dst;
51
52 for (s = src; s < src + len; s++)
53 {
54 if (*s == '\\')
55 {
56 *dst++ = ESCAPE_STRING_SYNTAX;
57 break;
58 }
59 }
60
61 *dst++ = '\'';
62 while (len-- > 0)
63 {
64 if (SQL_STR_DOUBLE(*src, true))
65 *dst++ = *src;
66 *dst++ = *src++;
67 }
68 *dst++ = '\'';
69
70 return dst - savedst;
71}
#define ESCAPE_STRING_SYNTAX
Definition: c.h:1123
#define SQL_STR_DOUBLE(ch, escape_backslash)
Definition: c.h:1120

References ESCAPE_STRING_SYNTAX, len, and SQL_STR_DOUBLE.

Referenced by quote_literal(), and quote_literal_cstr().

◆ quote_nullable()

Datum quote_nullable ( PG_FUNCTION_ARGS  )

Definition at line 125 of file quote.c.

126{
127 if (PG_ARGISNULL(0))
129 else
131 PG_GETARG_DATUM(0)));
132}
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:641
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Datum quote_literal(PG_FUNCTION_ARGS)
Definition: quote.c:78

References cstring_to_text(), DirectFunctionCall1, PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_DATUM, PG_RETURN_TEXT_P, and quote_literal().