Re: libpq binary transfer of the numeric data type -

Поиск
Список
Период
Сортировка
От Brijesh Shrivastav
Тема Re: libpq binary transfer of the numeric data type -
Дата
Msg-id 491DC5F3D279CD4EB4B157DDD62237F404E27FEF@zipwire.esri.com
обсуждение исходный текст
Список pgsql-interfaces
This is the part I am not clear. It seems the numeric_recv function
read int16s as you descibed below but returns Numeric structure.
What do we get from PQgetvalue(), a Numeric object or a series of 
int16s followed by array of numeric digits as sent in numeric_send() 
routine?


numeric_recv(PG_FUNCTION_ARGS)
{StringInfo    buf = (StringInfo) PG_GETARG_POINTER(0);NumericVar    value;Numeric        res;int            len,
    i;
 
init_var(&value);
len = (uint16) pq_getmsgint(buf, sizeof(uint16));if (len < 0 || len > NUMERIC_MAX_PRECISION +
NUMERIC_MAX_RESULT_SCALE)    ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),             errmsg("invalid length in external
\"numeric\" value")));
alloc_var(&value, len);
value.weight = (int16) pq_getmsgint(buf, sizeof(int16));value.sign = (uint16) pq_getmsgint(buf, sizeof(uint16));if
(!(value.sign== NUMERIC_POS ||      value.sign == NUMERIC_NEG ||      value.sign == NUMERIC_NAN))    ereport(ERROR,
 
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),             errmsg("invalid sign in external
\"numeric\" value")));
value.dscale = (uint16) pq_getmsgint(buf, sizeof(uint16));for (i = 0; i < len; i++){    NumericDigit d =
pq_getmsgint(buf,sizeof(NumericDigit));
 
    if (d < 0 || d >= NBASE)        ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),                 errmsg("invalid digit in external
\"numeric\" value")));    value.digits[i] = d;}
res = make_result(&value);free_var(&value);
PG_RETURN_NUMERIC(res);
}

warm regards,
Brijesh
-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Monday, August 02, 2004 4:35 PM
To: Brijesh Shrivastav
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] libpq binary transfer of the numeric data type
- II 


Brijesh Shrivastav <Bshrivastav@esri.com> writes:
> Has anyone had success with fetching numeric data in binary format?
> I tried to follow Tom's advice below and try to reverse engineer from 
> recv/send function. It seemes the end structure that user will 
> get is of Numeric type (see struct below)

No, it isn't.  What you get is a series of int16 fields:
pq_sendint(&buf, x.ndigits, sizeof(int16));pq_sendint(&buf, x.weight, sizeof(int16));pq_sendint(&buf, x.sign,
sizeof(int16));pq_sendint(&buf,x.dscale, sizeof(int16));for (i = 0; i < x.ndigits; i++)    pq_sendint(&buf,
x.digits[i],sizeof(NumericDigit));
 

Note that the "digits" are base-10000 digits.
        regards, tom lane


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: libpq binary transfer of the numeric data type - II
Следующее
От: Alex Ott
Дата:
Сообщение: working with big text fields