plperl_sql_ascii.patch
text/x-patch
Filename: plperl_sql_ascii.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| src/pl/plperl/plperl_helpers.h | 24 | 8 |
*** a/src/pl/plperl/plperl_helpers.h
--- b/src/pl/plperl/plperl_helpers.h
***************
*** 5,23 ****
* convert from utf8 to database encoding
*/
static inline char *
! utf_u2e(const char *utf8_str, size_t len)
{
! int enc = GetDatabaseEncoding();
!
! char *ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, enc);
/*
! * when we are a PG_UTF8 or SQL_ASCII database
! * pg_do_encoding_conversion() will not do any conversion or
! * verification. we need to do it manually instead.
*/
if (enc == PG_UTF8 || enc == PG_SQL_ASCII)
! pg_verify_mbstr_len(PG_UTF8, utf8_str, len, false);
if (ret == utf8_str)
ret = pstrdup(ret);
--- 5,24 ----
* convert from utf8 to database encoding
*/
static inline char *
! utf_u2e(char *utf8_str, size_t len)
{
! int enc = GetDatabaseEncoding();
! char *ret = utf8_str;
/*
! * when we are a PG_UTF8 or SQL_ASCII database pg_do_encoding_conversion()
! * will not do any conversion or verification. we need to do it manually
! * instead.
*/
if (enc == PG_UTF8 || enc == PG_SQL_ASCII)
! pg_verify_mbstr_len(enc, utf8_str, len, false);
! else
! ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, enc);
if (ret == utf8_str)
ret = pstrdup(ret);
***************
*** 66,72 **** sv2cstr(SV *sv)
* we are done */
SvREFCNT_inc(sv);
! val = SvPVutf8(sv, len);
/*
* we use perl's length in the event we had an embedded null byte to ensure
--- 67,80 ----
* we are done */
SvREFCNT_inc(sv);
! /*
! * when SQL_ASCII just treat it as byte soup, that is fetch the string out
! * however it is currently stored by perl
! */
! if (GetDatabaseEncoding() == PG_SQL_ASCII)
! val = SvPV(sv, len);
! else
! val = SvPVutf8(sv, len);
/*
* we use perl's length in the event we had an embedded null byte to ensure
***************
*** 89,99 **** static inline SV *
cstr2sv(const char *str)
{
SV *sv;
! char *utf8_str = utf_e2u(str);
sv = newSVpv(utf8_str, 0);
SvUTF8_on(sv);
-
pfree(utf8_str);
return sv;
--- 97,112 ----
cstr2sv(const char *str)
{
SV *sv;
! char *utf8_str;
!
! /* no conversion when SQL_ASCII */
! if (GetDatabaseEncoding() == PG_SQL_ASCII)
! return newSVpv(str, 0);
!
! utf8_str = utf_e2u(str);
sv = newSVpv(utf8_str, 0);
SvUTF8_on(sv);
pfree(utf8_str);
return sv;