mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Add conversions for int2 and int4 to and from text.
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.8 1997/09/08 21:48:29 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.9 1997/10/25 05:19:22 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* I/O routines:
|
* I/O routines:
|
||||||
* int2in, int2out, int28in, int28out, int4in, int4out
|
* int2in, int2out, int28in, int28out, int4in, int4out
|
||||||
* Conversion routines:
|
* Conversion routines:
|
||||||
* itoi
|
* itoi, int2_text, int4_text
|
||||||
* Boolean operators:
|
* Boolean operators:
|
||||||
* inteq, intne, intlt, intle, intgt, intge
|
* inteq, intne, intlt, intle, intgt, intge
|
||||||
* Arithmetic operators:
|
* Arithmetic operators:
|
||||||
@ -29,6 +29,7 @@
|
|||||||
* fix me when we figure out what we want to do about ANSIfication...
|
* fix me when we figure out what we want to do about ANSIfication...
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "fmgr.h"
|
#include "fmgr.h"
|
||||||
@ -228,6 +229,88 @@ i4toi2(int32 arg1)
|
|||||||
return ((int16) arg1);
|
return ((int16) arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
text *
|
||||||
|
int2_text(int16 arg1)
|
||||||
|
{
|
||||||
|
text *result;
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = int2out(arg1);
|
||||||
|
len = (strlen(str) + VARHDRSZ);
|
||||||
|
|
||||||
|
result = PALLOC(len);
|
||||||
|
|
||||||
|
VARSIZE(result) = len;
|
||||||
|
memmove(VARDATA(result), str, (len - VARHDRSZ));
|
||||||
|
|
||||||
|
PFREE(str);
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
} /* int2_text() */
|
||||||
|
|
||||||
|
int16
|
||||||
|
text_int2(text *string)
|
||||||
|
{
|
||||||
|
int16 result;
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
len = (VARSIZE(string) - VARHDRSZ);
|
||||||
|
|
||||||
|
str = PALLOC(len+1);
|
||||||
|
memmove(str, VARDATA(string), len);
|
||||||
|
*(str+len) = '\0';
|
||||||
|
|
||||||
|
result = int2in(str);
|
||||||
|
PFREE(str);
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
} /* text_int2() */
|
||||||
|
|
||||||
|
text *
|
||||||
|
int4_text(int32 arg1)
|
||||||
|
{
|
||||||
|
text *result;
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = int4out(arg1);
|
||||||
|
len = (strlen(str) + VARHDRSZ);
|
||||||
|
|
||||||
|
result = PALLOC(len);
|
||||||
|
|
||||||
|
VARSIZE(result) = len;
|
||||||
|
memmove(VARDATA(result), str, (len - VARHDRSZ));
|
||||||
|
|
||||||
|
PFREE(str);
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
} /* int4_text() */
|
||||||
|
|
||||||
|
int32
|
||||||
|
text_int4(text *string)
|
||||||
|
{
|
||||||
|
int32 result;
|
||||||
|
|
||||||
|
int len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
len = (VARSIZE(string) - VARHDRSZ);
|
||||||
|
|
||||||
|
str = PALLOC(len+1);
|
||||||
|
memmove(str, VARDATA(string), len);
|
||||||
|
*(str+len) = '\0';
|
||||||
|
|
||||||
|
result = int4in(str);
|
||||||
|
PFREE(str);
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
} /* text_int4() */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* =========================
|
* =========================
|
||||||
|
Reference in New Issue
Block a user