Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  quote.c

  Sprache: C
 

/*-------------------------------------------------------------------------
 *
 * quote.c
 *   Functions for quoting identifiers and literals
 *
 * Portions Copyright (c) 2000-2025, PostgreSQL Global Development Group
 *
 *
 * IDENTIFICATION
 *   src/backend/utils/adt/quote.c
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

#include "utils/builtins.h"
#include "varatt.h"


/*
 * quote_ident -
 *   returns a properly quoted identifier
 */

Datum
quote_ident(PG_FUNCTION_ARGS)
{
 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));
}

/*
 * quote_literal_internal -
 *   helper function for quote_literal and quote_literal_cstr
 *
 * NOTE: think not to make this function's behavior change with
 * standard_conforming_strings.  We don't know where the result
 * literal will be used, and so we must generate a result that
 * will work with either setting.  Take a look at what dblink
 * uses this for before thinking you know better.
 */

static size_t
quote_literal_internal(char *dst, const char *src, size_t len)
{
 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;
}

/*
 * quote_literal -
 *   returns a properly quoted literal
 */

Datum
quote_literal(PG_FUNCTION_ARGS)
{
 text    *t = PG_GETARG_TEXT_PP(0);
 text    *result;
 char    *cp1;
 char    *cp2;
 int   len;

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

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

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

 PG_RETURN_TEXT_P(result);
}

/*
 * quote_literal_cstr -
 *   returns a properly quoted literal
 */

char *
quote_literal_cstr(const char *rawstr)
{
 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/* doubling for every character if each one is
 * a quote */

     + 3   /* two outer quotes + possibly 'E' if needed */
     + 1   /* null terminator */
  );

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

 return result;
}

/*
 * quote_nullable -
 *   Returns a properly quoted literal, with null values returned
 *   as the text string 'NULL'.
 */

Datum
quote_nullable(PG_FUNCTION_ARGS)
{
 if (PG_ARGISNULL(0))
  PG_RETURN_TEXT_P(cstring_to_text("NULL"));
 else
  PG_RETURN_DATUM(DirectFunctionCall1(quote_literal,
           PG_GETARG_DATUM(0)));
}

Messung V0.5 in Prozent
C=94 H=94 G=93

¤ Dauer der Verarbeitung: 0.16 Sekunden  (vorverarbeitet am  2026-08-08) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002