mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Support for native nulls, bools and ints
This commit is contained in:
parent
5264cfb853
commit
e58a8671a2
1 changed files with 54 additions and 4 deletions
|
@ -30,6 +30,12 @@
|
|||
#include "php_pdo_pgsql.h"
|
||||
#include "php_pdo_pgsql_int.h"
|
||||
|
||||
/* from postgresql/src/include/catalog/pg_type.h */
|
||||
#define BOOLOID 16
|
||||
#define INT8OID 20
|
||||
#define INT2OID 21
|
||||
#define INT4OID 23
|
||||
|
||||
|
||||
static int pgsql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
|
||||
{
|
||||
|
@ -167,7 +173,27 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
|
|||
cols[colno].namelen = strlen(cols[colno].name);
|
||||
cols[colno].maxlen = PQfsize(S->result, colno);
|
||||
cols[colno].precision = PQfmod(S->result, colno);
|
||||
|
||||
switch(PQftype(S->result, colno)) {
|
||||
|
||||
case BOOLOID:
|
||||
cols[colno].param_type = PDO_PARAM_BOOL;
|
||||
break;
|
||||
|
||||
case INT2OID:
|
||||
case INT4OID:
|
||||
cols[colno].param_type = PDO_PARAM_INT;
|
||||
break;
|
||||
|
||||
case INT8OID:
|
||||
if (sizeof(long)>=8) {
|
||||
cols[colno].param_type = PDO_PARAM_INT;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
cols[colno].param_type = PDO_PARAM_STR;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -175,15 +201,39 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
|
|||
static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len TSRMLS_DC)
|
||||
{
|
||||
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
|
||||
struct pdo_column_data *cols = stmt->columns;
|
||||
long intval;
|
||||
zend_bool boolval;
|
||||
|
||||
if (!S->result) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We have already increased count by 1 in pgsql_stmt_fetch() */
|
||||
if (PQgetisnull(S->result, S->current_row - 1, colno)) { /* Check if we got NULL */
|
||||
*ptr = NULL;
|
||||
*len = 0;
|
||||
} else {
|
||||
*ptr = PQgetvalue(S->result, S->current_row - 1, colno);
|
||||
*len = PQgetlength(S->result, S->current_row - 1, colno);
|
||||
|
||||
switch(cols[colno].param_type) {
|
||||
|
||||
case PDO_PARAM_INT:
|
||||
intval = atol(*ptr);
|
||||
printf ("Here %d %s\n", intval, *ptr);
|
||||
*ptr = &intval;
|
||||
*len = sizeof(long);
|
||||
break;
|
||||
|
||||
case PDO_PARAM_BOOL:
|
||||
boolval = **ptr == 't' ? 1: 0;
|
||||
*ptr = &boolval;
|
||||
*len = sizeof(zend_bool);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue