version 1.1.1.4, 2013/10/14 08:02:28
|
version 1.1.1.5, 2014/06/15 20:03:53
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2013 The PHP Group | | | Copyright (c) 1997-2014 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 15
|
Line 15
|
| Authors: Zeev Suraski <zeev@zend.com> | |
| Authors: Zeev Suraski <zeev@zend.com> | |
| Jouni Ahto <jouni.ahto@exdec.fi> | |
| Jouni Ahto <jouni.ahto@exdec.fi> | |
| Yasuo Ohgaki <yohgaki@php.net> | |
| Yasuo Ohgaki <yohgaki@php.net> | |
| Youichi Iwakiri <yiwakiri@st.rim.or.jp> (pg_copy_*) | | | Youichi Iwakiri <yiwakiri@st.rim.or.jp> (pg_copy_*) | |
| Chris Kings-Lynne <chriskl@php.net> (v3 protocol) | | | Chris Kings-Lynne <chriskl@php.net> (v3 protocol) | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
*/ |
*/ |
|
|
Line 37
|
Line 37
|
#include "ext/standard/php_standard.h" |
#include "ext/standard/php_standard.h" |
#include "ext/standard/php_smart_str.h" |
#include "ext/standard/php_smart_str.h" |
#include "ext/ereg/php_regex.h" |
#include "ext/ereg/php_regex.h" |
|
#ifdef PHP_WIN32 |
|
# include "win32/time.h" |
|
#endif |
|
|
#undef PACKAGE_BUGREPORT |
#undef PACKAGE_BUGREPORT |
#undef PACKAGE_NAME |
#undef PACKAGE_NAME |
Line 743 ZEND_GET_MODULE(pgsql)
|
Line 746 ZEND_GET_MODULE(pgsql)
|
|
|
static int le_link, le_plink, le_result, le_lofp, le_string; |
static int le_link, le_plink, le_result, le_lofp, le_string; |
|
|
|
/* Compatibility definitions */ |
|
|
|
#ifndef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT |
|
#define pg_encoding_to_char(x) "SQL_ASCII" |
|
#endif |
|
|
|
#if !HAVE_PQESCAPE_CONN |
|
#define PQescapeStringConn(conn, to, form, len, error) PQescapeString(to, from, len) |
|
#endif |
|
|
|
#if HAVE_PQESCAPELITERAL |
|
#define PGSQLescapeLiteral(conn, str, len) PQescapeLiteral(conn, str, len) |
|
#define PGSQLescapeIdentifier(conn, str, len) PQescapeIdentifier(conn, str, len) |
|
#define PGSQLfree(a) PQfreemem(a) |
|
#else |
|
#define PGSQLescapeLiteral(conn, str, len) php_pgsql_PQescapeInternal(conn, str, len, 1, 0) |
|
#define PGSQLescapeLiteral2(conn, str, len) php_pgsql_PQescapeInternal(conn, str, len, 1, 1) |
|
#define PGSQLescapeIdentifier(conn, str, len) php_pgsql_PQescapeInternal(conn, str, len, 0, 0) |
|
#define PGSQLfree(a) efree(a) |
|
|
|
/* emulate libpq's PQescapeInternal() 9.0 or later */ |
|
static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t len, int escape_literal, int safe) { |
|
char *result, *rp, *s; |
|
size_t tmp_len; |
|
|
|
if (!conn) { |
|
return NULL; |
|
} |
|
|
|
/* allocate enough memory */ |
|
rp = result = (char *)safe_emalloc(len, 2, 5); /* leading " E" needs extra 2 bytes + quote_chars on both end for 2 bytes + NULL */ |
|
|
|
if (escape_literal) { |
|
size_t new_len; |
|
|
|
if (safe) { |
|
char *tmp = (char *)safe_emalloc(len, 2, 1); |
|
*rp++ = '\''; |
|
/* PQescapeString does not escape \, but it handles multibyte chars safely. |
|
This escape is incompatible with PQescapeLiteral. */ |
|
new_len = PQescapeStringConn(conn, tmp, str, len, NULL); |
|
strncpy(rp, tmp, new_len); |
|
efree(tmp); |
|
rp += new_len; |
|
} else { |
|
char *encoding; |
|
/* This is compatible with PQescapeLiteral, but it cannot handle multbyte chars |
|
such as SJIS, BIG5. Raise warning and return NULL by checking |
|
client_encoding. */ |
|
encoding = (char *) pg_encoding_to_char(PQclientEncoding(conn)); |
|
if (!strncmp(encoding, "SJIS", sizeof("SJIS")-1) || |
|
!strncmp(encoding, "SHIFT_JIS_2004", sizeof("SHIFT_JIS_2004")-1) || |
|
!strncmp(encoding, "BIG5", sizeof("BIG5")-1) || |
|
!strncmp(encoding, "GB18030", sizeof("GB18030")-1) || |
|
!strncmp(encoding, "GBK", sizeof("GBK")-1) || |
|
!strncmp(encoding, "JOHAB", sizeof("JOHAB")-1) || |
|
!strncmp(encoding, "UHC", sizeof("UHC")-1) ) { |
|
TSRMLS_FETCH(); |
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsafe encoding is used. Do not use '%s' encoding or use PostgreSQL 9.0 or later libpq.", encoding); |
|
} |
|
/* check backslashes */ |
|
tmp_len = strspn(str, "\\"); |
|
if (tmp_len != len) { |
|
/* add " E" for escaping slashes */ |
|
*rp++ = ' '; |
|
*rp++ = 'E'; |
|
} |
|
*rp++ = '\''; |
|
for (s = (char *)str; s - str < len; ++s) { |
|
if (*s == '\'' || *s == '\\') { |
|
*rp++ = *s; |
|
*rp++ = *s; |
|
} else { |
|
*rp++ = *s; |
|
} |
|
} |
|
} |
|
*rp++ = '\''; |
|
} else { |
|
/* Identifier escape. */ |
|
*rp++ = '"'; |
|
for (s = (char *)str; s - str < len; ++s) { |
|
if (*s == '"') { |
|
*rp++ = '"'; |
|
*rp++ = '"'; |
|
} else { |
|
*rp++ = *s; |
|
} |
|
} |
|
*rp++ = '"'; |
|
} |
|
*rp = '\0'; |
|
|
|
return result; |
|
} |
|
#endif |
|
|
|
|
/* {{{ _php_pgsql_trim_message */ |
/* {{{ _php_pgsql_trim_message */ |
static char * _php_pgsql_trim_message(const char *message, int *len) |
static char * _php_pgsql_trim_message(const char *message, int *len) |
{ |
{ |
Line 771 static inline char * _php_pgsql_trim_result(PGconn * p
|
Line 873 static inline char * _php_pgsql_trim_result(PGconn * p
|
|
|
#define PQErrorMessageTrim(pgsql, buf) _php_pgsql_trim_result(pgsql, buf) |
#define PQErrorMessageTrim(pgsql, buf) _php_pgsql_trim_result(pgsql, buf) |
|
|
#define PHP_PQ_ERROR(text, pgsql) { \ | #define PHP_PQ_ERROR(text, pgsql) { \ |
char *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL); \ | char *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL); \ |
php_error_docref(NULL TSRMLS_CC, E_WARNING, text, msgbuf); \ | php_error_docref(NULL TSRMLS_CC, E_WARNING, text, msgbuf); \ |
efree(msgbuf); \ | efree(msgbuf); \ |
} \ |
} \ |
|
|
/* {{{ php_pgsql_set_default_link |
/* {{{ php_pgsql_set_default_link |
*/ |
*/ |
static void php_pgsql_set_default_link(int id TSRMLS_DC) |
static void php_pgsql_set_default_link(int id TSRMLS_DC) |
{ | { |
zend_list_addref(id); |
zend_list_addref(id); |
|
|
if (PGG(default_link) != -1) { |
if (PGG(default_link) != -1) { |
Line 848 static void _php_pgsql_notice_ptr_dtor(void **ptr)
|
Line 950 static void _php_pgsql_notice_ptr_dtor(void **ptr)
|
{ |
{ |
php_pgsql_notice *notice = (php_pgsql_notice *)*ptr; |
php_pgsql_notice *notice = (php_pgsql_notice *)*ptr; |
if (notice) { |
if (notice) { |
efree(notice->message); | efree(notice->message); |
efree(notice); | efree(notice); |
notice = NULL; | notice = NULL; |
} | } |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 941 static int _php_pgsql_detect_identifier_escape(const c
|
Line 1043 static int _php_pgsql_detect_identifier_escape(const c
|
return SUCCESS; |
return SUCCESS; |
} |
} |
|
|
#if !HAVE_PQESCAPELITERAL |
|
/* {{{ _php_pgsql_escape_identifier |
|
* Since PQescapeIdentifier() is unavailable (PostgreSQL 9.0 <), idenfifers |
|
* should be escaped by pgsql module. |
|
* Note: this function does not care for encoding. Therefore users should not |
|
* use this with SJIS/BIG5 etc. (i.e. Encoding base injection may possible with |
|
* before PostgreSQL 9.0) |
|
*/ |
|
static char *_php_pgsql_escape_identifier(const char *field, size_t field_len) |
|
{ |
|
ulong field_escaped_len = field_len*2 + 3; |
|
ulong i, j = 0; |
|
char *field_escaped; |
|
|
|
field_escaped = (char *)malloc(field_escaped_len); |
|
field_escaped[j++] = '"'; |
|
for (i = 0; i < field_len; i++) { |
|
if (field[i] == '"') { |
|
field_escaped[j++] = '"'; |
|
field_escaped[j++] = '"'; |
|
} else { |
|
field_escaped[j++] = field[i]; |
|
} |
|
} |
|
field_escaped[j++] = '"'; |
|
field_escaped[j] = '\0'; |
|
return field_escaped; |
|
} |
|
/* }}} */ |
|
#endif |
|
|
|
/* {{{ _php_pgsql_strndup, no strndup should be used */ |
|
static char *_php_pgsql_strndup(const char *s, size_t len) |
|
{ |
|
char *new; |
|
|
|
if (NULL == s) { |
|
return (char *)NULL; |
|
} |
|
|
|
new = (char *) malloc(len + 1); |
|
|
|
if (NULL == new) { |
|
return (char *)NULL; |
|
} |
|
|
|
new[len] = '\0'; |
|
|
|
return memmove(new, s, len); |
|
} |
|
/* }}} */ |
|
|
|
/* {{{ PHP_INI |
/* {{{ PHP_INI |
*/ |
*/ |
PHP_INI_BEGIN() |
PHP_INI_BEGIN() |
Line 1020 static PHP_GINIT_FUNCTION(pgsql)
|
Line 1072 static PHP_GINIT_FUNCTION(pgsql)
|
PHP_MINIT_FUNCTION(pgsql) |
PHP_MINIT_FUNCTION(pgsql) |
{ |
{ |
REGISTER_INI_ENTRIES(); |
REGISTER_INI_ENTRIES(); |
| |
le_link = zend_register_list_destructors_ex(_close_pgsql_link, NULL, "pgsql link", module_number); |
le_link = zend_register_list_destructors_ex(_close_pgsql_link, NULL, "pgsql link", module_number); |
le_plink = zend_register_list_destructors_ex(NULL, _close_pgsql_plink, "pgsql link persistent", module_number); |
le_plink = zend_register_list_destructors_ex(NULL, _close_pgsql_plink, "pgsql link persistent", module_number); |
le_result = zend_register_list_destructors_ex(_free_result, NULL, "pgsql result", module_number); |
le_result = zend_register_list_destructors_ex(_free_result, NULL, "pgsql result", module_number); |
Line 1156 PHP_MINFO_FUNCTION(pgsql)
|
Line 1208 PHP_MINFO_FUNCTION(pgsql)
|
#else |
#else |
php_info_print_table_row(2, "SSL support", "disabled"); |
php_info_print_table_row(2, "SSL support", "disabled"); |
#endif |
#endif |
#endif /* HAVE_PG_CONFIG_H */ | #endif /* HAVE_PG_CONFIG_H */ |
snprintf(buf, sizeof(buf), "%ld", PGG(num_persistent)); |
snprintf(buf, sizeof(buf), "%ld", PGG(num_persistent)); |
php_info_print_table_row(2, "Active Persistent Links", buf); |
php_info_print_table_row(2, "Active Persistent Links", buf); |
snprintf(buf, sizeof(buf), "%ld", PGG(num_links)); |
snprintf(buf, sizeof(buf), "%ld", PGG(num_links)); |
Line 1224 static void php_pgsql_do_connect(INTERNAL_FUNCTION_PAR
|
Line 1276 static void php_pgsql_do_connect(INTERNAL_FUNCTION_PAR
|
break; |
break; |
} |
} |
} |
} |
| |
if (persistent && PGG(allow_persistent)) { |
if (persistent && PGG(allow_persistent)) { |
zend_rsrc_list_entry *le; |
zend_rsrc_list_entry *le; |
|
|
Line 1307 static void php_pgsql_do_connect(INTERNAL_FUNCTION_PAR
|
Line 1359 static void php_pgsql_do_connect(INTERNAL_FUNCTION_PAR
|
ZEND_REGISTER_RESOURCE(return_value, pgsql, le_plink); |
ZEND_REGISTER_RESOURCE(return_value, pgsql, le_plink); |
} else { /* Non persistent connection */ |
} else { /* Non persistent connection */ |
zend_rsrc_list_entry *index_ptr,new_index_ptr; |
zend_rsrc_list_entry *index_ptr,new_index_ptr; |
| |
/* first we check the hash for the hashed_details key. if it exists, |
/* first we check the hash for the hashed_details key. if it exists, |
* it should point us to the right offset where the actual pgsql link sits. |
* it should point us to the right offset where the actual pgsql link sits. |
* if it doesn't, open a new pgsql link, add it to the resource list, |
* if it doesn't, open a new pgsql link, add it to the resource list, |
Line 1371 static void php_pgsql_do_connect(INTERNAL_FUNCTION_PAR
|
Line 1423 static void php_pgsql_do_connect(INTERNAL_FUNCTION_PAR
|
cleanup: |
cleanup: |
smart_str_free(&str); |
smart_str_free(&str); |
return; |
return; |
| |
err: |
err: |
smart_str_free(&str); |
smart_str_free(&str); |
RETURN_FALSE; |
RETURN_FALSE; |
Line 1415 PHP_FUNCTION(pg_close)
|
Line 1467 PHP_FUNCTION(pg_close)
|
zval *pgsql_link = NULL; |
zval *pgsql_link = NULL; |
int id = -1, argc = ZEND_NUM_ARGS(); |
int id = -1, argc = ZEND_NUM_ARGS(); |
PGconn *pgsql; |
PGconn *pgsql; |
| |
if (zend_parse_parameters(argc TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { |
if (zend_parse_parameters(argc TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { |
return; |
return; |
} |
} |
| |
if (argc == 0) { |
if (argc == 0) { |
id = PGG(default_link); |
id = PGG(default_link); |
CHECK_DEFAULT_LINK(id); |
CHECK_DEFAULT_LINK(id); |
Line 1427 PHP_FUNCTION(pg_close)
|
Line 1479 PHP_FUNCTION(pg_close)
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 1435 PHP_FUNCTION(pg_close)
|
Line 1487 PHP_FUNCTION(pg_close)
|
zend_list_delete(Z_RESVAL_P(pgsql_link)); |
zend_list_delete(Z_RESVAL_P(pgsql_link)); |
} |
} |
|
|
if (id!=-1 | if (id!=-1 |
|| (pgsql_link && Z_RESVAL_P(pgsql_link)==PGG(default_link))) { |
|| (pgsql_link && Z_RESVAL_P(pgsql_link)==PGG(default_link))) { |
zend_list_delete(PGG(default_link)); |
zend_list_delete(PGG(default_link)); |
PGG(default_link) = -1; |
PGG(default_link) = -1; |
Line 1454 PHP_FUNCTION(pg_close)
|
Line 1506 PHP_FUNCTION(pg_close)
|
#define PHP_PG_HOST 6 |
#define PHP_PG_HOST 6 |
#define PHP_PG_VERSION 7 |
#define PHP_PG_VERSION 7 |
|
|
|
|
/* {{{ php_pgsql_get_link_info |
/* {{{ php_pgsql_get_link_info |
*/ |
*/ |
static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) |
static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) |
Line 1474 static void php_pgsql_get_link_info(INTERNAL_FUNCTION_
|
Line 1527 static void php_pgsql_get_link_info(INTERNAL_FUNCTION_
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 1600 PHP_FUNCTION(pg_parameter_status)
|
Line 1653 PHP_FUNCTION(pg_parameter_status)
|
} |
} |
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 1631 PHP_FUNCTION(pg_ping)
|
Line 1684 PHP_FUNCTION(pg_ping)
|
} |
} |
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 1706 PHP_FUNCTION(pg_query)
|
Line 1759 PHP_FUNCTION(pg_query)
|
} else { |
} else { |
status = (ExecStatusType) PQstatus(pgsql); |
status = (ExecStatusType) PQstatus(pgsql); |
} |
} |
| |
switch (status) { |
switch (status) { |
case PGRES_EMPTY_QUERY: |
case PGRES_EMPTY_QUERY: |
case PGRES_BAD_RESPONSE: |
case PGRES_BAD_RESPONSE: |
Line 1802 PHP_FUNCTION(pg_query_params)
|
Line 1855 PHP_FUNCTION(pg_query_params)
|
if (num_params > 0) { |
if (num_params > 0) { |
int i = 0; |
int i = 0; |
params = (char **)safe_emalloc(sizeof(char *), num_params, 0); |
params = (char **)safe_emalloc(sizeof(char *), num_params, 0); |
| |
for(i = 0; i < num_params; i++) { |
for(i = 0; i < num_params; i++) { |
if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { |
if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); |
Line 1899 PHP_FUNCTION(pg_prepare)
|
Line 1952 PHP_FUNCTION(pg_prepare)
|
return; |
return; |
} |
} |
} |
} |
| |
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 1929 PHP_FUNCTION(pg_prepare)
|
Line 1982 PHP_FUNCTION(pg_prepare)
|
} else { |
} else { |
status = (ExecStatusType) PQstatus(pgsql); |
status = (ExecStatusType) PQstatus(pgsql); |
} |
} |
| |
switch (status) { |
switch (status) { |
case PGRES_EMPTY_QUERY: |
case PGRES_EMPTY_QUERY: |
case PGRES_BAD_RESPONSE: |
case PGRES_BAD_RESPONSE: |
Line 2009 PHP_FUNCTION(pg_execute)
|
Line 2062 PHP_FUNCTION(pg_execute)
|
if (num_params > 0) { |
if (num_params > 0) { |
int i = 0; |
int i = 0; |
params = (char **)safe_emalloc(sizeof(char *), num_params, 0); |
params = (char **)safe_emalloc(sizeof(char *), num_params, 0); |
| |
for(i = 0; i < num_params; i++) { |
for(i = 0; i < num_params; i++) { |
if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { |
if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); |
Line 2051 PHP_FUNCTION(pg_execute)
|
Line 2104 PHP_FUNCTION(pg_execute)
|
} else { |
} else { |
status = (ExecStatusType) PQstatus(pgsql); |
status = (ExecStatusType) PQstatus(pgsql); |
} |
} |
| |
_php_pgsql_free_params(params, num_params); |
_php_pgsql_free_params(params, num_params); |
|
|
switch (status) { |
switch (status) { |
Line 2203 static char *get_field_name(PGconn *pgsql, Oid oid, Ha
|
Line 2256 static char *get_field_name(PGconn *pgsql, Oid oid, Ha
|
num_rows = PQntuples(result); |
num_rows = PQntuples(result); |
oid_offset = PQfnumber(result,"oid"); |
oid_offset = PQfnumber(result,"oid"); |
name_offset = PQfnumber(result,"typname"); |
name_offset = PQfnumber(result,"typname"); |
| |
for (i=0; i<num_rows; i++) { |
for (i=0; i<num_rows; i++) { |
if ((tmp_oid = PQgetvalue(result,i,oid_offset))==NULL) { |
if ((tmp_oid = PQgetvalue(result,i,oid_offset))==NULL) { |
continue; |
continue; |
Line 2213 static char *get_field_name(PGconn *pgsql, Oid oid, Ha
|
Line 2266 static char *get_field_name(PGconn *pgsql, Oid oid, Ha
|
smart_str_appends(&str, "pgsql_oid_"); |
smart_str_appends(&str, "pgsql_oid_"); |
smart_str_appends(&str, tmp_oid); |
smart_str_appends(&str, tmp_oid); |
smart_str_0(&str); |
smart_str_0(&str); |
| |
if ((tmp_name = PQgetvalue(result,i,name_offset))==NULL) { |
if ((tmp_name = PQgetvalue(result,i,name_offset))==NULL) { |
continue; |
continue; |
} |
} |
Line 2230 static char *get_field_name(PGconn *pgsql, Oid oid, Ha
|
Line 2283 static char *get_field_name(PGconn *pgsql, Oid oid, Ha
|
smart_str_free(&str); |
smart_str_free(&str); |
return ret; |
return ret; |
} |
} |
/* }}} */ | /* }}} */ |
|
|
#ifdef HAVE_PQFTABLE |
#ifdef HAVE_PQFTABLE |
/* {{{ proto mixed pg_field_table(resource result, int field_number[, bool oid_only]) |
/* {{{ proto mixed pg_field_table(resource result, int field_number[, bool oid_only]) |
Line 2263 PHP_FUNCTION(pg_field_table)
|
Line 2316 PHP_FUNCTION(pg_field_table)
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
|
|
if (return_oid) { |
if (return_oid) { |
#if UINT_MAX > LONG_MAX /* Oid is unsigned int, we don't need this code, where LONG is wider */ |
#if UINT_MAX > LONG_MAX /* Oid is unsigned int, we don't need this code, where LONG is wider */ |
if (oid > LONG_MAX) { |
if (oid > LONG_MAX) { |
Line 2293 PHP_FUNCTION(pg_field_table)
|
Line 2345 PHP_FUNCTION(pg_field_table)
|
smart_str_append_unsigned(&querystr, oid); |
smart_str_append_unsigned(&querystr, oid); |
smart_str_0(&querystr); |
smart_str_0(&querystr); |
|
|
|
|
if ((tmp_res = PQexec(pg_result->conn, querystr.c)) == NULL || PQresultStatus(tmp_res) != PGRES_TUPLES_OK) { |
if ((tmp_res = PQexec(pg_result->conn, querystr.c)) == NULL || PQresultStatus(tmp_res) != PGRES_TUPLES_OK) { |
if (tmp_res) { |
if (tmp_res) { |
PQclear(tmp_res); |
PQclear(tmp_res); |
Line 2321 PHP_FUNCTION(pg_field_table)
|
Line 2372 PHP_FUNCTION(pg_field_table)
|
} |
} |
|
|
} |
} |
/* }}} */ | /* }}} */ |
#endif | #endif |
|
|
#define PHP_PG_FIELD_NAME 1 |
#define PHP_PG_FIELD_NAME 1 |
#define PHP_PG_FIELD_SIZE 2 |
#define PHP_PG_FIELD_SIZE 2 |
Line 2338 static void php_pgsql_get_field_info(INTERNAL_FUNCTION
|
Line 2389 static void php_pgsql_get_field_info(INTERNAL_FUNCTION
|
PGresult *pgsql_result; |
PGresult *pgsql_result; |
pgsql_result_handle *pg_result; |
pgsql_result_handle *pg_result; |
Oid oid; |
Oid oid; |
| |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &result, &field) == FAILURE) { |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &result, &field) == FAILURE) { |
return; |
return; |
} |
} |
| |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
|
|
pgsql_result = pg_result->result; |
pgsql_result = pg_result->result; |
Line 2351 static void php_pgsql_get_field_info(INTERNAL_FUNCTION
|
Line 2402 static void php_pgsql_get_field_info(INTERNAL_FUNCTION
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset specified"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset specified"); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
switch (entry_type) { |
switch (entry_type) { |
case PHP_PG_FIELD_NAME: |
case PHP_PG_FIELD_NAME: |
Z_STRVAL_P(return_value) = PQfname(pgsql_result, field); |
Z_STRVAL_P(return_value) = PQfname(pgsql_result, field); |
Line 2438 PHP_FUNCTION(pg_field_num)
|
Line 2489 PHP_FUNCTION(pg_field_num)
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &result, &field, &field_len) == FAILURE) { |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &result, &field, &field_len) == FAILURE) { |
return; |
return; |
} |
} |
| |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
|
|
pgsql_result = pg_result->result; |
pgsql_result = pg_result->result; |
| |
Z_LVAL_P(return_value) = PQfnumber(pgsql_result, field); |
Z_LVAL_P(return_value) = PQfnumber(pgsql_result, field); |
Z_TYPE_P(return_value) = IS_LONG; |
Z_TYPE_P(return_value) = IS_LONG; |
} |
} |
Line 2457 PHP_FUNCTION(pg_fetch_result)
|
Line 2508 PHP_FUNCTION(pg_fetch_result)
|
PGresult *pgsql_result; |
PGresult *pgsql_result; |
pgsql_result_handle *pg_result; |
pgsql_result_handle *pg_result; |
int field_offset, pgsql_row, argc = ZEND_NUM_ARGS(); |
int field_offset, pgsql_row, argc = ZEND_NUM_ARGS(); |
| |
if (argc == 2) { |
if (argc == 2) { |
if (zend_parse_parameters(argc TSRMLS_CC, "rZ", &result, &field) == FAILURE) { |
if (zend_parse_parameters(argc TSRMLS_CC, "rZ", &result, &field) == FAILURE) { |
return; |
return; |
Line 2500 PHP_FUNCTION(pg_fetch_result)
|
Line 2551 PHP_FUNCTION(pg_fetch_result)
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset specified"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset specified"); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
if (PQgetisnull(pgsql_result, pgsql_row, field_offset)) { |
if (PQgetisnull(pgsql_result, pgsql_row, field_offset)) { |
Z_TYPE_P(return_value) = IS_NULL; |
Z_TYPE_P(return_value) = IS_NULL; |
} else { |
} else { |
Line 2603 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
Line 2654 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
|
|
data = safe_estrndup(element, element_len); |
data = safe_estrndup(element, element_len); |
data_len = element_len; |
data_len = element_len; |
| |
if (result_type & PGSQL_NUM) { |
if (result_type & PGSQL_NUM) { |
add_index_stringl(return_value, i, data, data_len, should_copy); |
add_index_stringl(return_value, i, data, data_len, should_copy); |
should_copy=1; |
should_copy=1; |
} |
} |
| |
if (result_type & PGSQL_ASSOC) { |
if (result_type & PGSQL_ASSOC) { |
field_name = PQfname(pgsql_result, i); |
field_name = PQfname(pgsql_result, i); |
add_assoc_stringl(return_value, field_name, data, data_len, should_copy); |
add_assoc_stringl(return_value, field_name, data, data_len, should_copy); |
Line 2621 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
Line 2672 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
zval dataset = *return_value; |
zval dataset = *return_value; |
zend_fcall_info fci; |
zend_fcall_info fci; |
zend_fcall_info_cache fcc; |
zend_fcall_info_cache fcc; |
zval *retval_ptr; | zval *retval_ptr; |
| |
object_and_properties_init(return_value, ce, NULL); |
object_and_properties_init(return_value, ce, NULL); |
zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC); |
zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC); |
| |
if (ce->constructor) { |
if (ce->constructor) { |
fci.size = sizeof(fci); |
fci.size = sizeof(fci); |
fci.function_table = &ce->function_table; |
fci.function_table = &ce->function_table; |
Line 2637 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
Line 2688 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
if (Z_TYPE_P(ctor_params) == IS_ARRAY) { |
if (Z_TYPE_P(ctor_params) == IS_ARRAY) { |
HashTable *ht = Z_ARRVAL_P(ctor_params); |
HashTable *ht = Z_ARRVAL_P(ctor_params); |
Bucket *p; |
Bucket *p; |
| |
fci.param_count = 0; |
fci.param_count = 0; |
fci.params = safe_emalloc(sizeof(zval*), ht->nNumOfElements, 0); | fci.params = safe_emalloc(sizeof(zval***), ht->nNumOfElements, 0); |
p = ht->pListHead; |
p = ht->pListHead; |
while (p != NULL) { |
while (p != NULL) { |
fci.params[fci.param_count++] = (zval**)p->pData; |
fci.params[fci.param_count++] = (zval**)p->pData; |
Line 2666 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
Line 2717 static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PAR
|
fcc.calling_scope = EG(scope); |
fcc.calling_scope = EG(scope); |
fcc.called_scope = Z_OBJCE_P(return_value); |
fcc.called_scope = Z_OBJCE_P(return_value); |
fcc.object_ptr = return_value; |
fcc.object_ptr = return_value; |
| |
if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { |
if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { |
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name); |
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name); |
} else { |
} else { |
Line 2772 PHP_FUNCTION(pg_fetch_all_columns)
|
Line 2823 PHP_FUNCTION(pg_fetch_all_columns)
|
|
|
array_init(return_value); |
array_init(return_value); |
|
|
if ((pg_numrows = PQntuples(pgsql_result)) <= 0) { | if ((pg_numrows = PQntuples(pgsql_result)) <= 0) { |
return; |
return; |
} |
} |
|
|
Line 2781 PHP_FUNCTION(pg_fetch_all_columns)
|
Line 2832 PHP_FUNCTION(pg_fetch_all_columns)
|
add_next_index_null(return_value); |
add_next_index_null(return_value); |
} else { |
} else { |
add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); |
add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); |
} | } |
} |
} |
} |
} |
/* }}} */ |
/* }}} */ |
Line 2803 PHP_FUNCTION(pg_result_seek)
|
Line 2854 PHP_FUNCTION(pg_result_seek)
|
if (row < 0 || row >= PQntuples(pg_result->result)) { |
if (row < 0 || row >= PQntuples(pg_result->result)) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
/* seek to offset */ |
/* seek to offset */ |
pg_result->row = row; |
pg_result->row = row; |
RETURN_TRUE; |
RETURN_TRUE; |
Line 2833 static void php_pgsql_data_info(INTERNAL_FUNCTION_PARA
|
Line 2884 static void php_pgsql_data_info(INTERNAL_FUNCTION_PARA
|
return; |
return; |
} |
} |
} |
} |
| |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
|
|
pgsql_result = pg_result->result; |
pgsql_result = pg_result->result; |
Line 2853 static void php_pgsql_data_info(INTERNAL_FUNCTION_PARA
|
Line 2904 static void php_pgsql_data_info(INTERNAL_FUNCTION_PARA
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
} |
} |
| |
switch(Z_TYPE_PP(field)) { |
switch(Z_TYPE_PP(field)) { |
case IS_STRING: |
case IS_STRING: |
convert_to_string_ex(field); |
convert_to_string_ex(field); |
Line 2868 static void php_pgsql_data_info(INTERNAL_FUNCTION_PARA
|
Line 2919 static void php_pgsql_data_info(INTERNAL_FUNCTION_PARA
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset specified"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset specified"); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
switch (entry_type) { |
switch (entry_type) { |
case PHP_PG_DATA_LENGTH: |
case PHP_PG_DATA_LENGTH: |
Z_LVAL_P(return_value) = PQgetlength(pgsql_result, pgsql_row, field_offset); |
Z_LVAL_P(return_value) = PQgetlength(pgsql_result, pgsql_row, field_offset); |
Line 2903 PHP_FUNCTION(pg_free_result)
|
Line 2954 PHP_FUNCTION(pg_free_result)
|
{ |
{ |
zval *result; |
zval *result; |
pgsql_result_handle *pg_result; |
pgsql_result_handle *pg_result; |
| |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { |
return; |
return; |
} |
} |
Line 2931 PHP_FUNCTION(pg_last_oid)
|
Line 2982 PHP_FUNCTION(pg_last_oid)
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { |
return; |
return; |
} |
} |
| |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); |
pgsql_result = pg_result->result; |
pgsql_result = pg_result->result; |
#ifdef HAVE_PQOIDVALUE |
#ifdef HAVE_PQOIDVALUE |
Line 2962 PHP_FUNCTION(pg_trace)
|
Line 3013 PHP_FUNCTION(pg_trace)
|
FILE *fp = NULL; |
FILE *fp = NULL; |
php_stream *stream; |
php_stream *stream; |
id = PGG(default_link); |
id = PGG(default_link); |
| |
if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) { |
if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (argc < 3) { |
if (argc < 3) { |
CHECK_DEFAULT_LINK(id); |
CHECK_DEFAULT_LINK(id); |
} | } |
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 3012 PHP_FUNCTION(pg_untrace)
|
Line 3063 PHP_FUNCTION(pg_untrace)
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
PQuntrace(pgsql); |
PQuntrace(pgsql); |
Line 3024 PHP_FUNCTION(pg_untrace)
|
Line 3075 PHP_FUNCTION(pg_untrace)
|
Create a large object */ |
Create a large object */ |
PHP_FUNCTION(pg_lo_create) |
PHP_FUNCTION(pg_lo_create) |
{ |
{ |
zval *pgsql_link = NULL, *oid = NULL; | zval *pgsql_link = NULL, *oid = NULL; |
PGconn *pgsql; | PGconn *pgsql; |
Oid pgsql_oid, wanted_oid = InvalidOid; | Oid pgsql_oid, wanted_oid = InvalidOid; |
int id = -1, argc = ZEND_NUM_ARGS(); | int id = -1, argc = ZEND_NUM_ARGS(); |
|
|
if (zend_parse_parameters(argc TSRMLS_CC, "|zz", &pgsql_link, &oid) == FAILURE) { |
if (zend_parse_parameters(argc TSRMLS_CC, "|zz", &pgsql_link, &oid) == FAILURE) { |
return; |
return; |
Line 3049 PHP_FUNCTION(pg_lo_create)
|
Line 3100 PHP_FUNCTION(pg_lo_create)
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
if (oid) { |
if (oid) { |
#ifndef HAVE_PG_LO_CREATE | #ifndef HAVE_PG_LO_CREATE |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "OID value passing not supported"); | php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Passing OID value is not supported. Upgrade your PostgreSQL"); |
#else |
#else |
switch (Z_TYPE_P(oid)) { |
switch (Z_TYPE_P(oid)) { |
case IS_STRING: |
case IS_STRING: |
{ | { |
char *end_ptr; |
char *end_ptr; |
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10); |
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10); |
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) { |
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) { |
Line 3080 PHP_FUNCTION(pg_lo_create)
|
Line 3131 PHP_FUNCTION(pg_lo_create)
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
PGSQL_RETURN_OID(pgsql_oid); | PGSQL_RETURN_OID(pgsql_oid); |
#endif |
#endif |
} |
} |
|
|
Line 3089 PHP_FUNCTION(pg_lo_create)
|
Line 3140 PHP_FUNCTION(pg_lo_create)
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
PGSQL_RETURN_OID(pgsql_oid); | PGSQL_RETURN_OID(pgsql_oid); |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 3151 PHP_FUNCTION(pg_lo_unlink)
|
Line 3202 PHP_FUNCTION(pg_lo_unlink)
|
} |
} |
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 3223 PHP_FUNCTION(pg_lo_open)
|
Line 3274 PHP_FUNCTION(pg_lo_open)
|
} |
} |
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 3315 PHP_FUNCTION(pg_lo_close)
|
Line 3366 PHP_FUNCTION(pg_lo_close)
|
Read a large object */ |
Read a large object */ |
PHP_FUNCTION(pg_lo_read) |
PHP_FUNCTION(pg_lo_read) |
{ |
{ |
zval *pgsql_id; | zval *pgsql_id; |
long len; | long len; |
int buf_len = PGSQL_LO_READ_BUF_SIZE, nbytes, argc = ZEND_NUM_ARGS(); |
int buf_len = PGSQL_LO_READ_BUF_SIZE, nbytes, argc = ZEND_NUM_ARGS(); |
char *buf; |
char *buf; |
pgLofp *pgsql; |
pgLofp *pgsql; |
Line 3443 PHP_FUNCTION(pg_lo_import)
|
Line 3494 PHP_FUNCTION(pg_lo_import)
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 3454 PHP_FUNCTION(pg_lo_import)
|
Line 3505 PHP_FUNCTION(pg_lo_import)
|
Oid wanted_oid; |
Oid wanted_oid; |
switch (Z_TYPE_P(oid)) { |
switch (Z_TYPE_P(oid)) { |
case IS_STRING: |
case IS_STRING: |
{ | { |
char *end_ptr; |
char *end_ptr; |
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10); |
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10); |
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) { |
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) { |
Line 3576 PHP_FUNCTION(pg_lo_export)
|
Line 3627 PHP_FUNCTION(pg_lo_export)
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
if (lo_export(pgsql, oid, file_out)) { |
if (lo_export(pgsql, oid, file_out)) { |
RETURN_TRUE; |
RETURN_TRUE; |
} | } |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
/* }}} */ |
/* }}} */ |
Line 3697 PHP_FUNCTION(pg_set_client_encoding)
|
Line 3748 PHP_FUNCTION(pg_set_client_encoding)
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 3731 PHP_FUNCTION(pg_client_encoding)
|
Line 3782 PHP_FUNCTION(pg_client_encoding)
|
|
|
/* Just do the same as found in PostgreSQL sources... */ |
/* Just do the same as found in PostgreSQL sources... */ |
|
|
#ifndef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT |
|
#define pg_encoding_to_char(x) "SQL_ASCII" |
|
#endif |
|
|
|
Z_STRVAL_P(return_value) = (char *) pg_encoding_to_char(PQclientEncoding(pgsql)); |
Z_STRVAL_P(return_value) = (char *) pg_encoding_to_char(PQclientEncoding(pgsql)); |
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); |
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); |
Z_STRVAL_P(return_value) = (char *) estrdup(Z_STRVAL_P(return_value)); |
Z_STRVAL_P(return_value) = (char *) estrdup(Z_STRVAL_P(return_value)); |
Line 3767 PHP_FUNCTION(pg_end_copy)
|
Line 3814 PHP_FUNCTION(pg_end_copy)
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 3903 PHP_FUNCTION(pg_copy_to)
|
Line 3950 PHP_FUNCTION(pg_copy_to)
|
PHP_PQ_ERROR("getline failed: %s", pgsql); |
PHP_PQ_ERROR("getline failed: %s", pgsql); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
if (copybuf[0] == '\\' && |
if (copybuf[0] == '\\' && |
copybuf[1] == '.' && |
copybuf[1] == '.' && |
copybuf[2] == '\0') |
copybuf[2] == '\0') |
Line 4111 PHP_FUNCTION(pg_escape_string)
|
Line 4158 PHP_FUNCTION(pg_escape_string)
|
} |
} |
|
|
to = (char *) safe_emalloc(from_len, 2, 1); |
to = (char *) safe_emalloc(from_len, 2, 1); |
|
|
#ifdef HAVE_PQESCAPE_CONN |
#ifdef HAVE_PQESCAPE_CONN |
if (pgsql_link != NULL || id != -1) { |
if (pgsql_link != NULL || id != -1) { |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
to_len = (int) PQescapeStringConn(pgsql, to, from, (size_t)from_len, NULL); |
to_len = (int) PQescapeStringConn(pgsql, to, from, (size_t)from_len, NULL); |
} else | } else |
#endif |
#endif |
to_len = (int) PQescapeString(to, from, (size_t)from_len); |
to_len = (int) PQescapeString(to, from, (size_t)from_len); |
|
|
Line 4191 PHP_FUNCTION(pg_escape_bytea)
|
Line 4237 PHP_FUNCTION(pg_escape_bytea)
|
*/ |
*/ |
static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t *retbuflen) |
static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t *retbuflen) |
{ |
{ |
size_t buflen; | size_t buflen; |
unsigned char *buffer, |
unsigned char *buffer, |
*sp, |
*sp, |
*bp; |
*bp; |
Line 4251 static unsigned char * php_pgsql_unescape_bytea(unsign
|
Line 4297 static unsigned char * php_pgsql_unescape_bytea(unsign
|
memcpy(buf, sp-2, 3); |
memcpy(buf, sp-2, 3); |
buf[3] = '\0'; |
buf[3] = '\0'; |
start = buf; |
start = buf; |
*bp = (unsigned char)strtoul(start, (char **)&end, 8); | *bp = (unsigned char)strtoul(start, (char **)&end, 8); |
buflen -= 3; |
buflen -= 3; |
state = 0; |
state = 0; |
} |
} |
Line 4299 PHP_FUNCTION(pg_unescape_bytea)
|
Line 4345 PHP_FUNCTION(pg_unescape_bytea)
|
#endif |
#endif |
|
|
#ifdef HAVE_PQESCAPE |
#ifdef HAVE_PQESCAPE |
#if !HAVE_PQESCAPELITERAL |
|
/* emulate libpq's PQescapeInternal() 9.0 or later */ |
|
static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t len, int escape_literal) { |
|
char *result, *rp; |
|
const char *s; |
|
size_t tmp_len; |
|
int input_len = len; |
|
char quote_char = escape_literal ? '\'' : '"'; |
|
|
|
if (!conn) { |
|
return NULL; |
|
} |
|
|
|
/* |
|
* NOTE: multibyte strings that could cointain slashes should be considered. |
|
* (e.g. SJIS, BIG5) However, it cannot be done without valid PGconn and mbstring. |
|
* Therefore, this function does not support such encodings currently. |
|
* FIXME: add encoding check and skip multibyte char bytes if there is vaild PGconn. |
|
*/ |
|
|
|
/* allocate enough memory */ |
|
rp = result = (char *)emalloc(len*2 + 5); /* leading " E" needs extra 2 bytes + quote_chars on both end for 2 bytes + NULL */ |
|
|
|
if (escape_literal) { |
|
/* check backslashes */ |
|
tmp_len = strspn(str, "\\"); |
|
if (tmp_len != len) { |
|
/* add " E" for escaping slashes */ |
|
*rp++ = ' '; |
|
*rp++ = 'E'; |
|
} |
|
} |
|
/* open quote */ |
|
*rp++ = quote_char; |
|
for (s = str; s - str < input_len; ++s) { |
|
if (*s == quote_char || (escape_literal && *s == '\\')) { |
|
*rp++ = *s; |
|
*rp++ = *s; |
|
} else { |
|
*rp++ = *s; |
|
} |
|
} |
|
*rp++ = quote_char; |
|
*rp = '\0'; |
|
|
|
return result; |
|
} |
|
#endif |
|
|
|
static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_literal) { |
static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_literal) { |
char *from = NULL, *to = NULL; |
char *from = NULL, *to = NULL; |
zval *pgsql_link = NULL; |
zval *pgsql_link = NULL; |
PGconn *pgsql; |
PGconn *pgsql; |
int from_len; |
int from_len; |
int id = -1; |
int id = -1; |
|
char *tmp; |
|
|
switch (ZEND_NUM_ARGS()) { |
switch (ZEND_NUM_ARGS()) { |
case 1: |
case 1: |
Line 4381 static void php_pgsql_escape_internal(INTERNAL_FUNCTIO
|
Line 4379 static void php_pgsql_escape_internal(INTERNAL_FUNCTIO
|
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot get pgsql link"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot get pgsql link"); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
#ifdef HAVE_PQESCAPELITERAL |
|
/* Use a block with a local var to avoid unused variable warnings */ |
|
{ |
|
char *tmp; |
|
|
|
if (escape_literal) { | if (escape_literal) { |
tmp = PQescapeLiteral(pgsql, from, (size_t)from_len); | tmp = PGSQLescapeLiteral(pgsql, from, (size_t)from_len); |
} else { | } else { |
tmp = PQescapeIdentifier(pgsql, from, (size_t)from_len); | tmp = PGSQLescapeIdentifier(pgsql, from, (size_t)from_len); |
} | |
if (!tmp) { | |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape"); | |
RETURN_FALSE; | |
} | |
to = estrdup(tmp); | |
PQfreemem(tmp); | |
} |
} |
#else | if (!tmp) { |
to = php_pgsql_PQescapeInternal(pgsql, from, (size_t)from_len, escape_literal); | |
if (!to) { | |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape"); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
#endif | to = estrdup(tmp); |
| PGSQLfree(tmp); |
|
|
RETURN_STRING(to, 0); |
RETURN_STRING(to, 0); |
} |
} |
Line 4452 PHP_FUNCTION(pg_result_error)
|
Line 4438 PHP_FUNCTION(pg_result_error)
|
} |
} |
/* }}} */ |
/* }}} */ |
|
|
|
|
#if HAVE_PQRESULTERRORFIELD |
#if HAVE_PQRESULTERRORFIELD |
/* {{{ proto string pg_result_error_field(resource result, int fieldcode) |
/* {{{ proto string pg_result_error_field(resource result, int fieldcode) |
Get error message field associated with result */ |
Get error message field associated with result */ |
Line 4497 PHP_FUNCTION(pg_result_error_field)
|
Line 4484 PHP_FUNCTION(pg_result_error_field)
|
/* }}} */ |
/* }}} */ |
#endif |
#endif |
|
|
|
|
/* {{{ proto int pg_connection_status(resource connection) |
/* {{{ proto int pg_connection_status(resource connection) |
Get connection status */ |
Get connection status */ |
PHP_FUNCTION(pg_connection_status) |
PHP_FUNCTION(pg_connection_status) |
Line 4517 PHP_FUNCTION(pg_connection_status)
|
Line 4505 PHP_FUNCTION(pg_connection_status)
|
|
|
/* }}} */ |
/* }}} */ |
|
|
|
|
#if HAVE_PGTRANSACTIONSTATUS |
#if HAVE_PGTRANSACTIONSTATUS |
/* {{{ proto int pg_transaction_status(resource connection) |
/* {{{ proto int pg_transaction_status(resource connection) |
Get transaction status */ |
Get transaction status */ |
Line 4539 PHP_FUNCTION(pg_transaction_status)
|
Line 4528 PHP_FUNCTION(pg_transaction_status)
|
|
|
/* }}} */ |
/* }}} */ |
|
|
|
|
/* {{{ proto bool pg_connection_reset(resource connection) |
/* {{{ proto bool pg_connection_reset(resource connection) |
Reset connection (reconnect) */ |
Reset connection (reconnect) */ |
PHP_FUNCTION(pg_connection_reset) |
PHP_FUNCTION(pg_connection_reset) |
Line 4560 PHP_FUNCTION(pg_connection_reset)
|
Line 4550 PHP_FUNCTION(pg_connection_reset)
|
} |
} |
RETURN_TRUE; |
RETURN_TRUE; |
} |
} |
|
|
/* }}} */ |
/* }}} */ |
|
|
|
|
#define PHP_PG_ASYNC_IS_BUSY 1 |
#define PHP_PG_ASYNC_IS_BUSY 1 |
#define PHP_PG_ASYNC_REQUEST_CANCEL 2 |
#define PHP_PG_ASYNC_REQUEST_CANCEL 2 |
| |
| |
/* {{{ php_pgsql_flush_query |
/* {{{ php_pgsql_flush_query |
*/ |
*/ |
static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_DC) |
static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_DC) |
Line 4585 static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_
|
Line 4576 static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_
|
return leftover; |
return leftover; |
} |
} |
/* }}} */ |
/* }}} */ |
| |
| |
/* {{{ php_pgsql_do_async |
/* {{{ php_pgsql_do_async |
*/ |
*/ |
static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type) |
static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type) |
Line 4815 PHP_FUNCTION(pg_send_prepare)
|
Line 4807 PHP_FUNCTION(pg_send_prepare)
|
|
|
if (pgsql_link == NULL && id == -1) { |
if (pgsql_link == NULL && id == -1) { |
RETURN_FALSE; |
RETURN_FALSE; |
} | } |
|
|
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); |
|
|
Line 5103 PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link,
|
Line 5095 PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link,
|
size_t new_len; |
size_t new_len; |
int i, num_rows; |
int i, num_rows; |
zval *elem; |
zval *elem; |
| |
if (!*table_name) { |
if (!*table_name) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified"); |
return FAILURE; |
return FAILURE; |
Line 5123 PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link,
|
Line 5115 PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link,
|
"FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n " |
"FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n " |
"WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '"); |
"WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '"); |
escaped = (char *)safe_emalloc(strlen(tmp_name2), 2, 1); |
escaped = (char *)safe_emalloc(strlen(tmp_name2), 2, 1); |
#if HAVE_PQESCAPE_CONN |
|
new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, strlen(tmp_name2), NULL); |
new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, strlen(tmp_name2), NULL); |
#else |
|
new_len = PQescapeString(escaped, tmp_name2, strlen(tmp_name2)); |
|
#endif |
|
if (new_len) { |
if (new_len) { |
smart_str_appends(&querystr, escaped); | smart_str_appendl(&querystr, escaped, new_len); |
} |
} |
efree(escaped); |
efree(escaped); |
|
|
smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '"); |
smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '"); |
escaped = (char *)safe_emalloc(strlen(tmp_name), 2, 1); |
escaped = (char *)safe_emalloc(strlen(tmp_name), 2, 1); |
#if HAVE_PQESCAPE_CONN |
|
new_len = PQescapeStringConn(pg_link, escaped, tmp_name, strlen(tmp_name), NULL); |
new_len = PQescapeStringConn(pg_link, escaped, tmp_name, strlen(tmp_name), NULL); |
#else |
|
new_len = PQescapeString(escaped, tmp_name, strlen(tmp_name)); |
|
#endif |
|
if (new_len) { |
if (new_len) { |
smart_str_appends(&querystr, escaped); | smart_str_appendl(&querystr, escaped, new_len); |
} |
} |
efree(escaped); |
efree(escaped); |
|
|
Line 5204 PHP_FUNCTION(pg_meta_data)
|
Line 5188 PHP_FUNCTION(pg_meta_data)
|
uint table_name_len; |
uint table_name_len; |
PGconn *pgsql; |
PGconn *pgsql; |
int id = -1; |
int id = -1; |
| |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", |
&pgsql_link, &table_name, &table_name_len) == FAILURE) { |
&pgsql_link, &table_name, &table_name_len) == FAILURE) { |
return; |
return; |
Line 5231 PHP_FUNCTION(pg_meta_data)
|
Line 5215 PHP_FUNCTION(pg_meta_data)
|
} |
} |
/* }}} */ |
/* }}} */ |
|
|
|
|
/* {{{ php_pgsql_get_data_type |
/* {{{ php_pgsql_get_data_type |
*/ |
*/ |
static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t len) |
static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t len) |
{ |
{ |
/* This is stupid way to do. I'll fix it when I decied how to support | /* This is stupid way to do. I'll fix it when I decied how to support |
user defined types. (Yasuo) */ |
user defined types. (Yasuo) */ |
| |
/* boolean */ |
/* boolean */ |
if (!strcmp(type_name, "bool")|| !strcmp(type_name, "boolean")) |
if (!strcmp(type_name, "bool")|| !strcmp(type_name, "boolean")) |
return PG_BOOL; |
return PG_BOOL; |
Line 5316 static php_pgsql_data_type php_pgsql_get_data_type(con
|
Line 5301 static php_pgsql_data_type php_pgsql_get_data_type(con
|
return PG_POLYGON; |
return PG_POLYGON; |
if (!strcmp(type_name, "circle")) |
if (!strcmp(type_name, "circle")) |
return PG_CIRCLE; |
return PG_CIRCLE; |
| |
return PG_UNKNOWN; |
return PG_UNKNOWN; |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
/* {{{ php_pgsql_convert_match |
/* {{{ php_pgsql_convert_match |
* test field value with regular expression specified. | * test field value with regular expression specified. |
*/ |
*/ |
static int php_pgsql_convert_match(const char *str, const char *regex , int icase TSRMLS_DC) | static int php_pgsql_convert_match(const char *str, size_t str_len, const char *regex , int icase TSRMLS_DC) |
{ |
{ |
regex_t re; | regex_t re; |
regmatch_t *subs; |
regmatch_t *subs; |
int regopt = REG_EXTENDED; |
int regopt = REG_EXTENDED; |
int regerr, ret = SUCCESS; |
int regerr, ret = SUCCESS; |
|
int i; |
|
|
|
/* Check invalid chars for POSIX regex */ |
|
for (i = 0; i < str_len; i++) { |
|
if (str[i] == '\n' || |
|
str[i] == '\r' || |
|
str[i] == '\0' ) { |
|
return FAILURE; |
|
} |
|
} |
|
|
if (icase) { |
if (icase) { |
regopt |= REG_ICASE; |
regopt |= REG_ICASE; |
} |
} |
| |
regerr = regcomp(&re, regex, regopt); |
regerr = regcomp(&re, regex, regopt); |
if (regerr) { |
if (regerr) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot compile regex"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot compile regex"); |
Line 5345 static int php_pgsql_convert_match(const char *str, co
|
Line 5340 static int php_pgsql_convert_match(const char *str, co
|
|
|
regerr = regexec(&re, str, re.re_nsub+1, subs, 0); |
regerr = regexec(&re, str, re.re_nsub+1, subs, 0); |
if (regerr == REG_NOMATCH) { |
if (regerr == REG_NOMATCH) { |
#ifdef PHP_DEBUG | #ifdef PHP_DEBUG |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "'%s' does not match with '%s'", str, regex); |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "'%s' does not match with '%s'", str, regex); |
#endif |
#endif |
ret = FAILURE; |
ret = FAILURE; |
Line 5367 static int php_pgsql_convert_match(const char *str, co
|
Line 5362 static int php_pgsql_convert_match(const char *str, co
|
static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC) |
static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC) |
{ |
{ |
smart_str str = {0}; |
smart_str str = {0}; |
| |
assert(Z_TYPE_P(src) == IS_STRING); |
assert(Z_TYPE_P(src) == IS_STRING); |
assert(should_free == 1 || should_free == 0); |
assert(should_free == 1 || should_free == 0); |
|
|
Line 5376 static int php_pgsql_add_quotes(zval *src, zend_bool s
|
Line 5371 static int php_pgsql_add_quotes(zval *src, zend_bool s
|
smart_str_appendl(&str, Z_STRVAL_P(src), Z_STRLEN_P(src)); |
smart_str_appendl(&str, Z_STRVAL_P(src), Z_STRLEN_P(src)); |
smart_str_appendc(&str, '\''); |
smart_str_appendc(&str, '\''); |
smart_str_0(&str); |
smart_str_0(&str); |
| |
if (should_free) { |
if (should_free) { |
efree(Z_STRVAL_P(src)); |
efree(Z_STRVAL_P(src)); |
} |
} |
Line 5400 static int php_pgsql_add_quotes(zval *src, zend_bool s
|
Line 5395 static int php_pgsql_add_quotes(zval *src, zend_bool s
|
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected NULL for 'NOT NULL' field '%s'", field ); \ |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected NULL for 'NOT NULL' field '%s'", field ); \ |
err = 1; \ |
err = 1; \ |
} \ |
} \ |
} | } |
|
|
/* {{{ php_pgsql_convert |
/* {{{ php_pgsql_convert |
* check and convert array values (fieldname=>vlaue pair) for sql |
* check and convert array values (fieldname=>vlaue pair) for sql |
Line 5414 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5409 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
zval *meta, **def, **type, **not_null, **has_default, **is_enum, **val, *new_val; |
zval *meta, **def, **type, **not_null, **has_default, **is_enum, **val, *new_val; |
int key_type, err = 0, skip_field; |
int key_type, err = 0, skip_field; |
php_pgsql_data_type data_type; |
php_pgsql_data_type data_type; |
| |
assert(pg_link != NULL); |
assert(pg_link != NULL); |
assert(Z_TYPE_P(values) == IS_ARRAY); |
assert(Z_TYPE_P(values) == IS_ARRAY); |
assert(Z_TYPE_P(result) == IS_ARRAY); |
assert(Z_TYPE_P(result) == IS_ARRAY); |
Line 5437 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5432 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos)) { |
zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos)) { |
skip_field = 0; |
skip_field = 0; |
new_val = NULL; |
new_val = NULL; |
| |
if ((key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &field, &field_len, &num_idx, 0, &pos)) == HASH_KEY_NON_EXISTANT) { |
if ((key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &field, &field_len, &num_idx, 0, &pos)) == HASH_KEY_NON_EXISTANT) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to get array key type"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to get array key type"); |
err = 1; |
err = 1; |
Line 5518 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5513 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
break; |
break; |
| |
case IS_LONG: |
case IS_LONG: |
case IS_BOOL: |
case IS_BOOL: |
if (Z_LVAL_PP(val)) { |
if (Z_LVAL_PP(val)) { |
Line 5541 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5536 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects string, null, long or boolelan value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field); |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects string, null, long or boolelan value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field); |
} |
} |
break; |
break; |
| |
case PG_OID: |
case PG_OID: |
case PG_INT2: |
case PG_INT2: |
case PG_INT4: |
case PG_INT4: |
Line 5553 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5548 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
else { |
else { |
/* FIXME: better regex must be used */ |
/* FIXME: better regex must be used */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([+-]{0,1}[0-9]+)$", 0 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([+-]{0,1}[0-9]+)$", 0 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} |
} |
else { |
else { |
Line 5561 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5556 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
break; |
break; |
| |
case IS_DOUBLE: |
case IS_DOUBLE: |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
convert_to_long_ex(&new_val); |
convert_to_long_ex(&new_val); |
Line 5595 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5590 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
else { |
else { |
/* FIXME: better regex must be used */ |
/* FIXME: better regex must be used */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([+-]{0,1}[0-9]+)|([+-]{0,1}[0-9]*[\\.][0-9]+)|([+-]{0,1}[0-9]+[\\.][0-9]*)$", 0 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([+-]{0,1}[0-9]+)|([+-]{0,1}[0-9]*[\\.][0-9]+)|([+-]{0,1}[0-9]+[\\.][0-9]*)$", 0 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} |
} |
else { |
else { |
Line 5603 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5598 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
break; |
break; |
| |
case IS_LONG: |
case IS_LONG: |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
break; |
break; |
| |
case IS_DOUBLE: |
case IS_DOUBLE: |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
break; |
break; |
| |
case IS_NULL: |
case IS_NULL: |
ZVAL_STRING(new_val, "NULL", 1); |
ZVAL_STRING(new_val, "NULL", 1); |
break; |
break; |
Line 5638 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5633 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
else { |
else { |
|
char *tmp; |
Z_TYPE_P(new_val) = IS_STRING; |
Z_TYPE_P(new_val) = IS_STRING; |
#if HAVE_PQESCAPE_CONN | tmp = (char *)safe_emalloc(Z_STRLEN_PP(val), 2, 1); |
{ | Z_STRLEN_P(new_val) = (int)PQescapeStringConn(pg_link, tmp, Z_STRVAL_PP(val), Z_STRLEN_PP(val), NULL); |
char *tmp; | Z_STRVAL_P(new_val) = tmp; |
tmp = (char *)safe_emalloc(Z_STRLEN_PP(val), 2, 1); | |
Z_STRLEN_P(new_val) = (int)PQescapeStringConn(pg_link, tmp, Z_STRVAL_PP(val), Z_STRLEN_PP(val), NULL); | |
Z_STRVAL_P(new_val) = tmp; | |
} | |
#else | |
Z_STRVAL_P(new_val) = (int)PQescapeString(Z_STRVAL_PP(val), Z_STRLEN_PP(val), &Z_STRLEN_P(new_val), 0 TSRMLS_CC); | |
#endif | |
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC); |
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC); |
} |
} |
break; |
break; |
| |
case IS_LONG: |
case IS_LONG: |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
convert_to_string_ex(&new_val); |
convert_to_string_ex(&new_val); |
break; |
break; |
| |
case IS_DOUBLE: |
case IS_DOUBLE: |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
convert_to_string_ex(&new_val); |
convert_to_string_ex(&new_val); |
Line 5675 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5664 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field); |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field); |
} |
} |
break; |
break; |
| |
case PG_UNIX_TIME: |
case PG_UNIX_TIME: |
case PG_UNIX_TIME_INTERVAL: |
case PG_UNIX_TIME_INTERVAL: |
/* these are the actallay a integer */ |
/* these are the actallay a integer */ |
Line 5686 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5675 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
else { |
else { |
/* FIXME: Better regex must be used */ |
/* FIXME: Better regex must be used */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^[0-9]+$", 0 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^[0-9]+$", 0 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} | } |
else { |
else { |
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); |
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); |
convert_to_long_ex(&new_val); |
convert_to_long_ex(&new_val); |
} |
} |
} |
} |
break; |
break; |
| |
case IS_DOUBLE: |
case IS_DOUBLE: |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
convert_to_long_ex(&new_val); |
convert_to_long_ex(&new_val); |
break; |
break; |
| |
case IS_LONG: |
case IS_LONG: |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
break; |
break; |
| |
case IS_NULL: |
case IS_NULL: |
ZVAL_STRING(new_val, "NULL", 1); |
ZVAL_STRING(new_val, "NULL", 1); |
break; |
break; |
Line 5717 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5706 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for '%s' (%s)", Z_STRVAL_PP(type), field); |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for '%s' (%s)", Z_STRVAL_PP(type), field); |
} |
} |
break; |
break; |
| |
case PG_CIDR: |
case PG_CIDR: |
case PG_INET: |
case PG_INET: |
switch (Z_TYPE_PP(val)) { |
switch (Z_TYPE_PP(val)) { |
Line 5727 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5716 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
else { |
else { |
/* FIXME: Better regex must be used */ |
/* FIXME: Better regex must be used */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([0-9]{1,3}\\.){3}[0-9]{1,3}(/[0-9]{1,2}){0,1}$", 0 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{1,3}\\.){3}[0-9]{1,3}(/[0-9]{1,2}){0,1}$", 0 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} |
} |
else { |
else { |
Line 5743 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5732 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
|
|
default: |
default: |
err = 1; |
err = 1; |
} | } |
PGSQL_CONV_CHECK_IGNORE(); |
PGSQL_CONV_CHECK_IGNORE(); |
if (err) { |
if (err) { |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for '%s' (%s)", Z_STRVAL_PP(type), field); |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for '%s' (%s)", Z_STRVAL_PP(type), field); |
} |
} |
break; |
break; |
| |
case PG_TIME_WITH_TIMEZONE: |
case PG_TIME_WITH_TIMEZONE: |
case PG_TIMESTAMP: |
case PG_TIMESTAMP: |
case PG_TIMESTAMP_WITH_TIMEZONE: |
case PG_TIMESTAMP_WITH_TIMEZONE: |
Line 5761 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5750 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
ZVAL_STRINGL(new_val, "NOW()", sizeof("NOW()")-1, 1); |
ZVAL_STRINGL(new_val, "NOW()", sizeof("NOW()")-1, 1); |
} else { |
} else { |
/* FIXME: better regex must be used */ |
/* FIXME: better regex must be used */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})([ \\t]+(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,4}(:[0-9]{1,2}){0,1}|[-a-zA-Z_/+]{1,50})){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})([ \\t]+(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,4}(:[0-9]{1,2}){0,1}|[-a-zA-Z_/+]{1,50})){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} else { |
} else { |
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); |
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); |
Line 5769 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5758 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
break; |
break; |
| |
case IS_NULL: |
case IS_NULL: |
ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1); |
ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1); |
break; |
break; |
Line 5782 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5771 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field); |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field); |
} |
} |
break; |
break; |
| |
case PG_DATE: |
case PG_DATE: |
switch(Z_TYPE_PP(val)) { |
switch(Z_TYPE_PP(val)) { |
case IS_STRING: |
case IS_STRING: |
Line 5791 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5780 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
else { |
else { |
/* FIXME: better regex must be used */ |
/* FIXME: better regex must be used */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})$", 1 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})$", 1 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} |
} |
else { |
else { |
Line 5800 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5789 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
break; |
break; |
| |
case IS_NULL: |
case IS_NULL: |
ZVAL_STRING(new_val, "NULL", 1); |
ZVAL_STRING(new_val, "NULL", 1); |
break; |
break; |
Line 5822 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5811 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
else { |
else { |
/* FIXME: better regex must be used */ |
/* FIXME: better regex must be used */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} |
} |
else { |
else { |
Line 5831 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5820 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
break; |
break; |
| |
case IS_NULL: |
case IS_NULL: |
ZVAL_STRING(new_val, "NULL", 1); |
ZVAL_STRING(new_val, "NULL", 1); |
break; |
break; |
Line 5868 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5857 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Quantities of days, hours, minutes, and seconds can be specified without explicit |
Quantities of days, hours, minutes, and seconds can be specified without explicit |
unit markings. For example, '1 12:59:10' is read the same as '1 day 12 hours 59 min 10 |
unit markings. For example, '1 12:59:10' is read the same as '1 day 12 hours 59 min 10 |
sec'. |
sec'. |
*/ | */ |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), |
"^(@?[ \\t]+)?(" |
"^(@?[ \\t]+)?(" |
| |
/* Textual time units and their abbreviations: */ |
/* Textual time units and their abbreviations: */ |
"(([-+]?[ \\t]+)?" |
"(([-+]?[ \\t]+)?" |
"[0-9]+(\\.[0-9]*)?[ \\t]*" |
"[0-9]+(\\.[0-9]*)?[ \\t]*" |
Line 5908 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5897 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); |
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); |
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC); |
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC); |
} |
} |
} | } |
break; |
break; |
| |
case IS_NULL: |
case IS_NULL: |
ZVAL_STRING(new_val, "NULL", 1); |
ZVAL_STRING(new_val, "NULL", 1); |
break; |
break; |
Line 5952 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5941 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Z_STRLEN_P(new_val) = s.len; |
Z_STRLEN_P(new_val) = s.len; |
} |
} |
break; |
break; |
| |
case IS_LONG: |
case IS_LONG: |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
ZVAL_LONG(new_val, Z_LVAL_PP(val)); |
convert_to_string_ex(&new_val); |
convert_to_string_ex(&new_val); |
break; |
break; |
| |
case IS_DOUBLE: |
case IS_DOUBLE: |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); |
convert_to_string_ex(&new_val); |
convert_to_string_ex(&new_val); |
Line 5984 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5973 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
ZVAL_STRING(new_val, "NULL", 1); |
ZVAL_STRING(new_val, "NULL", 1); |
} |
} |
else { |
else { |
if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([0-9a-f]{2,2}:){5,5}[0-9a-f]{2,2}$", 1 TSRMLS_CC) == FAILURE) { | if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9a-f]{2,2}:){5,5}[0-9a-f]{2,2}$", 1 TSRMLS_CC) == FAILURE) { |
err = 1; |
err = 1; |
} |
} |
else { |
else { |
Line 5993 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 5982 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
} |
} |
} |
} |
break; |
break; |
| |
case IS_NULL: |
case IS_NULL: |
ZVAL_STRING(new_val, "NULL", 1); |
ZVAL_STRING(new_val, "NULL", 1); |
break; |
break; |
Line 6028 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 6017 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
err = 1; |
err = 1; |
break; |
break; |
} /* switch */ |
} /* switch */ |
| |
if (err) { |
if (err) { |
zval_dtor(new_val); |
zval_dtor(new_val); |
FREE_ZVAL(new_val); |
FREE_ZVAL(new_val); |
Line 6040 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
Line 6029 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, c
|
size_t field_len = strlen(field); |
size_t field_len = strlen(field); |
|
|
if (_php_pgsql_detect_identifier_escape(field, field_len) == SUCCESS) { |
if (_php_pgsql_detect_identifier_escape(field, field_len) == SUCCESS) { |
escaped = _php_pgsql_strndup(field, field_len); | add_assoc_zval(result, field, new_val); |
} else { |
} else { |
#if HAVE_PQESCAPELITERAL | escaped = PGSQLescapeIdentifier(pg_link, field, field_len); |
escaped = PQescapeIdentifier(pg_link, field, field_len); | add_assoc_zval(result, escaped, new_val); |
#else | PGSQLfree(escaped); |
escaped = _php_pgsql_escape_identifier(field, field_len); | |
#endif | |
} |
} |
add_assoc_zval(result, escaped, new_val); |
|
free(escaped); |
|
} |
} |
} /* for */ |
} /* for */ |
zval_dtor(meta); |
zval_dtor(meta); |
Line 6074 PHP_FUNCTION(pg_convert)
|
Line 6059 PHP_FUNCTION(pg_convert)
|
ulong option = 0; |
ulong option = 0; |
PGconn *pg_link; |
PGconn *pg_link; |
int id = -1; |
int id = -1; |
| |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
"rsa|l", &pgsql_link, &table_name, &table_name_len, &values, &option) == FAILURE) { |
"rsa|l", &pgsql_link, &table_name, &table_name_len, &values, &option) == FAILURE) { |
return; |
return; |
Line 6134 static inline void build_tablename(smart_str *querystr
|
Line 6119 static inline void build_tablename(smart_str *querystr
|
token = php_strtok_r(table_copy, ".", &tmp); |
token = php_strtok_r(table_copy, ".", &tmp); |
len = strlen(token); |
len = strlen(token); |
if (_php_pgsql_detect_identifier_escape(token, len) == SUCCESS) { |
if (_php_pgsql_detect_identifier_escape(token, len) == SUCCESS) { |
escaped = _php_pgsql_strndup(token, len); | smart_str_appendl(querystr, token, len); |
} else { |
} else { |
#if HAVE_PQESCAPELITERAL | escaped = PGSQLescapeIdentifier(pg_link, token, len); |
escaped = PQescapeIdentifier(pg_link, token, len); | smart_str_appends(querystr, escaped); |
#else | PGSQLfree(escaped); |
escaped = _php_pgsql_escape_identifier(token, len); | |
#endif | |
} |
} |
smart_str_appends(querystr, escaped); |
|
free(escaped); |
|
if (tmp && *tmp) { |
if (tmp && *tmp) { |
len = strlen(tmp); |
len = strlen(tmp); |
/* "schema"."table" format */ |
/* "schema"."table" format */ |
if (_php_pgsql_detect_identifier_escape(tmp, len) == SUCCESS) { |
if (_php_pgsql_detect_identifier_escape(tmp, len) == SUCCESS) { |
escaped = _php_pgsql_strndup(tmp, len); | smart_str_appendc(querystr, '.'); |
| smart_str_appendl(querystr, tmp, len); |
} else { |
} else { |
#if HAVE_PQESCAPELITERAL | escaped = PGSQLescapeIdentifier(pg_link, tmp, len); |
escaped = PQescapeIdentifier(pg_link, tmp, len); | smart_str_appendc(querystr, '.'); |
#else | smart_str_appends(querystr, escaped); |
escaped = _php_pgsql_escape_identifier(tmp, len); | PGSQLfree(escaped); |
#endif | |
} |
} |
smart_str_appendc(querystr, '.'); |
|
smart_str_appends(querystr, escaped); |
|
free(escaped); |
|
} |
} |
efree(table_copy); |
efree(table_copy); |
} |
} |
Line 6258 no_values:
|
Line 6236 no_values:
|
|
|
cleanup: |
cleanup: |
if (!(opt & PGSQL_DML_NO_CONV) && converted) { |
if (!(opt & PGSQL_DML_NO_CONV) && converted) { |
zval_dtor(converted); | zval_dtor(converted); |
FREE_ZVAL(converted); |
FREE_ZVAL(converted); |
} |
} |
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { |
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { |
Line 6319 static inline int build_assignment_string(smart_str *q
|
Line 6297 static inline int build_assignment_string(smart_str *q
|
for (zend_hash_internal_pointer_reset_ex(ht, &pos); |
for (zend_hash_internal_pointer_reset_ex(ht, &pos); |
zend_hash_get_current_data_ex(ht, (void **)&val, &pos) == SUCCESS; |
zend_hash_get_current_data_ex(ht, (void **)&val, &pos) == SUCCESS; |
zend_hash_move_forward_ex(ht, &pos)) { |
zend_hash_move_forward_ex(ht, &pos)) { |
key_type = zend_hash_get_current_key_ex(ht, &fld, &fld_len, &num_idx, 0, &pos); | key_type = zend_hash_get_current_key_ex(ht, &fld, &fld_len, &num_idx, 0, &pos); |
if (key_type == HASH_KEY_IS_LONG) { |
if (key_type == HASH_KEY_IS_LONG) { |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects associative array for values to be inserted"); |
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects associative array for values to be inserted"); |
return -1; |
return -1; |
Line 6330 static inline int build_assignment_string(smart_str *q
|
Line 6308 static inline int build_assignment_string(smart_str *q
|
} else { |
} else { |
smart_str_appendc(querystr, '='); |
smart_str_appendc(querystr, '='); |
} |
} |
| |
switch(Z_TYPE_PP(val)) { |
switch(Z_TYPE_PP(val)) { |
case IS_STRING: |
case IS_STRING: |
smart_str_appendl(querystr, Z_STRVAL_PP(val), Z_STRLEN_PP(val)); |
smart_str_appendl(querystr, Z_STRVAL_PP(val), Z_STRLEN_PP(val)); |
Line 6459 PHP_FUNCTION(pg_update)
|
Line 6437 PHP_FUNCTION(pg_update)
|
RETURN_STRING(sql, 0); |
RETURN_STRING(sql, 0); |
} |
} |
RETURN_TRUE; |
RETURN_TRUE; |
} | } |
/* }}} */ |
/* }}} */ |
|
|
/* {{{ php_pgsql_delete |
/* {{{ php_pgsql_delete |
Line 6506 PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, co
|
Line 6484 PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, co
|
|
|
cleanup: |
cleanup: |
if (!(opt & PGSQL_DML_NO_CONV)) { |
if (!(opt & PGSQL_DML_NO_CONV)) { |
zval_dtor(ids_converted); | zval_dtor(ids_converted); |
FREE_ZVAL(ids_converted); |
FREE_ZVAL(ids_converted); |
} |
} |
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { |
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { |
Line 6610 PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, co
|
Line 6588 PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, co
|
assert(Z_TYPE_P(ids_array) == IS_ARRAY); |
assert(Z_TYPE_P(ids_array) == IS_ARRAY); |
assert(Z_TYPE_P(ret_array) == IS_ARRAY); |
assert(Z_TYPE_P(ret_array) == IS_ARRAY); |
assert(!(opt & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING))); |
assert(!(opt & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING))); |
| |
if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) { |
if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) { |
return FAILURE; |
return FAILURE; |
} |
} |
Line 6644 PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, co
|
Line 6622 PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, co
|
|
|
cleanup: |
cleanup: |
if (!(opt & PGSQL_DML_NO_CONV)) { |
if (!(opt & PGSQL_DML_NO_CONV)) { |
zval_dtor(ids_converted); | zval_dtor(ids_converted); |
FREE_ZVAL(ids_converted); |
FREE_ZVAL(ids_converted); |
} |
} |
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { |
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { |
Line 6692 PHP_FUNCTION(pg_select)
|
Line 6670 PHP_FUNCTION(pg_select)
|
RETURN_STRING(sql, 0); |
RETURN_STRING(sql, 0); |
} |
} |
return; |
return; |
} | } |
/* }}} */ |
/* }}} */ |
|
|
#endif |
#endif |