mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Tweak some #if's to be more orthogonal.
(PHP pg_set_error_verbosity) New function to set PostgreSQL error verbosity (PHP pg_copy_from) Use non-deprecated API if it is available (PHP pg_copy_to) Use non-deprecated API if it is available
This commit is contained in:
parent
b30d8beebf
commit
e2b87e6230
8 changed files with 131 additions and 7 deletions
3
NEWS
3
NEWS
|
@ -8,6 +8,8 @@ PHP NEWS
|
|||
. ext/mnogosearch (Jani, Derick)
|
||||
. ext/w32api (Jani, Derick)
|
||||
. ext/yp (Jani, Derick)
|
||||
- Updated pg_copy_from and pg_copy_to to use non-deprecated COPY API if
|
||||
it exists (Christopher)
|
||||
- Changed stream_filter_(ap|pre)pend() to return resource. (Sara)
|
||||
- Changed mysqli_exception and sqlite_exception to use RuntimeException as base
|
||||
if SPL extension is present. (Georg, Marcus)
|
||||
|
@ -39,6 +41,7 @@ PHP NEWS
|
|||
. pg_send_execute() - async equivalent of pg_execute().
|
||||
. pg_result_error_field() - highly detailed error information,
|
||||
most importantly the SQLSTATE error code.
|
||||
. pg_set_error_verbosity() - set verbosity of errors
|
||||
- Added optional fifth parameter "count" to preg_replace_callback() and
|
||||
preg_replace() to count the number of replacements made. FR #32275. (Andrey)
|
||||
- Added optional third parameter "charlist" to str_word_count() which
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
PostgreSQL
|
||||
Jouni Ahto, Zeev Suraski, Yasuo Ohgaki
|
||||
Jouni Ahto, Zeev Suraski, Yasuo Ohgaki, Chris Kings-Lynne
|
||||
|
|
|
@ -83,6 +83,10 @@ if test "$PHP_PGSQL" != "no"; then
|
|||
AC_CHECK_LIB(pq, PQsendQueryParams,AC_DEFINE(HAVE_PQSENDQUERYPARAMS,1,[PostgreSQL 7.4 or later]))
|
||||
AC_CHECK_LIB(pq, PQsendPrepare,AC_DEFINE(HAVE_PQSENDPREPARE,1,[PostgreSQL 7.4 or later]))
|
||||
AC_CHECK_LIB(pq, PQsendQueryPrepared,AC_DEFINE(HAVE_PQSENDQUERYPREPARED,1,[PostgreSQL 7.4 or later]))
|
||||
AC_CHECK_LIB(pq, PQputCopyData,AC_DEFINE(HAVE_PQPUTCOPYDATA,1,[PostgreSQL 7.4 or later]))
|
||||
AC_CHECK_LIB(pq, PQputCopyEnd,AC_DEFINE(HAVE_PQPUTCOPYEND,1,[PostgreSQL 7.4 or later]))
|
||||
AC_CHECK_LIB(pq, PQgetCopyData,AC_DEFINE(HAVE_PQGETCOPYDATA,1,[PostgreSQL 7.4 or later]))
|
||||
AC_CHECK_LIB(pq, PQsetErrorVerbosity,AC_DEFINE(HAVE_PQSETERRORVERBOSITY,1,[PostgreSQL 7.4 or later]))
|
||||
AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibye]))
|
||||
LIBS=$old_LIBS
|
||||
LDFLAGS=$old_LDFLAGS
|
||||
|
|
|
@ -8,7 +8,7 @@ if (PHP_PGSQL != "no") {
|
|||
CHECK_HEADER_ADD_INCLUDE("libpq-fe.h", "CFLAGS_PGSQL", PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PGSQL)) {
|
||||
EXTENSION("pgsql", "pgsql.c");
|
||||
AC_DEFINE('HAVE_PGSQL', 1, 'Have PostgreSQL library');
|
||||
ADD_FLAG("CFLAGS_PGSQL", "/D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS /D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D HAVE_PQSENDQUERYPREPARED ");
|
||||
ADD_FLAG("CFLAGS_PGSQL", "/D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS /D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D HAVE_PQSENDQUERYPREPARED /D HAVE_PQPUTCOPYDATA /D HAVE_PQPUTCOPYEND /D HAVE_PQGETCOPYDATA /D HAVE_PQSETERRORVERBOSITY");
|
||||
} else {
|
||||
WARNING("pgsql not enabled; libraries and headers not found");
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
| Jouni Ahto <jouni.ahto@exdec.fi> |
|
||||
| Yasuo Ohgaki <yohgaki@php.net> |
|
||||
| Youichi Iwakiri <yiwakiri@st.rim.or.jp> (pg_copy_*) |
|
||||
| Chris Kings-Lynne <chriskl@php.net> (v3 protocol) |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
@ -177,6 +178,9 @@ function_entry pgsql_functions[] = {
|
|||
PHP_FE(pg_escape_bytea, NULL)
|
||||
PHP_FE(pg_unescape_bytea, NULL)
|
||||
#endif
|
||||
#if HAVE_PQSETERRORVERBOSITY
|
||||
PHP_FE(pg_set_error_verbosity, NULL)
|
||||
#endif
|
||||
#if HAVE_PQCLIENTENCODING
|
||||
PHP_FE(pg_client_encoding, NULL)
|
||||
PHP_FE(pg_set_client_encoding, NULL)
|
||||
|
@ -466,6 +470,12 @@ PHP_MINIT_FUNCTION(pgsql)
|
|||
REGISTER_LONG_CONSTANT("PGSQL_TRANSACTION_INTRANS", PQTRANS_INTRANS, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PGSQL_TRANSACTION_INERROR", PQTRANS_INERROR, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PGSQL_TRANSACTION_UNKNOWN", PQTRANS_UNKNOWN, CONST_CS | CONST_PERSISTENT);
|
||||
#endif
|
||||
#if HAVE_PQSETERRORVERBOSITY
|
||||
/* For pg_set_error_verbosity() */
|
||||
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_TERSE", PQERRORS_TERSE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_DEFAULT", PQERRORS_DEFAULT, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_VERBOSE", PQERRORS_VERBOSE, CONST_CS | CONST_PERSISTENT);
|
||||
#endif
|
||||
/* For lo_seek() */
|
||||
REGISTER_LONG_CONSTANT("PGSQL_SEEK_SET", SEEK_SET, CONST_CS | CONST_PERSISTENT);
|
||||
|
@ -2905,6 +2915,51 @@ PHP_FUNCTION(pg_lo_tell)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
#if HAVE_PQSETERRORVERBOSITY
|
||||
/* {{{ proto int pg_set_error_verbosity([resource connection,] int verbosity)
|
||||
Set error verbosity */
|
||||
PHP_FUNCTION(pg_set_error_verbosity)
|
||||
{
|
||||
zval **verbosity, **pgsql_link = NULL;
|
||||
long val;
|
||||
int id = -1;
|
||||
PGconn *pgsql;
|
||||
|
||||
switch(ZEND_NUM_ARGS()) {
|
||||
case 1:
|
||||
if (zend_get_parameters_ex(1, &verbosity)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
id = PGG(default_link);
|
||||
CHECK_DEFAULT_LINK(id);
|
||||
break;
|
||||
case 2:
|
||||
if (zend_get_parameters_ex(2, &pgsql_link, &verbosity)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
WRONG_PARAM_COUNT;
|
||||
break;
|
||||
}
|
||||
if (pgsql_link == NULL && id == -1) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink);
|
||||
|
||||
convert_to_long_ex(verbosity);
|
||||
val = Z_LVAL_PP(verbosity);
|
||||
if (val & (PQERRORS_TERSE|PQERRORS_DEFAULT|PQERRORS_VERBOSE)) {
|
||||
Z_LVAL_P(return_value) = PQsetErrorVerbosity(pgsql, val);
|
||||
Z_TYPE_P(return_value) = IS_LONG;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PQCLIENTENCODING
|
||||
/* {{{ proto int pg_set_client_encoding([resource connection,] string encoding)
|
||||
Set client encoding */
|
||||
|
@ -2987,8 +3042,9 @@ PHP_FUNCTION(pg_client_encoding)
|
|||
/* }}} */
|
||||
#endif
|
||||
|
||||
|
||||
#if !HAVE_PQGETCOPYDATA
|
||||
#define COPYBUFSIZ 8192
|
||||
#endif
|
||||
|
||||
/* {{{ proto bool pg_end_copy([resource connection])
|
||||
Sync with backend. Completes the Copy command */
|
||||
|
@ -3064,7 +3120,6 @@ PHP_FUNCTION(pg_put_line)
|
|||
|
||||
convert_to_string_ex(query);
|
||||
result = PQputline(pgsql, Z_STRVAL_PP(query));
|
||||
|
||||
if (result==EOF) {
|
||||
PHP_PQ_ERROR("Query failed: %s", pgsql);
|
||||
RETURN_FALSE;
|
||||
|
@ -3087,7 +3142,9 @@ PHP_FUNCTION(pg_copy_to)
|
|||
PGresult *pgsql_result;
|
||||
ExecStatusType status;
|
||||
int copydone = 0;
|
||||
#if !HAVE_PQGETCOPYDATA
|
||||
char copybuf[COPYBUFSIZ];
|
||||
#endif
|
||||
char *csv = (char *)NULL;
|
||||
int ret;
|
||||
int argc = ZEND_NUM_ARGS();
|
||||
|
@ -3128,6 +3185,26 @@ PHP_FUNCTION(pg_copy_to)
|
|||
if (pgsql_result) {
|
||||
PQclear(pgsql_result);
|
||||
array_init(return_value);
|
||||
#if HAVE_PQGETCOPYDATA
|
||||
while (!copydone)
|
||||
{
|
||||
ret = PQgetCopyData(pgsql, &csv, 0);
|
||||
switch (ret) {
|
||||
case -1:
|
||||
copydone = 1;
|
||||
break;
|
||||
case 0:
|
||||
case -2:
|
||||
PHP_PQ_ERROR("getline failed: %s", pgsql);
|
||||
RETURN_FALSE;
|
||||
break;
|
||||
default:
|
||||
add_next_index_string(return_value, csv, 1);
|
||||
PQfreemem(csv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
while (!copydone)
|
||||
{
|
||||
if ((ret = PQgetline(pgsql, copybuf, COPYBUFSIZ))) {
|
||||
|
@ -3168,6 +3245,7 @@ PHP_FUNCTION(pg_copy_to)
|
|||
PHP_PQ_ERROR("endcopy failed: %s", pgsql);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
#endif
|
||||
while ((pgsql_result = PQgetResult(pgsql))) {
|
||||
PQclear(pgsql_result);
|
||||
}
|
||||
|
@ -3238,13 +3316,33 @@ PHP_FUNCTION(pg_copy_from)
|
|||
if (pgsql_result) {
|
||||
PQclear(pgsql_result);
|
||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pg_rows), &pos);
|
||||
#if HAVE_PQPUTCOPYDATA
|
||||
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
|
||||
convert_to_string_ex(tmp);
|
||||
query = (char *)emalloc(Z_STRLEN_PP(tmp) +2);
|
||||
strcpy(query, Z_STRVAL_PP(tmp));
|
||||
if(*(query+Z_STRLEN_PP(tmp)-1) != '\n')
|
||||
strcat(query, "\n");
|
||||
if (PQputline(pgsql, query)) {
|
||||
if (PQputCopyData(pgsql, query, strlen(query)) != 1) {
|
||||
efree(query);
|
||||
PHP_PQ_ERROR("copy failed: %s", pgsql);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
efree(query);
|
||||
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos);
|
||||
}
|
||||
if (PQputCopyEnd(pgsql, NULL) != 1) {
|
||||
PHP_PQ_ERROR("putcopyend failed: %s", pgsql);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
#else
|
||||
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
|
||||
convert_to_string_ex(tmp);
|
||||
query = (char *)emalloc(Z_STRLEN_PP(tmp) +2);
|
||||
strcpy(query, Z_STRVAL_PP(tmp));
|
||||
if(*(query+Z_STRLEN_PP(tmp)-1) != '\n')
|
||||
strcat(query, "\n");
|
||||
if (PQputline(pgsql, query)==EOF) {
|
||||
efree(query);
|
||||
PHP_PQ_ERROR("copy failed: %s", pgsql);
|
||||
RETURN_FALSE;
|
||||
|
@ -3260,6 +3358,7 @@ PHP_FUNCTION(pg_copy_from)
|
|||
PHP_PQ_ERROR("endcopy failed: %s", pgsql);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
#endif
|
||||
while ((pgsql_result = PQgetResult(pgsql))) {
|
||||
PQclear(pgsql_result);
|
||||
}
|
||||
|
@ -3489,8 +3588,11 @@ PHP_FUNCTION(pg_result_error_field)
|
|||
}
|
||||
if (fieldcode & (PG_DIAG_SEVERITY|PG_DIAG_SQLSTATE|PG_DIAG_MESSAGE_PRIMARY|PG_DIAG_MESSAGE_DETAIL
|
||||
|PG_DIAG_MESSAGE_HINT|PG_DIAG_STATEMENT_POSITION
|
||||
#if defined(PG_DIAG_INTERNAL_POSITION) && defined(PG_DIAG_INTERNAL_QUERY)
|
||||
|PG_DIAG_INTERNAL_POSITION|PG_DIAG_INTERNAL_QUERY
|
||||
#if PG_DIAG_INTERNAL_POSITION
|
||||
|PG_DIAG_INTERNAL_POSITION
|
||||
#endif
|
||||
#if PG_DIAG_INTERNAL_QUERY
|
||||
|PG_DIAG_INTERNAL_QUERY
|
||||
#endif
|
||||
|PG_DIAG_CONTEXT|PG_DIAG_SOURCE_FILE|PG_DIAG_SOURCE_LINE
|
||||
|PG_DIAG_SOURCE_FUNCTION)) {
|
||||
|
|
|
@ -157,6 +157,9 @@ PHP_FUNCTION(pg_untrace);
|
|||
/* utility functions */
|
||||
PHP_FUNCTION(pg_client_encoding);
|
||||
PHP_FUNCTION(pg_set_client_encoding);
|
||||
#if HAVE_PQSETERRORVERBOSITY
|
||||
PHP_FUNCTION(pg_set_error_verbosity);
|
||||
#endif
|
||||
#if HAVE_PQESCAPE
|
||||
PHP_FUNCTION(pg_escape_string);
|
||||
PHP_FUNCTION(pg_escape_bytea);
|
||||
|
|
|
@ -7,6 +7,13 @@ PostgreSQL copy functions
|
|||
|
||||
include('config.inc');
|
||||
|
||||
$db = pg_connect($conn_str);
|
||||
|
||||
$rows = pg_copy_to($db, $table_name);
|
||||
|
||||
pg_query($db, "DELETE FROM $table_name");
|
||||
|
||||
pg_copy_from($db, $table_name, $rows);
|
||||
|
||||
echo "OK";
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@ $enc = pg_client_encoding($db);
|
|||
|
||||
pg_set_client_encoding($db, $enc);
|
||||
|
||||
if (function_exists('pg_set_error_verbosity')) {
|
||||
pg_set_error_verbosity(PGSQL_ERRORS_TERSE);
|
||||
pg_set_error_verbosity(PGSQL_ERRORS_DEFAULT);
|
||||
pg_set_error_verbosity(PGSQL_ERRORS_VERBOSE);
|
||||
}
|
||||
echo "OK";
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue