mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Decode pgsql LOB objects (bytea type) on fetch
This commit is contained in:
parent
64e8c3105c
commit
bf77a39349
3 changed files with 31 additions and 1 deletions
|
@ -167,7 +167,7 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen TSRMLS_DC)
|
static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC)
|
||||||
{
|
{
|
||||||
*quoted = emalloc(2*unquotedlen + 3);
|
*quoted = emalloc(2*unquotedlen + 3);
|
||||||
(*quoted)[0] = '\'';
|
(*quoted)[0] = '\'';
|
||||||
|
|
|
@ -39,6 +39,20 @@
|
||||||
#define OIDOID 26
|
#define OIDOID 26
|
||||||
|
|
||||||
|
|
||||||
|
static void _pdo_pgsql_free_lobs(pdo_stmt_t *stmt TSRMLS_DC)
|
||||||
|
{
|
||||||
|
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<stmt->column_count; i++) {
|
||||||
|
if (S->cols[i].lobval) {
|
||||||
|
free(S->cols[i].lobval);
|
||||||
|
S->cols[i].lobval = NULL;
|
||||||
|
S->cols[i].lobval = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int pgsql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
|
static int pgsql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
|
||||||
{
|
{
|
||||||
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
|
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
|
||||||
|
@ -63,6 +77,7 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(S->cols) {
|
if(S->cols) {
|
||||||
|
_pdo_pgsql_free_lobs(stmt TSRMLS_CC);
|
||||||
efree(S->cols);
|
efree(S->cols);
|
||||||
S->cols = NULL;
|
S->cols = NULL;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +141,9 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
|
||||||
{
|
{
|
||||||
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
|
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
|
||||||
|
|
||||||
|
/* free any allocated lob objects from the previos fetch operation */
|
||||||
|
_pdo_pgsql_free_lobs(stmt TSRMLS_CC);
|
||||||
|
|
||||||
if (S->cursor_name) {
|
if (S->cursor_name) {
|
||||||
char *ori_str = NULL;
|
char *ori_str = NULL;
|
||||||
char *q = NULL;
|
char *q = NULL;
|
||||||
|
@ -195,6 +213,10 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case BYTEAOID:
|
||||||
|
cols[colno].param_type = PDO_PARAM_LOB;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cols[colno].param_type = PDO_PARAM_STR;
|
cols[colno].param_type = PDO_PARAM_STR;
|
||||||
}
|
}
|
||||||
|
@ -232,6 +254,12 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned
|
||||||
*ptr = (char *) &(S->cols[colno].boolval);
|
*ptr = (char *) &(S->cols[colno].boolval);
|
||||||
*len = sizeof(zend_bool);
|
*len = sizeof(zend_bool);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PDO_PARAM_LOB:
|
||||||
|
S->cols[colno].lobval = PQunescapeBytea(*ptr, &(S->cols[colno].loblen));
|
||||||
|
*ptr = S->cols[colno].lobval;
|
||||||
|
*len = S->cols[colno].loblen;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ typedef struct {
|
||||||
Oid pgsql_type;
|
Oid pgsql_type;
|
||||||
long intval;
|
long intval;
|
||||||
zend_bool boolval;
|
zend_bool boolval;
|
||||||
|
char *lobval;
|
||||||
|
size_t loblen;
|
||||||
} pdo_pgsql_column;
|
} pdo_pgsql_column;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue