#include "postgres.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
Go to the source code of this file.
Functions | |
Datum | namein (PG_FUNCTION_ARGS) |
Datum | nameout (PG_FUNCTION_ARGS) |
Datum | namerecv (PG_FUNCTION_ARGS) |
Datum | namesend (PG_FUNCTION_ARGS) |
Datum | nameeq (PG_FUNCTION_ARGS) |
Datum | namene (PG_FUNCTION_ARGS) |
Datum | namelt (PG_FUNCTION_ARGS) |
Datum | namele (PG_FUNCTION_ARGS) |
Datum | namegt (PG_FUNCTION_ARGS) |
Datum | namege (PG_FUNCTION_ARGS) |
int | namecpy (Name n1, Name n2) |
int | namestrcpy (Name name, const char *str) |
int | namestrcmp (Name name, const char *str) |
Datum | current_user (PG_FUNCTION_ARGS) |
Datum | session_user (PG_FUNCTION_ARGS) |
Datum | current_schema (PG_FUNCTION_ARGS) |
Datum | current_schemas (PG_FUNCTION_ARGS) |
Datum current_schema | ( | PG_FUNCTION_ARGS | ) |
Definition at line 280 of file name.c.
References CStringGetDatum, DirectFunctionCall1, fetch_search_path(), get_namespace_name(), linitial_oid, list_free(), namein(), NIL, PG_RETURN_DATUM, and PG_RETURN_NULL.
{ List *search_path = fetch_search_path(false); char *nspname; if (search_path == NIL) PG_RETURN_NULL(); nspname = get_namespace_name(linitial_oid(search_path)); list_free(search_path); if (!nspname) PG_RETURN_NULL(); /* recently-deleted namespace? */ PG_RETURN_DATUM(DirectFunctionCall1(namein, CStringGetDatum(nspname))); }
Datum current_schemas | ( | PG_FUNCTION_ARGS | ) |
Definition at line 295 of file name.c.
References construct_array(), CStringGetDatum, DirectFunctionCall1, fetch_search_path(), get_namespace_name(), lfirst_oid, list_free(), list_length(), namein(), NAMEOID, palloc(), PG_GETARG_BOOL, and PG_RETURN_POINTER.
{ List *search_path = fetch_search_path(PG_GETARG_BOOL(0)); ListCell *l; Datum *names; int i; ArrayType *array; names = (Datum *) palloc(list_length(search_path) * sizeof(Datum)); i = 0; foreach(l, search_path) { char *nspname; nspname = get_namespace_name(lfirst_oid(l)); if (nspname) /* watch out for deleted namespace */ { names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname)); i++; } } list_free(search_path); array = construct_array(names, i, NAMEOID, NAMEDATALEN, /* sizeof(Name) */ false, /* Name is not by-val */ 'c'); /* alignment of Name */ PG_RETURN_POINTER(array); }
Datum current_user | ( | PG_FUNCTION_ARGS | ) |
Definition at line 264 of file name.c.
References CStringGetDatum, DirectFunctionCall1, GetUserId(), GetUserNameFromId(), namein(), and PG_RETURN_DATUM.
Definition at line 191 of file name.c.
References NAMEDATALEN, and NameStr.
{ if (!n1 || !n2) return -1; strncpy(NameStr(*n1), NameStr(*n2), NAMEDATALEN); return 0; }
Datum nameeq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 134 of file name.c.
References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.
{ Name arg1 = PG_GETARG_NAME(0); Name arg2 = PG_GETARG_NAME(1); PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) == 0); }
Datum namege | ( | PG_FUNCTION_ARGS | ) |
Definition at line 179 of file name.c.
References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.
{ Name arg1 = PG_GETARG_NAME(0); Name arg2 = PG_GETARG_NAME(1); PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) >= 0); }
Datum namegt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 170 of file name.c.
References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.
{ Name arg1 = PG_GETARG_NAME(0); Name arg2 = PG_GETARG_NAME(1); PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) > 0); }
Datum namein | ( | PG_FUNCTION_ARGS | ) |
Definition at line 46 of file name.c.
References NAMEDATALEN, NameStr, palloc0(), PG_GETARG_CSTRING, pg_mbcliplen(), and PG_RETURN_NAME.
Referenced by createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateRole(), CreateTableSpace(), CreateTrigger(), current_schema(), current_schemas(), current_user(), get_available_versions_for_extension(), getdatabaseencoding(), InsertExtensionTuple(), pg_available_extensions(), pg_client_encoding(), pg_convert_from(), pg_convert_to(), PG_encoding_to_char(), plpgsql_exec_trigger(), RenameRole(), session_user(), and string_to_datum().
{ char *s = PG_GETARG_CSTRING(0); Name result; int len; len = strlen(s); /* Truncate oversize input */ if (len >= NAMEDATALEN) len = pg_mbcliplen(s, len, NAMEDATALEN - 1); /* We use palloc0 here to ensure result is zero-padded */ result = (Name) palloc0(NAMEDATALEN); memcpy(NameStr(*result), s, len); PG_RETURN_NAME(result); }
Datum namele | ( | PG_FUNCTION_ARGS | ) |
Definition at line 161 of file name.c.
References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.
{ Name arg1 = PG_GETARG_NAME(0); Name arg2 = PG_GETARG_NAME(1); PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) <= 0); }
Datum namelt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 152 of file name.c.
References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.
{ Name arg1 = PG_GETARG_NAME(0); Name arg2 = PG_GETARG_NAME(1); PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) < 0); }
Datum namene | ( | PG_FUNCTION_ARGS | ) |
Definition at line 143 of file name.c.
References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.
{ Name arg1 = PG_GETARG_NAME(0); Name arg2 = PG_GETARG_NAME(1); PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) != 0); }
Datum nameout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 69 of file name.c.
References NameStr, PG_GETARG_NAME, PG_RETURN_CSTRING, and pstrdup().
Referenced by make_greater_string(), RelationBuildTriggers(), and set_timetravel().
{ Name s = PG_GETARG_NAME(0); PG_RETURN_CSTRING(pstrdup(NameStr(*s))); }
Datum namerecv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 80 of file name.c.
References buf, StringInfoData::cursor, ereport, errcode(), errdetail(), errmsg(), ERROR, StringInfoData::len, NAMEDATALEN, palloc0(), pfree(), PG_GETARG_POINTER, PG_RETURN_NAME, and pq_getmsgtext().
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); Name result; char *str; int nbytes; str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); if (nbytes >= NAMEDATALEN) ereport(ERROR, (errcode(ERRCODE_NAME_TOO_LONG), errmsg("identifier too long"), errdetail("Identifier must be less than %d characters.", NAMEDATALEN))); result = (NameData *) palloc0(NAMEDATALEN); memcpy(result, str, nbytes); pfree(str); PG_RETURN_NAME(result); }
Datum namesend | ( | PG_FUNCTION_ARGS | ) |
Definition at line 104 of file name.c.
References buf, NameStr, PG_GETARG_NAME, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendtext().
{ Name s = PG_GETARG_NAME(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendtext(&buf, NameStr(*s), strlen(NameStr(*s))); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
int namestrcmp | ( | Name | name, | |
const char * | str | |||
) |
Definition at line 248 of file name.c.
References NameStr.
Referenced by attnameAttNum(), CopyGetAttnums(), CreateTrigger(), get_timetravel(), GetAttributeByName(), set_timetravel(), and SPI_fnumber().
{ if (!name && !str) return 0; if (!name) return -1; /* NULL < anything */ if (!str) return 1; /* NULL < anything */ return strncmp(NameStr(*name), str, NAMEDATALEN); }
int namestrcpy | ( | Name | name, | |
const char * | str | |||
) |
Definition at line 217 of file name.c.
References NAMEDATALEN, NameStr, and StrNCpy.
Referenced by AddEnumLabel(), ATExecAddColumn(), build_dummy_tuple(), CollationCreate(), ConstructTupleDescriptor(), ConversionCreate(), create_proc_lang(), CreateConstraintEntry(), CreateOpFamily(), current_database(), DefineAttr(), DefineOpClass(), DefineSequence(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), EnumValuesCreate(), formrdesc(), InsertRule(), NamespaceCreate(), OperatorCreate(), OperatorShellMake(), ProcedureCreate(), RelationBuildLocalRelation(), RemoveAttributeById(), renameatt_internal(), RenameConstraintById(), RenameDatabase(), RenameRelationInternal(), RenameRewriteRule(), RenameSchema(), RenameTableSpace(), renametrig(), RenameTypeInternal(), TupleDescInitEntry(), TypeCreate(), TypeGetTupleDesc(), and TypeShellMake().
{ if (!name || !str) return -1; StrNCpy(NameStr(*name), str, NAMEDATALEN); return 0; }
Datum session_user | ( | PG_FUNCTION_ARGS | ) |
Definition at line 270 of file name.c.
References CStringGetDatum, DirectFunctionCall1, GetSessionUserId(), GetUserNameFromId(), namein(), and PG_RETURN_DATUM.