PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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)
 
charquote_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
34}
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
const char * str
static int fb(int x)
const char * quote_identifier(const char *ident)
Definition c.h:706
text * cstring_to_text(const char *s)
Definition varlena.c:181
char * text_to_cstring(const text *t)
Definition varlena.c:214

References cstring_to_text(), fb(), 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 76 of file quote.c.

77{
78 text *t = PG_GETARG_TEXT_PP(0);
79 text *result;
80 char *cp1;
81 char *cp2;
82 int len;
83
85 /* We make a worst-case result area; wasting a little space is OK */
86 result = (text *) palloc(len * 2 + 3 + VARHDRSZ);
87
88 cp1 = VARDATA_ANY(t);
89 cp2 = VARDATA(result);
90
92
93 PG_RETURN_TEXT_P(result);
94}
#define VARHDRSZ
Definition c.h:711
void * palloc(Size size)
Definition mcxt.c:1387
const void size_t len
static size_t quote_literal_internal(char *dst, const char *src, size_t len)
Definition quote.c:45
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition varatt.h:472
static char * VARDATA(const void *PTR)
Definition varatt.h:305
static char * VARDATA_ANY(const void *PTR)
Definition varatt.h:486
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

References fb(), 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 101 of file quote.c.

102{
103 char *result;
104 int len;
105 int newlen;
106
107 len = strlen(rawstr);
108 /* We make a worst-case result area; wasting a little space is OK */
109 result = palloc(
110 (len * 2) /* doubling for every character if each one is
111 * a quote */
112 + 3 /* two outer quotes + possibly 'E' if needed */
113 + 1 /* null terminator */
114 );
115
117 result[newlen] = '\0';
118
119 return result;
120}

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

Referenced by build_tuplestore_recursively(), copy_sequences(), fetch_remote_slots(), 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 45 of file quote.c.

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

References ESCAPE_STRING_SYNTAX, fb(), len, and SQL_STR_DOUBLE.

Referenced by quote_literal(), and quote_literal_cstr().

◆ quote_nullable()

Datum quote_nullable ( PG_FUNCTION_ARGS  )

Definition at line 128 of file quote.c.

129{
130 if (PG_ARGISNULL(0))
132 else
134 PG_GETARG_DATUM(0)));
135}
#define PG_ARGISNULL(n)
Definition fmgr.h:209
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
Datum quote_literal(PG_FUNCTION_ARGS)
Definition quote.c:76

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