Pg: Add perl2bin() and bin2perl() conversion methods
This commit is contained in:
parent
af9340f908
commit
beeefcf337
4 changed files with 69 additions and 2 deletions
27
c/pgconn.c
27
c/pgconn.c
|
|
@ -626,3 +626,30 @@ static void fupg_tio_free(fupg_tio *tio) {
|
|||
safefree(tio->record.tio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static SV *fupg_perl2bin(pTHX_ fupg_conn *conn, Oid oid, SV *sv) {
|
||||
int refresh_done = 0;
|
||||
fupg_tio tio;
|
||||
fustr buf;
|
||||
memset(&tio, 0, sizeof(tio));
|
||||
fupg_tio_setup(aTHX_ conn, &tio, FUPGT_SEND, oid, &refresh_done);
|
||||
fustr_init(&buf, sv_newmortal(), SIZE_MAX);
|
||||
tio.send(aTHX_ &tio, sv, &buf); /* XXX: Leaks 'tio' on error */
|
||||
fupg_tio_free(&tio);
|
||||
return fustr_done(&buf);
|
||||
}
|
||||
|
||||
static SV *fupg_bin2perl(pTHX_ fupg_conn *conn, Oid oid, SV *sv) {
|
||||
int refresh_done = 0;
|
||||
fupg_tio tio;
|
||||
STRLEN len;
|
||||
const char *buf = SvPVbyte(sv, len);
|
||||
memset(&tio, 0, sizeof(tio));
|
||||
fupg_tio_setup(aTHX_ conn, &tio, FUPGT_RECV, oid, &refresh_done);
|
||||
SV *r = tio.recv(aTHX_ &tio, buf, len); /* XXX: Leaks 'tio' on error */
|
||||
fupg_tio_free(&tio);
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue