summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2014-08-19 19:02:07 +0200
committerAnatol Belski <ab@php.net>2014-08-19 19:02:07 +0200
commit4ed156d4df70acf0aa81dc75fceea1837157665f (patch)
tree6af9c9886e46c297f75ab51c535056cf229071af /ext/pdo_pgsql
parent92269d25a37cbcfbb82364e9a58f232c880295a8 (diff)
downloadphp-git-4ed156d4df70acf0aa81dc75fceea1837157665f.tar.gz
ported from pdo - pgsql, odbc, mysql, firebirt, dblib
Diffstat (limited to 'ext/pdo_pgsql')
-rw-r--r--ext/pdo_pgsql/pdo_pgsql.c10
-rw-r--r--ext/pdo_pgsql/pgsql_driver.c32
-rw-r--r--ext/pdo_pgsql/pgsql_statement.c25
-rw-r--r--ext/pdo_pgsql/php_pdo_pgsql_int.h2
4 files changed, 37 insertions, 32 deletions
diff --git a/ext/pdo_pgsql/pdo_pgsql.c b/ext/pdo_pgsql/pdo_pgsql.c
index b3fd8ef879..fc7aa827ab 100644
--- a/ext/pdo_pgsql/pdo_pgsql.c
+++ b/ext/pdo_pgsql/pdo_pgsql.c
@@ -87,11 +87,11 @@ PHP_MINIT_FUNCTION(pdo_pgsql)
{
REGISTER_PDO_CLASS_CONST_INT("PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT", PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT);
REGISTER_PDO_CLASS_CONST_INT("PGSQL_ATTR_DISABLE_PREPARES", PDO_PGSQL_ATTR_DISABLE_PREPARES);
- REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_IDLE", (long)PGSQL_TRANSACTION_IDLE);
- REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_ACTIVE", (long)PGSQL_TRANSACTION_ACTIVE);
- REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_INTRANS", (long)PGSQL_TRANSACTION_INTRANS);
- REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_INERROR", (long)PGSQL_TRANSACTION_INERROR);
- REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_UNKNOWN", (long)PGSQL_TRANSACTION_UNKNOWN);
+ REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_IDLE", (php_int_t)PGSQL_TRANSACTION_IDLE);
+ REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_ACTIVE", (php_int_t)PGSQL_TRANSACTION_ACTIVE);
+ REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_INTRANS", (php_int_t)PGSQL_TRANSACTION_INTRANS);
+ REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_INERROR", (php_int_t)PGSQL_TRANSACTION_INERROR);
+ REGISTER_PDO_CLASS_CONST_INT("PGSQL_TRANSACTION_UNKNOWN", (php_int_t)PGSQL_TRANSACTION_UNKNOWN);
php_pdo_register_driver(&pdo_pgsql_driver);
return SUCCESS;
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index 06016887b9..809ee34f7c 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -151,8 +151,8 @@ static int pgsql_lob_flush(php_stream *stream TSRMLS_DC)
return 0;
}
-static int pgsql_lob_seek(php_stream *stream, off_t offset, int whence,
- off_t *newoffset TSRMLS_DC)
+static int pgsql_lob_seek(php_stream *stream, php_off_t offset, int whence,
+ php_off_t *newoffset TSRMLS_DC)
{
struct pdo_pgsql_lob_self *self = (struct pdo_pgsql_lob_self*)stream->abstract;
int pos = lo_lseek(self->conn, self->lfd, offset, whence);
@@ -214,7 +214,7 @@ static int pgsql_handle_closer(pdo_dbh_t *dbh TSRMLS_DC) /* {{{ */
}
/* }}} */
-static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC)
+static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, php_int_t sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC)
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
pdo_pgsql_stmt *S = ecalloc(1, sizeof(pdo_pgsql_stmt));
@@ -287,11 +287,11 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
return 1;
}
-static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC)
+static php_int_t pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, php_int_t sql_len TSRMLS_DC)
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
PGresult *res;
- long ret = 1;
+ php_int_t ret = 1;
ExecStatusType qs;
if (!(res = PQexec(H->server, sql))) {
@@ -306,7 +306,11 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
return -1;
}
H->pgoid = PQoidValue(res);
- ret = (qs == PGRES_COMMAND_OK) ? atol(PQcmdTuples(res)) : 0L;
+ if (qs == PGRES_COMMAND_OK) {
+ ZEND_ATOI(ret, PQcmdTuples(res));
+ } else {
+ ret = Z_I(0);
+ }
PQclear(res);
return ret;
@@ -350,7 +354,7 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned
if (H->pgoid == InvalidOid) {
return NULL;
}
- *len = spprintf(&id, 0, "%ld", (long) H->pgoid);
+ *len = spprintf(&id, 0, ZEND_INT_FMT, (php_int_t) H->pgoid);
} else {
PGresult *res;
ExecStatusType status;
@@ -373,7 +377,7 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned
return id;
}
-static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value TSRMLS_DC)
+static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, php_int_t attr, zval *return_value TSRMLS_DC)
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
@@ -906,7 +910,7 @@ static PHP_METHOD(PDO, pgsqlLOBCreate)
lfd = lo_creat(H->server, INV_READ|INV_WRITE);
if (lfd != InvalidOid) {
- zend_string *buf = strpprintf(0, "%lu", (long) lfd);
+ zend_string *buf = strpprintf(0, ZEND_UINT_FMT, (php_int_t) lfd);
RETURN_STR(buf);
}
@@ -1011,11 +1015,11 @@ static PHP_METHOD(PDO, pgsqlGetNotify)
{
pdo_dbh_t *dbh;
pdo_pgsql_db_handle *H;
- long result_type = PDO_FETCH_USE_DEFAULT;
- long ms_timeout = 0;
+ php_int_t result_type = PDO_FETCH_USE_DEFAULT;
+ php_int_t ms_timeout = 0;
PGnotify *pgsql_notify;
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll",
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ii",
&result_type, &ms_timeout)) {
RETURN_FALSE;
}
@@ -1107,7 +1111,7 @@ static const zend_function_entry *pdo_pgsql_get_driver_methods(pdo_dbh_t *dbh, i
}
}
-static int pdo_pgsql_set_attr(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC)
+static int pdo_pgsql_set_attr(pdo_dbh_t *dbh, php_int_t attr, zval *val TSRMLS_DC)
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
@@ -1154,7 +1158,7 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
int ret = 0;
char *conn_str, *p, *e;
char *tmp_pass;
- long connect_timeout = 30;
+ php_int_t connect_timeout = 30;
H = pecalloc(1, sizeof(pdo_pgsql_db_handle), dbh->is_persistent);
dbh->driver_data = H;
diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c
index b464211f90..eb13548558 100644
--- a/ext/pdo_pgsql/pgsql_statement.c
+++ b/ext/pdo_pgsql/pgsql_statement.c
@@ -230,10 +230,10 @@ stmt_retry:
}
if (status == PGRES_COMMAND_OK) {
- stmt->row_count = (long)atoi(PQcmdTuples(S->result));
+ ZEND_ATOI(stmt->row_count, PQcmdTuples(S->result));
H->pgoid = PQoidValue(S->result);
} else {
- stmt->row_count = (long)PQntuples(S->result);
+ stmt->row_count = (php_int_t)PQntuples(S->result);
}
return 1;
@@ -256,14 +256,15 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
/* decode name from $1, $2 into 0, 1 etc. */
if (param->name) {
if (param->name->val[0] == '$') {
- param->paramno = atoi(param->name->val + 1);
+ ZEND_ATOI(param->paramno, param->name->val + 1);
} else {
/* resolve parameter name to rewritten name */
char *namevar;
if (stmt->bound_param_map && (namevar = zend_hash_find_ptr(stmt->bound_param_map,
param->name)) != NULL) {
- param->paramno = atoi(namevar + 1) - 1;
+ ZEND_ATOI(param->paramno, namevar + 1);
+ param->paramno--;
} else {
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", param->name->val TSRMLS_CC);
return 0;
@@ -390,7 +391,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
}
static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
- enum pdo_fetch_orientation ori, long offset TSRMLS_DC)
+ enum pdo_fetch_orientation ori, php_int_t offset TSRMLS_DC)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
@@ -404,8 +405,8 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
case PDO_FETCH_ORI_PRIOR: spprintf(&ori_str, 0, "BACKWARD"); break;
case PDO_FETCH_ORI_FIRST: spprintf(&ori_str, 0, "FIRST"); break;
case PDO_FETCH_ORI_LAST: spprintf(&ori_str, 0, "LAST"); break;
- case PDO_FETCH_ORI_ABS: spprintf(&ori_str, 0, "ABSOLUTE %ld", offset); break;
- case PDO_FETCH_ORI_REL: spprintf(&ori_str, 0, "RELATIVE %ld", offset); break;
+ case PDO_FETCH_ORI_ABS: spprintf(&ori_str, 0, "ABSOLUTE %pd", offset); break;
+ case PDO_FETCH_ORI_REL: spprintf(&ori_str, 0, "RELATIVE %pd", offset); break;
default:
return 0;
}
@@ -479,7 +480,7 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
break;
case INT8OID:
- if (sizeof(long)>=8) {
+ if (sizeof(php_int_t)>=8) {
cols[colno].param_type = PDO_PARAM_INT;
} else {
cols[colno].param_type = PDO_PARAM_STR;
@@ -497,7 +498,7 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
return 1;
}
-static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len, int *caller_frees TSRMLS_DC)
+static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, php_uint_t *len, int *caller_frees TSRMLS_DC)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
struct pdo_column_data *cols = stmt->columns;
@@ -518,9 +519,9 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned
switch (cols[colno].param_type) {
case PDO_PARAM_INT:
- S->cols[colno].intval = atol(*ptr);
+ ZEND_ATOI(S->cols[colno].intval, *ptr);
*ptr = (char *) &(S->cols[colno].intval);
- *len = sizeof(long);
+ *len = sizeof(php_int_t);
break;
case PDO_PARAM_BOOL:
@@ -576,7 +577,7 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned
return 1;
}
-static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, long colno, zval *return_value TSRMLS_DC)
+static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, php_int_t colno, zval *return_value TSRMLS_DC)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
PGresult *res;
diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h
index 4d0652049e..0462daff1f 100644
--- a/ext/pdo_pgsql/php_pdo_pgsql_int.h
+++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h
@@ -54,7 +54,7 @@ typedef struct {
typedef struct {
char *def;
Oid pgsql_type;
- long intval;
+ php_int_t intval;
zend_bool boolval;
} pdo_pgsql_column;