Decode pgsql LOB objects (bytea type) on fetch

This commit is contained in:
Edin Kadribasic 2005-02-05 22:55:23 +00:00
parent 64e8c3105c
commit bf77a39349
3 changed files with 31 additions and 1 deletions

View file

@ -167,7 +167,7 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
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)[0] = '\'';

View file

@ -39,6 +39,20 @@
#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)
{
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) {
_pdo_pgsql_free_lobs(stmt TSRMLS_CC);
efree(S->cols);
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;
/* free any allocated lob objects from the previos fetch operation */
_pdo_pgsql_free_lobs(stmt TSRMLS_CC);
if (S->cursor_name) {
char *ori_str = NULL;
char *q = NULL;
@ -195,6 +213,10 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
}
break;
case BYTEAOID:
cols[colno].param_type = PDO_PARAM_LOB;
break;
default:
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);
*len = sizeof(zend_bool);
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;
}
}

View file

@ -46,6 +46,8 @@ typedef struct {
Oid pgsql_type;
long intval;
zend_bool boolval;
char *lobval;
size_t loblen;
} pdo_pgsql_column;
typedef struct {