mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Add conversion functions to and from the "name" data type.
This commit is contained in:
parent
e8cbf3a79c
commit
457b6efa43
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.31 1998/05/09 22:42:07 thomas Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.32 1998/05/29 13:33:24 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -201,8 +201,7 @@ int32
|
|||||||
bpchar_char(char *s)
|
bpchar_char(char *s)
|
||||||
{
|
{
|
||||||
return ((int32) *VARDATA(s));
|
return ((int32) *VARDATA(s));
|
||||||
} /* char_bpchar() */
|
} /* bpchar_char() */
|
||||||
|
|
||||||
|
|
||||||
/* char_bpchar()
|
/* char_bpchar()
|
||||||
* Convert char to bpchar(1).
|
* Convert char to bpchar(1).
|
||||||
@ -221,6 +220,70 @@ char_bpchar(int32 c)
|
|||||||
} /* char_bpchar() */
|
} /* char_bpchar() */
|
||||||
|
|
||||||
|
|
||||||
|
/* bpchar_name()
|
||||||
|
* Converts a bpchar() type to a NameData type.
|
||||||
|
*/
|
||||||
|
NameData *
|
||||||
|
bpchar_name(char *s)
|
||||||
|
{
|
||||||
|
NameData *result;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
len = VARSIZE(s) - VARHDRSZ;
|
||||||
|
if (len > NAMEDATALEN) len = NAMEDATALEN;
|
||||||
|
|
||||||
|
while (len > 0) {
|
||||||
|
if (*(VARDATA(s)+len-1) != ' ') break;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef STRINGDEBUG
|
||||||
|
printf("bpchar- convert string length %d (%d) ->%d\n",
|
||||||
|
VARSIZE(s)-VARHDRSZ, VARSIZE(s), len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
result = (NameData *) palloc(NAMEDATALEN);
|
||||||
|
StrNCpy(result->data, VARDATA(s), NAMEDATALEN);
|
||||||
|
|
||||||
|
/* now null pad to full length... */
|
||||||
|
while (len < NAMEDATALEN) {
|
||||||
|
*(result->data + len) = '\0';
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
} /* bpchar_name() */
|
||||||
|
|
||||||
|
/* name_bpchar()
|
||||||
|
* Converts a NameData type to a bpchar type.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
name_bpchar(NameData *s)
|
||||||
|
{
|
||||||
|
char *result;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
len = strlen(s->data);
|
||||||
|
|
||||||
|
#ifdef STRINGDEBUG
|
||||||
|
printf("bpchar- convert string length %d (%d) ->%d\n",
|
||||||
|
VARSIZE(s)-VARHDRSZ, VARSIZE(s), len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
result = (char *) palloc(VARHDRSZ + len);
|
||||||
|
strncpy(VARDATA(result), s->data, len);
|
||||||
|
VARSIZE(result) = len + VARHDRSZ;
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
} /* name_bpchar() */
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* varchar - varchar() *
|
* varchar - varchar() *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.34 1998/05/09 22:42:07 thomas Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.35 1998/05/29 13:33:58 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -759,3 +759,62 @@ byteaSetBit(text *v, int32 n, int32 newBit)
|
|||||||
|
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* text_name()
|
||||||
|
* Converts a text() type to a NameData type.
|
||||||
|
*/
|
||||||
|
NameData *
|
||||||
|
text_name(text *s)
|
||||||
|
{
|
||||||
|
NameData *result;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
len = VARSIZE(s) - VARHDRSZ;
|
||||||
|
if (len > NAMEDATALEN) len = NAMEDATALEN;
|
||||||
|
|
||||||
|
#ifdef STRINGDEBUG
|
||||||
|
printf("text- convert string length %d (%d) ->%d\n",
|
||||||
|
VARSIZE(s)-VARHDRSZ, VARSIZE(s), len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
result = palloc(NAMEDATALEN);
|
||||||
|
StrNCpy(result->data, VARDATA(s), NAMEDATALEN);
|
||||||
|
|
||||||
|
/* now null pad to full length... */
|
||||||
|
while (len < NAMEDATALEN) {
|
||||||
|
*(result->data + len) = '\0';
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
} /* text_name() */
|
||||||
|
|
||||||
|
/* name_text()
|
||||||
|
* Converts a NameData type to a text type.
|
||||||
|
*/
|
||||||
|
text *
|
||||||
|
name_text(NameData *s)
|
||||||
|
{
|
||||||
|
text *result;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
len = strlen(s->data);
|
||||||
|
|
||||||
|
#ifdef STRINGDEBUG
|
||||||
|
printf("text- convert string length %d (%d) ->%d\n",
|
||||||
|
VARSIZE(s)-VARHDRSZ, VARSIZE(s), len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
result = palloc(VARHDRSZ + len);
|
||||||
|
strncpy(VARDATA(result), s->data, len);
|
||||||
|
VARSIZE(result) = len + VARHDRSZ;
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
} /* name_text() */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user