Permalink
Browse files

Merge branch 'PHP-5.5'

Conflicts:
	NEWS
  • Loading branch information...
2 parents 7a31692 + dc495bb commit c4fe37bd8c5e35d1957d43acecbcb3f010501e4a Andrey Hristov committed Jan 15, 2013
Showing with 1,305 additions and 131 deletions.
  1. +0 −1 NEWS
  2. +18 −0 Zend/zend_operators.c
  3. +2 −0 Zend/zend_operators.h
  4. +390 −67 ext/date/php_date.c
  5. +14 −0 ext/date/php_date.h
  6. +56 −0 ext/date/tests/date_period-immutable.phpt
  7. +25 −0 ext/date/tests/date_time_immutable-inherited.phpt
  8. +167 −0 ext/date/tests/date_time_immutable.phpt
  9. +10 −9 ext/dba/dba_flatfile.c
  10. +12 −5 ext/dba/dba_gdbm.c
  11. +0 −1 ext/dba/dba_inifile.c
  12. +6 −4 ext/dba/dba_qdbm.c
  13. +4 −0 ext/dba/tests/dba_db1.phpt
  14. +4 −0 ext/dba/tests/dba_db2.phpt
  15. +4 −0 ext/dba/tests/dba_db3.phpt
  16. +4 −0 ext/dba/tests/dba_db4_000.phpt
  17. +4 −0 ext/dba/tests/dba_dbm.phpt
  18. +4 −0 ext/dba/tests/dba_flatfile.phpt
  19. +2 −0 ext/dba/tests/dba_gdbm.phpt
  20. +10 −2 ext/dba/tests/dba_handler.inc
  21. +4 −0 ext/dba/tests/dba_inifile.phpt
  22. +4 −0 ext/dba/tests/dba_ndbm.phpt
  23. +2 −0 ext/dba/tests/dba_qdbm.phpt
  24. +4 −0 ext/dba/tests/dba_tcadb.phpt
  25. +90 −3 ext/mysqlnd/mysqlnd.c
  26. +1 −0 ext/mysqlnd/mysqlnd.h
  27. +4 −1 ext/mysqlnd/mysqlnd_auth.c
  28. +3 −0 ext/mysqlnd/mysqlnd_enum_n_def.h
  29. +2 −1 ext/mysqlnd/mysqlnd_libmysql_compat.h
  30. +5 −1 ext/mysqlnd/mysqlnd_structs.h
  31. +65 −1 ext/mysqlnd/mysqlnd_wireprotocol.c
  32. +1 −1 ext/mysqlnd/mysqlnd_wireprotocol.h
  33. +4 −2 ext/pdo_oci/oci_driver.c
  34. +1 −2 ext/pdo_oci/oci_statement.c
  35. +165 −0 ext/pdo_oci/tests/bug57702.phpt
  36. +6 −0 ext/pdo_sqlite/sqlite_statement.c
  37. +27 −0 ext/pdo_sqlite/tests/bug_63916-2.phpt
  38. +27 −0 ext/pdo_sqlite/tests/bug_63916.phpt
  39. +1 −1 ext/pgsql/pgsql.c
  40. +23 −0 ext/pgsql/tests/bug46408.phpt
  41. +5 −5 ext/spl/tests/SplFileObject_fputcsv.phpt
  42. +12 −0 ext/sqlite3/sqlite3.c
  43. +27 −0 ext/sqlite3/tests/bug63921-32bit.phpt
  44. +27 −0 ext/sqlite3/tests/bug63921-64bit.phpt
  45. +2 −6 ext/standard/file.c
  46. +1 −1 ext/standard/image.c
  47. +5 −5 ext/standard/tests/file/fputcsv.phpt
  48. +20 −0 ext/standard/tests/file/fputcsv_bug43225.phpt
  49. +16 −1 ext/standard/tests/image/getimagesize.phpt
  50. +6 −4 ext/standard/tests/image/image_type_to_mime_type.phpt
  51. BIN ext/standard/tests/image/test1bpix.bmp
  52. +5 −3 sapi/cli/php_cli_server.c
  53. +3 −3 sapi/cli/tests/php_cli_server_013.phpt
  54. +1 −1 sapi/cli/tests/php_cli_server_014.phpt
View
1 NEWS
@@ -1,6 +1,5 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-<<<<<<< HEAD
?? ??? 201?, PHP 5.6.0
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
View
18 Zend/zend_operators.c
@@ -572,6 +572,24 @@ ZEND_API void convert_to_boolean(zval *op) /* {{{ */
}
/* }}} */
+ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC) /* {{{ */
+{
+ double dval;
+ switch (Z_TYPE_P(op)) {
+ case IS_DOUBLE: {
+ TSRMLS_FETCH();
+ dval = Z_DVAL_P(op);
+ Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%.*H", (int) EG(precision), dval);
+ /* %H already handles removing trailing zeros from the fractional part, yay */
+ break;
+ }
+ default:
+ _convert_to_string(op ZEND_FILE_LINE_CC);
+ }
+ Z_TYPE_P(op) = IS_STRING;
+}
+/* }}} */
+
ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
{
long lval;
View
2 Zend/zend_operators.h
@@ -301,6 +301,7 @@ ZEND_API int increment_function(zval *op1);
ZEND_API int decrement_function(zval *op2);
ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC);
+ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC);
ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC);
ZEND_API void convert_to_long(zval *op);
ZEND_API void convert_to_double(zval *op);
@@ -314,6 +315,7 @@ ZEND_API void multi_convert_to_double_ex(int argc, ...);
ZEND_API void multi_convert_to_string_ex(int argc, ...);
ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2);
ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2);
+#define convert_to_cstring(op) if ((op)->type != IS_STRING) { _convert_to_cstring((op) ZEND_FILE_LINE_CC); }
#define convert_to_string(op) if ((op)->type != IS_STRING) { _convert_to_string((op) ZEND_FILE_LINE_CC); }
ZEND_API double zend_string_to_double(const char *number, zend_uint length);
View
457 ext/date/php_date.c
@@ -385,7 +385,9 @@ const zend_function_entry date_functions[] = {
/* Advanced Interface */
PHP_FE(date_create, arginfo_date_create)
+ PHP_FE(date_create_immutable, arginfo_date_create)
PHP_FE(date_create_from_format, arginfo_date_create_from_format)
+ PHP_FE(date_create_immutable_from_format, arginfo_date_create_from_format)
PHP_FE(date_parse, arginfo_date_parse)
PHP_FE(date_parse_from_format, arginfo_date_parse_from_format)
PHP_FE(date_get_last_errors, arginfo_date_get_last_errors)
@@ -450,6 +452,20 @@ const zend_function_entry date_funcs_date[] = {
PHP_FE_END
};
+const zend_function_entry date_funcs_immutable[] = {
+ PHP_ME(DateTimeImmutable, __construct, arginfo_date_create, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
+ PHP_ME(DateTimeImmutable, __set_state, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(DateTimeImmutable, modify, arginfo_date_method_modify, 0)
+ PHP_ME(DateTimeImmutable, add, arginfo_date_method_add, 0)
+ PHP_ME(DateTimeImmutable, sub, arginfo_date_method_sub, 0)
+ PHP_ME(DateTimeImmutable, setTimezone, arginfo_date_method_timezone_set, 0)
+ PHP_ME(DateTimeImmutable, setTime, arginfo_date_method_time_set, 0)
+ PHP_ME(DateTimeImmutable, setDate, arginfo_date_method_date_set, 0)
+ PHP_ME(DateTimeImmutable, setISODate, arginfo_date_method_isodate_set, 0)
+ PHP_ME(DateTimeImmutable, setTimestamp, arginfo_date_method_timestamp_set, 0)
+ PHP_FE_END
+};
+
const zend_function_entry date_funcs_timezone[] = {
PHP_ME(DateTimeZone, __construct, arginfo_timezone_open, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getName, timezone_name_get, arginfo_timezone_method_name_get, 0)
@@ -508,19 +524,26 @@ PHP_INI_END()
/* }}} */
zend_class_entry *date_ce_date, *date_ce_timezone, *date_ce_interval, *date_ce_period;
+zend_class_entry *date_ce_immutable;
PHPAPI zend_class_entry *php_date_get_date_ce(void)
{
return date_ce_date;
}
+PHPAPI zend_class_entry *php_date_get_immutable_ce(void)
+{
+ return date_ce_immutable;
+}
+
PHPAPI zend_class_entry *php_date_get_timezone_ce(void)
{
return date_ce_timezone;
}
static zend_object_handlers date_object_handlers_date;
+static zend_object_handlers date_object_handlers_immutable;
static zend_object_handlers date_object_handlers_timezone;
static zend_object_handlers date_object_handlers_interval;
static zend_object_handlers date_object_handlers_period;
@@ -555,11 +578,13 @@ static void date_object_free_storage_interval(void *object TSRMLS_DC);
static void date_object_free_storage_period(void *object TSRMLS_DC);
static zend_object_value date_object_new_date(zend_class_entry *class_type TSRMLS_DC);
+static zend_object_value date_object_new_immutable(zend_class_entry *class_type TSRMLS_DC);
static zend_object_value date_object_new_timezone(zend_class_entry *class_type TSRMLS_DC);
static zend_object_value date_object_new_interval(zend_class_entry *class_type TSRMLS_DC);
static zend_object_value date_object_new_period(zend_class_entry *class_type TSRMLS_DC);
static zend_object_value date_object_clone_date(zval *this_ptr TSRMLS_DC);
+static zend_object_value date_object_clone_immutable(zval *this_ptr TSRMLS_DC);
static zend_object_value date_object_clone_timezone(zval *this_ptr TSRMLS_DC);
static zend_object_value date_object_clone_interval(zval *this_ptr TSRMLS_DC);
static zend_object_value date_object_clone_period(zval *this_ptr TSRMLS_DC);
@@ -1822,7 +1847,7 @@ static void date_period_it_current_data(zend_object_iterator *iter, zval ***data
/* Create new object */
MAKE_STD_ZVAL(iterator->current);
- php_date_instantiate(date_ce_date, iterator->current TSRMLS_CC);
+ php_date_instantiate(object->start_ce, iterator->current TSRMLS_CC);
newdateobj = (php_date_obj *) zend_object_store_get_object(iterator->current TSRMLS_CC);
newdateobj->time = timelib_time_ctor();
*newdateobj->time = *it_time;
@@ -1908,7 +1933,7 @@ zend_object_iterator *date_object_period_get_iterator(zend_class_entry *ce, zval
static void date_register_classes(TSRMLS_D)
{
- zend_class_entry ce_date, ce_timezone, ce_interval, ce_period;
+ zend_class_entry ce_date, ce_immutable, ce_timezone, ce_interval, ce_period;
INIT_CLASS_ENTRY(ce_date, "DateTime", date_funcs_date);
ce_date.create_object = date_object_new_date;
@@ -1934,6 +1959,13 @@ static void date_register_classes(TSRMLS_D)
REGISTER_DATE_CLASS_CONST_STRING("RSS", DATE_FORMAT_RFC1123);
REGISTER_DATE_CLASS_CONST_STRING("W3C", DATE_FORMAT_RFC3339);
+ INIT_CLASS_ENTRY(ce_immutable, "DateTimeImmutable", date_funcs_immutable);
+ ce_immutable.create_object = date_object_new_date;
+ date_ce_immutable = zend_register_internal_class_ex(&ce_immutable, date_ce_date, "DateTime" TSRMLS_CC);
+ memcpy(&date_object_handlers_immutable, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ date_object_handlers_immutable.clone_obj = date_object_clone_date;
+ date_object_handlers_immutable.compare_objects = date_object_compare_date;
+ date_object_handlers_immutable.get_properties = date_object_get_properties;
INIT_CLASS_ENTRY(ce_timezone, "DateTimeZone", date_funcs_timezone);
ce_timezone.create_object = date_object_new_timezone;
@@ -2034,6 +2066,19 @@ static zend_object_value date_object_clone_date(zval *this_ptr TSRMLS_DC)
return new_ov;
}
+static zval* date_clone_immutable(zval *object)
+{
+ zval *new_object;
+
+ ALLOC_ZVAL(new_object);
+ Z_OBJVAL_P(new_object) = date_object_clone_date(object);
+ Z_SET_REFCOUNT_P(new_object, 1);
+ Z_SET_ISREF_P(new_object);
+ Z_TYPE_P(new_object) = IS_OBJECT;
+
+ return new_object;
+}
+
static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC)
{
if (Z_TYPE_P(d1) == IS_OBJECT && Z_TYPE_P(d2) == IS_OBJECT &&
@@ -2470,6 +2515,26 @@ PHP_FUNCTION(date_create)
}
/* }}} */
+/* {{{ proto DateTime date_create_immutable([string time[, DateTimeZone object]])
+ Returns new DateTime object
+*/
+PHP_FUNCTION(date_create_immutable)
+{
+ zval *timezone_object = NULL;
+ char *time_str = NULL;
+ int time_str_len = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_instantiate(date_ce_immutable, return_value TSRMLS_CC);
+ if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
/* {{{ proto DateTime date_create_from_format(string format, string time[, DateTimeZone object])
Returns new DateTime object formatted according to the specified format
*/
@@ -2490,6 +2555,26 @@ PHP_FUNCTION(date_create_from_format)
}
/* }}} */
+/* {{{ proto DateTime date_create_immutable_from_format(string format, string time[, DateTimeZone object])
+ Returns new DateTime object formatted according to the specified format
+*/
+PHP_FUNCTION(date_create_immutable_from_format)
+{
+ zval *timezone_object = NULL;
+ char *time_str = NULL, *format_str = NULL;
+ int time_str_len = 0, format_str_len = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|O", &format_str, &format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_instantiate(date_ce_immutable, return_value TSRMLS_CC);
+ if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
/* {{{ proto DateTime::__construct([string time[, DateTimeZone object]])
Creates new DateTime object
*/
@@ -2508,6 +2593,24 @@ PHP_METHOD(DateTime, __construct)
}
/* }}} */
+/* {{{ proto DateTimeImmutable::__construct([string time[, DateTimeZone object]])
+ Creates new DateTimeImmutable object
+*/
+PHP_METHOD(DateTimeImmutable, __construct)
+{
+ zval *timezone_object = NULL;
+ char *time_str = NULL;
+ int time_str_len = 0;
+ zend_error_handling error_handling;
+
+ zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
+ php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC);
+ }
+ zend_restore_error_handling(&error_handling TSRMLS_CC);
+}
+/* }}} */
+
static int php_date_initialize_from_hash(zval **return_value, php_date_obj **dateobj, HashTable *myht TSRMLS_DC)
{
zval **z_date = NULL;
@@ -2575,6 +2678,26 @@ PHP_METHOD(DateTime, __set_state)
}
/* }}} */
+/* {{{ proto DateTimeImmutable::__set_state()
+*/
+PHP_METHOD(DateTimeImmutable, __set_state)
+{
+ php_date_obj *dateobj;
+ zval *array;
+ HashTable *myht;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ myht = HASH_OF(array);
+
+ php_date_instantiate(date_ce_immutable, return_value TSRMLS_CC);
+ dateobj = (php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
+ php_date_initialize_from_hash(&return_value, &dateobj, myht TSRMLS_CC);
+}
+/* }}} */
+
/* {{{ proto DateTime::__wakeup()
*/
PHP_METHOD(DateTime, __wakeup)
@@ -2760,21 +2883,12 @@ PHP_FUNCTION(date_format)
}
/* }}} */
-/* {{{ proto DateTime date_modify(DateTime object, string modify)
- Alters the timestamp.
-*/
-PHP_FUNCTION(date_modify)
+static void php_date_modify(zval *object, char *modify, int modify_len, zval *return_value TSRMLS_DC)
{
- zval *object;
php_date_obj *dateobj;
- char *modify;
- int modify_len;
timelib_time *tmp_time;
timelib_error_container *err = NULL;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_date, &modify, &modify_len) == FAILURE) {
- RETURN_FALSE;
- }
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
@@ -2823,30 +2937,57 @@ PHP_FUNCTION(date_modify)
timelib_update_ts(dateobj->time, NULL);
timelib_update_from_sse(dateobj->time);
dateobj->time->have_relative = 0;
+}
+
+/* {{{ proto DateTime date_modify(DateTime object, string modify)
+ Alters the timestamp.
+*/
+PHP_FUNCTION(date_modify)
+{
+ zval *object;
+ char *modify;
+ int modify_len;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_date, &modify, &modify_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_modify(object, modify, modify_len, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
-/* {{{ proto DateTime date_add(DateTime object, DateInterval interval)
- Adds an interval to the current date in object.
+/* {{{ proto DateTimeImmutable::modify()
*/
-PHP_FUNCTION(date_add)
+PHP_METHOD(DateTimeImmutable, modify)
{
- zval *object, *interval;
- php_date_obj *dateobj;
- php_interval_obj *intobj;
- int bias = 1;
+ zval *object, *new_object;
+ char *modify;
+ int modify_len;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &interval, date_ce_interval) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_date, &modify, &modify_len) == FAILURE) {
RETURN_FALSE;
}
+
+ new_object = date_clone_immutable(object);
+ php_date_modify(new_object, modify, modify_len, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
+static void php_date_add(zval *object, zval *interval, zval *return_value TSRMLS_DC)
+{
+ php_date_obj *dateobj;
+ php_interval_obj *intobj;
+ int bias = 1;
+
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
intobj = (php_interval_obj *) zend_object_store_get_object(interval TSRMLS_CC);
DATE_CHECK_INITIALIZED(intobj->initialized, DateInterval);
-
if (intobj->diff->have_weekday_relative || intobj->diff->have_special_relative) {
memcpy(&dateobj->time->relative, intobj->diff, sizeof(struct timelib_rel_time));
} else {
@@ -2867,24 +3008,48 @@ PHP_FUNCTION(date_add)
timelib_update_ts(dateobj->time, NULL);
timelib_update_from_sse(dateobj->time);
dateobj->time->have_relative = 0;
+}
+
+/* {{{ proto DateTime date_add(DateTime object, DateInterval interval)
+ Adds an interval to the current date in object.
+*/
+PHP_FUNCTION(date_add)
+{
+ zval *object, *interval;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &interval, date_ce_interval) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_add(object, interval, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
-/* {{{ proto DateTime date_sub(DateTime object, DateInterval interval)
- Subtracts an interval to the current date in object.
+/* {{{ proto DateTimeImmutable::add()
*/
-PHP_FUNCTION(date_sub)
+PHP_METHOD(DateTimeImmutable, add)
{
- zval *object, *interval;
- php_date_obj *dateobj;
- php_interval_obj *intobj;
- int bias = 1;
+ zval *object, *interval, *new_object;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &interval, date_ce_interval) == FAILURE) {
RETURN_FALSE;
}
+
+ new_object = date_clone_immutable(object);
+ php_date_add(new_object, interval, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
+static void php_date_sub(zval *object, zval *interval, zval *return_value TSRMLS_DC)
+{
+ php_date_obj *dateobj;
+ php_interval_obj *intobj;
+ int bias = 1;
+
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
intobj = (php_interval_obj *) zend_object_store_get_object(interval TSRMLS_CC);
@@ -2913,11 +3078,42 @@ PHP_FUNCTION(date_sub)
timelib_update_from_sse(dateobj->time);
dateobj->time->have_relative = 0;
+}
+
+/* {{{ proto DateTime date_sub(DateTime object, DateInterval interval)
+ Subtracts an interval to the current date in object.
+*/
+PHP_FUNCTION(date_sub)
+{
+ zval *object, *interval;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &interval, date_ce_interval) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_sub(object, interval, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
+/* {{{ proto DateTimeImmutable::sub()
+*/
+PHP_METHOD(DateTimeImmutable, sub)
+{
+ zval *object, *interval, *new_object;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &interval, date_ce_interval) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ new_object = date_clone_immutable(object);
+ php_date_sub(new_object, interval, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
/* {{{ proto DateTimeZone date_timezone_get(DateTime object)
Return new DateTimeZone object relative to give DateTime
*/
@@ -2956,19 +3152,11 @@ PHP_FUNCTION(date_timezone_get)
}
/* }}} */
-/* {{{ proto DateTime date_timezone_set(DateTime object, DateTimeZone object)
- Sets the timezone for the DateTime object.
-*/
-PHP_FUNCTION(date_timezone_set)
+static void php_date_timezone_set(zval *object, zval *timezone_object, zval *return_value TSRMLS_DC)
{
- zval *object;
- zval *timezone_object;
php_date_obj *dateobj;
php_timezone_obj *tzobj;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &timezone_object, date_ce_timezone) == FAILURE) {
- RETURN_FALSE;
- }
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone_object TSRMLS_CC);
@@ -2978,11 +3166,44 @@ PHP_FUNCTION(date_timezone_set)
}
timelib_set_timezone(dateobj->time, tzobj->tzi.tz);
timelib_unixtime2local(dateobj->time, dateobj->time->sse);
+}
+
+/* {{{ proto DateTime date_timezone_set(DateTime object, DateTimeZone object)
+ Sets the timezone for the DateTime object.
+*/
+PHP_FUNCTION(date_timezone_set)
+{
+ zval *object;
+ zval *timezone_object;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &timezone_object, date_ce_timezone) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_timezone_set(object, timezone_object, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
+/* {{{ proto DateTimeImmutable::setTimezone()
+*/
+PHP_METHOD(DateTimeImmutable, setTimezone)
+{
+ zval *object, *new_object;
+ zval *timezone_object;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_date, &timezone_object, date_ce_timezone) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ new_object = date_clone_immutable(object);
+ php_date_timezone_set(new_object, timezone_object, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
/* {{{ proto long date_offset_get(DateTime object)
Returns the DST offset.
*/
@@ -3018,64 +3239,106 @@ PHP_FUNCTION(date_offset_get)
}
/* }}} */
-/* {{{ proto DateTime date_time_set(DateTime object, long hour, long minute[, long second])
- Sets the time.
-*/
-PHP_FUNCTION(date_time_set)
+static void php_date_time_set(zval *object, long h, long i, long s, zval *return_value TSRMLS_DC)
{
- zval *object;
php_date_obj *dateobj;
- long h, i, s = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &h, &i, &s) == FAILURE) {
- RETURN_FALSE;
- }
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
dateobj->time->h = h;
dateobj->time->i = i;
dateobj->time->s = s;
timelib_update_ts(dateobj->time, NULL);
+}
+
+/* {{{ proto DateTime date_time_set(DateTime object, long hour, long minute[, long second])
+ Sets the time.
+*/
+PHP_FUNCTION(date_time_set)
+{
+ zval *object;
+ long h, i, s = 0;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &h, &i, &s) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_time_set(object, h, i, s, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
-/* {{{ proto DateTime date_date_set(DateTime object, long year, long month, long day)
- Sets the date.
+/* {{{ proto DateTimeImmutable::setTime()
*/
-PHP_FUNCTION(date_date_set)
+PHP_METHOD(DateTimeImmutable, setTime)
{
- zval *object;
- php_date_obj *dateobj;
- long y, m, d;
+ zval *object, *new_object;
+ long h, i, s = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olll", &object, date_ce_date, &y, &m, &d) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &h, &i, &s) == FAILURE) {
RETURN_FALSE;
}
+
+ new_object = date_clone_immutable(object);
+ php_date_time_set(new_object, h, i, s, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
+static void php_date_date_set(zval *object, long y, long m, long d, zval *return_value TSRMLS_DC)
+{
+ php_date_obj *dateobj;
+
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
dateobj->time->y = y;
dateobj->time->m = m;
dateobj->time->d = d;
timelib_update_ts(dateobj->time, NULL);
+}
+
+/* {{{ proto DateTime date_date_set(DateTime object, long year, long month, long day)
+ Sets the date.
+*/
+PHP_FUNCTION(date_date_set)
+{
+ zval *object;
+ long y, m, d;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olll", &object, date_ce_date, &y, &m, &d) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_date_set(object, y, m, d, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
-/* {{{ proto DateTime date_isodate_set(DateTime object, long year, long week[, long day])
- Sets the ISO date.
+/* {{{ proto DateTimeImmutable::setDate()
*/
-PHP_FUNCTION(date_isodate_set)
+PHP_METHOD(DateTimeImmutable, setDate)
{
- zval *object;
- php_date_obj *dateobj;
- long y, w, d = 1;
+ zval *object, *new_object;
+ long y, m, d;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &y, &w, &d) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olll", &object, date_ce_date, &y, &m, &d) == FAILURE) {
RETURN_FALSE;
}
+
+ new_object = date_clone_immutable(object);
+ php_date_date_set(new_object, y, m, d, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
+static void php_date_isodate_set(zval *object, long y, long w, long d, zval *return_value TSRMLS_DC)
+{
+ php_date_obj *dateobj;
+
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
dateobj->time->y = y;
@@ -3086,32 +3349,90 @@ PHP_FUNCTION(date_isodate_set)
dateobj->time->have_relative = 1;
timelib_update_ts(dateobj->time, NULL);
+}
+
+/* {{{ proto DateTime date_isodate_set(DateTime object, long year, long week[, long day])
+ Sets the ISO date.
+*/
+PHP_FUNCTION(date_isodate_set)
+{
+ zval *object;
+ long y, w, d = 1;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &y, &w, &d) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_isodate_set(object, y, w, d, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
-/* {{{ proto DateTime date_timestamp_set(DateTime object, long unixTimestamp)
- Sets the date and time based on an Unix timestamp.
+/* {{{ proto DateTimeImmutable::setISODate()
*/
-PHP_FUNCTION(date_timestamp_set)
+PHP_METHOD(DateTimeImmutable, setISODate)
{
- zval *object;
- php_date_obj *dateobj;
- long timestamp;
+ zval *object, *new_object;
+ long y, w, d = 1;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, date_ce_date, &timestamp) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &y, &w, &d) == FAILURE) {
RETURN_FALSE;
}
+
+ new_object = date_clone_immutable(object);
+ php_date_isodate_set(new_object, y, w, d, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
+static void php_date_timestamp_set(zval *object, long timestamp, zval *return_value TSRMLS_DC)
+{
+ php_date_obj *dateobj;
+
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
timelib_unixtime2local(dateobj->time, (timelib_sll)timestamp);
timelib_update_ts(dateobj->time, NULL);
+}
+
+/* {{{ proto DateTime date_timestamp_set(DateTime object, long unixTimestamp)
+ Sets the date and time based on an Unix timestamp.
+*/
+PHP_FUNCTION(date_timestamp_set)
+{
+ zval *object;
+ long timestamp;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, date_ce_date, &timestamp) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_date_timestamp_set(object, timestamp, return_value TSRMLS_CC);
RETURN_ZVAL(object, 1, 0);
}
/* }}} */
+/* {{{ proto DateTimeImmutable::setTimestamp()
+*/
+PHP_METHOD(DateTimeImmutable, setTimestamp)
+{
+ zval *object, *new_object;
+ long timestamp;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, date_ce_date, &timestamp) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ new_object = date_clone_immutable(object);
+ php_date_timestamp_set(new_object, timestamp, return_value TSRMLS_CC);
+
+ RETURN_ZVAL(new_object, 0, 1);
+}
+/* }}} */
+
/* {{{ proto long date_timestamp_get(DateTime object)
Gets the Unix timestamp.
*/
@@ -3861,6 +4182,7 @@ PHP_METHOD(DatePeriod, __construct)
if (dpobj->end) {
timelib_update_ts(dpobj->end, NULL);
}
+ dpobj->start_ce = date_ce_date;
} else {
/* init */
intobj = (php_interval_obj *) zend_object_store_get_object(interval TSRMLS_CC);
@@ -3876,6 +4198,7 @@ PHP_METHOD(DatePeriod, __construct)
clone->tz_info = dateobj->time->tz_info;
}
dpobj->start = clone;
+ dpobj->start_ce = Z_OBJCE_P(start);
/* interval */
dpobj->interval = timelib_rel_time_clone(intobj->diff);
View
14 ext/date/php_date.h
@@ -51,7 +51,9 @@ PHP_METHOD(DateTime, __construct);
PHP_METHOD(DateTime, __wakeup);
PHP_METHOD(DateTime, __set_state);
PHP_FUNCTION(date_create);
+PHP_FUNCTION(date_create_immutable);
PHP_FUNCTION(date_create_from_format);
+PHP_FUNCTION(date_create_immutable_from_format);
PHP_FUNCTION(date_parse);
PHP_FUNCTION(date_parse_from_format);
PHP_FUNCTION(date_get_last_errors);
@@ -70,6 +72,17 @@ PHP_FUNCTION(date_isodate_set);
PHP_FUNCTION(date_timestamp_set);
PHP_FUNCTION(date_timestamp_get);
+PHP_METHOD(DateTimeImmutable, __construct);
+PHP_METHOD(DateTimeImmutable, __set_state);
+PHP_METHOD(DateTimeImmutable, modify);
+PHP_METHOD(DateTimeImmutable, add);
+PHP_METHOD(DateTimeImmutable, sub);
+PHP_METHOD(DateTimeImmutable, setTimezone);
+PHP_METHOD(DateTimeImmutable, setTime);
+PHP_METHOD(DateTimeImmutable, setDate);
+PHP_METHOD(DateTimeImmutable, setISODate);
+PHP_METHOD(DateTimeImmutable, setTimestamp);
+
PHP_METHOD(DateTimeZone, __construct);
PHP_FUNCTION(timezone_open);
PHP_FUNCTION(timezone_name_get);
@@ -141,6 +154,7 @@ struct _php_interval_obj {
struct _php_period_obj {
zend_object std;
timelib_time *start;
+ zend_class_entry *start_ce;
timelib_time *current;
timelib_time *end;
timelib_rel_time *interval;
View
56 ext/date/tests/date_period-immutable.phpt
@@ -0,0 +1,56 @@
+--TEST--
+DatePeriod
+--FILE--
+<?php
+date_default_timezone_set('UTC');
+$db1 = new DateTimeImmutable( '2008-01-01' );
+$db2 = new DateTime( '2008-01-01' );
+$de = new DateTime( '2008-03-31' );
+$di = DateInterval::createFromDateString( 'first day of next month' );
+
+foreach ( new DatePeriod( $db1, $di, $de ) as $dt )
+{
+ echo get_class( $dt ), "\n";
+ echo $dt->format( "l Y-m-d\n" );
+ echo $dt->modify( "3 tuesday" )->format( "l Y-m-d\n" );
+ echo $dt->format( "l Y-m-d\n\n" );
+}
+
+foreach ( new DatePeriod( $db2, $di, $de ) as $dt )
+{
+ echo get_class( $dt ), "\n";
+ echo $dt->format( "l Y-m-d\n" );
+ echo $dt->modify( "3 tuesday" )->format( "l Y-m-d\n" );
+ echo $dt->format( "l Y-m-d\n\n" );
+}
+?>
+--EXPECT--
+DateTimeImmutable
+Tuesday 2008-01-01
+Tuesday 2008-01-15
+Tuesday 2008-01-01
+
+DateTimeImmutable
+Friday 2008-02-01
+Tuesday 2008-02-19
+Friday 2008-02-01
+
+DateTimeImmutable
+Saturday 2008-03-01
+Tuesday 2008-03-18
+Saturday 2008-03-01
+
+DateTime
+Tuesday 2008-01-01
+Tuesday 2008-01-15
+Tuesday 2008-01-15
+
+DateTime
+Friday 2008-02-01
+Tuesday 2008-02-19
+Tuesday 2008-02-19
+
+DateTime
+Saturday 2008-03-01
+Tuesday 2008-03-18
+Tuesday 2008-03-18
View
25 ext/date/tests/date_time_immutable-inherited.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Tests for DateTimeImmutable.
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+$tz = new DateTimeZone("Asia/Tokyo");
+$current = "2012-12-27 16:24:08";
+
+echo "\ngetTimezone():\n";
+$v = date_create_immutable($current);
+$x = $v->getTimezone();
+var_dump($x->getName());
+
+echo "\ngetTimestamp():\n";
+$v = date_create_immutable($current);
+$x = $v->getTimestamp();
+var_dump($x);
+?>
+--EXPECT--
+getTimezone():
+string(13) "Europe/London"
+
+getTimestamp():
+int(1356625448)
View
167 ext/date/tests/date_time_immutable.phpt
@@ -0,0 +1,167 @@
+--TEST--
+Tests for DateTimeImmutable.
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+$tz = new DateTimeZone("Asia/Tokyo");
+$current = "2012-12-27 16:24:08";
+
+function dump($a, $b, $c)
+{
+ echo 'orig: ', $a->format('Y-m-d H:i:s e'), "\n";
+ echo 'copy: ', $b->format('Y-m-d H:i:s e'), "\n";
+ echo 'changed: ', $c->format('Y-m-d H:i:s e'), "\n";
+}
+
+echo "modify():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->modify("+2 days");
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->modify("+2 days");
+dump($v, $z, $x);
+
+echo "\nadd():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->add(new DateInterval("P2DT2S"));
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->add(new DateInterval("P2DT2S"));
+dump($v, $z, $x);
+
+echo "\nsub():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->sub(new DateInterval("P2DT2S"));
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->sub(new DateInterval("P2DT2S"));
+dump($v, $z, $x);
+
+echo "\nsetTimezone():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->setTimezone($tz);
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->setTimezone($tz);
+dump($v, $z, $x);
+$v = new DateTimeImmutable($current);
+$z = $v;
+$x = $z->setTimezone($tz);
+dump($v, $z, $x);
+
+echo "\nsetTime():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->setTime(5, 7, 19);
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->setTime(5, 7, 19);
+dump($v, $z, $x);
+
+echo "\nsetDate():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->setDate(5, 7, 19);
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->setDate(5, 7, 19);
+dump($v, $z, $x);
+
+echo "\nsetIsoDate():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->setIsoDate(2012, 2, 6);
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->setIsoDate(2012, 2, 6);
+dump($v, $z, $x);
+
+echo "\nsetTimestamp():\n";
+$v = date_create_immutable($current);
+$z = $v;
+$x = $z->setTimestamp(2012234222);
+dump($v, $z, $x);
+$v = date_create($current);
+$z = $v;
+$x = $z->setTimestamp(2012234222);
+dump($v, $z, $x);
+?>
+--EXPECT--
+modify():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2012-12-29 16:24:08 Europe/London
+orig: 2012-12-29 16:24:08 Europe/London
+copy: 2012-12-29 16:24:08 Europe/London
+changed: 2012-12-29 16:24:08 Europe/London
+
+add():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2012-12-29 16:24:10 Europe/London
+orig: 2012-12-29 16:24:10 Europe/London
+copy: 2012-12-29 16:24:10 Europe/London
+changed: 2012-12-29 16:24:10 Europe/London
+
+sub():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2012-12-25 16:24:06 Europe/London
+orig: 2012-12-25 16:24:06 Europe/London
+copy: 2012-12-25 16:24:06 Europe/London
+changed: 2012-12-25 16:24:06 Europe/London
+
+setTimezone():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2012-12-28 01:24:08 Asia/Tokyo
+orig: 2012-12-28 01:24:08 Asia/Tokyo
+copy: 2012-12-28 01:24:08 Asia/Tokyo
+changed: 2012-12-28 01:24:08 Asia/Tokyo
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2012-12-28 01:24:08 Asia/Tokyo
+
+setTime():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2012-12-27 05:07:19 Europe/London
+orig: 2012-12-27 05:07:19 Europe/London
+copy: 2012-12-27 05:07:19 Europe/London
+changed: 2012-12-27 05:07:19 Europe/London
+
+setDate():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 0005-07-19 16:24:08 Europe/London
+orig: 0005-07-19 16:24:08 Europe/London
+copy: 0005-07-19 16:24:08 Europe/London
+changed: 0005-07-19 16:24:08 Europe/London
+
+setIsoDate():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2012-01-14 16:24:08 Europe/London
+orig: 2012-01-14 16:24:08 Europe/London
+copy: 2012-01-14 16:24:08 Europe/London
+changed: 2012-01-14 16:24:08 Europe/London
+
+setTimestamp():
+orig: 2012-12-27 16:24:08 Europe/London
+copy: 2012-12-27 16:24:08 Europe/London
+changed: 2033-10-06 18:57:02 Europe/London
+orig: 2033-10-06 18:57:02 Europe/London
+copy: 2033-10-06 18:57:02 Europe/London
+changed: 2033-10-06 18:57:02 Europe/London
View
19 ext/dba/dba_flatfile.c
@@ -88,15 +88,16 @@ DBA_UPDATE_FUNC(flatfile)
gval.dsize = vallen;
switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) {
- case -1:
- php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
- return FAILURE;
- default:
- case 0:
- return SUCCESS;
- case 1:
- php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
- return FAILURE;
+ case 0:
+ return SUCCESS;
+ case 1:
+ return FAILURE;
+ case -1:
+ php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
+ return FAILURE;
+ default:
+ php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Unknown return value");
+ return FAILURE;
}
}
View
17 ext/dba/dba_gdbm.c
@@ -104,11 +104,18 @@ DBA_UPDATE_FUNC(gdbm)
gval.dptr = (char *) val;
gval.dsize = vallen;
- if(gdbm_store(dba->dbf, gkey, gval,
- mode == 1 ? GDBM_INSERT : GDBM_REPLACE) == 0)
- return SUCCESS;
- php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno));
- return FAILURE;
+ switch (gdbm_store(dba->dbf, gkey, gval, mode == 1 ? GDBM_INSERT : GDBM_REPLACE)) {
+ case 0:
+ return SUCCESS;
+ case 1:
+ return FAILURE;
+ case -1:
+ php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno));
+ return FAILURE;
+ default:
+ php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Unknown return value");
+ return FAILURE;
+ }
}
DBA_EXISTS_FUNC(gdbm)
View
1 ext/dba/dba_inifile.c
@@ -101,7 +101,6 @@ DBA_UPDATE_FUNC(inifile)
case 0:
return SUCCESS;
case 1:
- php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
return FAILURE;
}
}
View
10 ext/dba/dba_qdbm.c
@@ -96,13 +96,15 @@ DBA_FETCH_FUNC(qdbm)
DBA_UPDATE_FUNC(qdbm)
{
QDBM_DATA;
- int result;
- result = dpput(dba->dbf, key, keylen, val, vallen, mode == 1 ? DP_DKEEP : DP_DOVER);
- if (result)
+ if (dpput(dba->dbf, key, keylen, val, vallen, mode == 1 ? DP_DKEEP : DP_DOVER)) {
return SUCCESS;
+ }
+
+ if (dpecode != DP_EKEEP) {
+ php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", dperrmsg(dpecode));
+ }
- php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", dperrmsg(dpecode));
return FAILURE;
}
View
4 ext/dba/tests/dba_db1.phpt
@@ -18,6 +18,8 @@ database handler: db1
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -33,6 +35,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
4 ext/dba/tests/dba_db2.phpt
@@ -18,6 +18,8 @@ database handler: db2
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -33,6 +35,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
4 ext/dba/tests/dba_db3.phpt
@@ -18,6 +18,8 @@ database handler: db3
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -33,6 +35,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
4 ext/dba/tests/dba_db4_000.phpt
@@ -22,6 +22,8 @@ database handler: db4
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -37,6 +39,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
4 ext/dba/tests/dba_dbm.phpt
@@ -18,6 +18,8 @@ database handler: dbm
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -33,6 +35,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
4 ext/dba/tests/dba_flatfile.phpt
@@ -22,6 +22,8 @@ database handler: flatfile
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -37,6 +39,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
2 ext/dba/tests/dba_gdbm.phpt
@@ -21,6 +21,8 @@ database handler: gdbm
Content String 2
Content 2 replaced
Read during write:%sallowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
12 ext/dba/tests/dba_handler.inc
@@ -46,8 +46,16 @@ do {
echo "Read during write: allowed\n";
}
if ($db_writer!==FALSE) {
- dba_insert("key number 6", "The 6th value", $db_writer);
- @dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer);
+ if (dba_insert("key number 6", "The 6th value", $db_writer)) {
+ echo '"key number 6" written' . "\n";
+ } else {
+ echo 'Failed to write "key number 6"' . "\n";
+ }
+ if (dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer)) {
+ echo '"key number 6" written 2nd time' . "\n";
+ } else {
+ echo 'Failed to write "key number 6" 2nd time' . "\n";
+ }
dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
dba_delete("key4", $db_writer);
echo dba_fetch("key2", $db_writer)."\n";
View
4 ext/dba/tests/dba_inifile.phpt
@@ -18,6 +18,8 @@ database handler: inifile
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -33,6 +35,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
4 ext/dba/tests/dba_ndbm.phpt
@@ -18,6 +18,8 @@ database handler: ndbm
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -33,6 +35,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
2 ext/dba/tests/dba_qdbm.phpt
@@ -19,6 +19,8 @@ database handler: qdbm
Content String 2
Content 2 replaced
Read during write:%sallowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
4 ext/dba/tests/dba_tcadb.phpt
@@ -22,6 +22,8 @@ database handler: tcadb
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
@@ -37,6 +39,8 @@ array(3) {
Content String 2
Content 2 replaced
Read during write: not allowed
+"key number 6" written
+Failed to write "key number 6" 2nd time
Content 2 replaced 2nd time
The 6th value
array(3) {
View
93 ext/mysqlnd/mysqlnd.c
@@ -95,6 +95,11 @@ MYSQLND_METHOD(mysqlnd_conn_data, free_options)(MYSQLND_CONN_DATA * conn TSRMLS_
mnd_pefree(conn->options->cfg_section, pers);
conn->options->cfg_section = NULL;
}
+ if (conn->options->connect_attr) {
+ zend_hash_destroy(conn->options->connect_attr);
+ mnd_pefree(conn->options->connect_attr, pers);
+ conn->options->connect_attr = NULL;
+ }
}
/* }}} */
@@ -797,20 +802,23 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect_handshake)(MYSQLND_CONN_DATA * conn,
goto err;
}
+ conn->client_flag = mysql_flags;
+ conn->server_capabilities = greet_packet->server_capabilities;
+
if (FAIL == mysqlnd_connect_run_authentication(conn, user, passwd, db, db_len, (size_t) passwd_len,
greet_packet, conn->options, mysql_flags TSRMLS_CC))
{
goto err;
}
- conn->client_flag = mysql_flags;
- conn->server_capabilities = greet_packet->server_capabilities;
conn->upsert_status->warning_count = 0;
conn->upsert_status->server_status = greet_packet->server_status;
conn->upsert_status->affected_rows = 0;
PACKET_FREE(greet_packet);
DBG_RETURN(PASS);
err:
+ conn->client_flag = 0;
+ conn->server_capabilities = 0;
PACKET_FREE(greet_packet);
DBG_RETURN(FAIL);
}
@@ -1086,6 +1094,7 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn_handle,
DBG_ENTER("mysqlnd_conn::connect");
if (PASS == conn->m->local_tx_start(conn, this_func TSRMLS_CC)) {
+ mysqlnd_options4(conn_handle, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_name", "mysqlnd");
ret = conn->m->connect(conn, host, user, passwd, passwd_len, db, db_len, port, socket_or_pipe, mysql_flags TSRMLS_CC);
conn->m->local_tx_end(conn, this_func, FAIL TSRMLS_CC);
@@ -2375,6 +2384,19 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const c
conn->options->flags &= ~CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS;
}
break;
+ case MYSQL_OPT_CONNECT_ATTR_RESET:
+ if (conn->options->connect_attr) {
+ DBG_INF_FMT("Before reset %d attribute(s)", zend_hash_num_elements(conn->options->connect_attr));
+ zend_hash_clean(conn->options->connect_attr);
+ }
+ break;
+ case MYSQL_OPT_CONNECT_ATTR_DELETE:
+ if (conn->options->connect_attr && value) {
+ DBG_INF_FMT("Before delete %d attribute(s)", zend_hash_num_elements(conn->options->connect_attr));
+ zend_hash_del(conn->options->connect_attr, value, strlen(value));
+ DBG_INF_FMT("%d left", zend_hash_num_elements(conn->options->connect_attr));
+ }
+ break;
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_SHARED_MEMORY_BASE_NAME:
case MYSQL_OPT_USE_RESULT:
@@ -2395,6 +2417,69 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const c
/* }}} */
+/* {{{ connect_attr_item_dtor */
+static void
+connect_attr_item_dtor(void * pDest)
+{
+#ifdef ZTS
+ TSRMLS_FETCH();
+#endif
+ DBG_ENTER("connect_attr_item_dtor");
+ mnd_pefree(*(char **) pDest, 1);
+ DBG_VOID_RETURN;
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_conn_data::set_client_option_2d */
+static enum_func_status
+MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA * const conn,
+ enum mysqlnd_option option,
+ const char * const key,
+ const char * const value
+ TSRMLS_DC)
+{
+ size_t this_func = STRUCT_OFFSET(struct st_mysqlnd_conn_data_methods, set_client_option_2d);
+ enum_func_status ret = PASS;
+ DBG_ENTER("mysqlnd_conn_data::set_client_option_2d");
+ DBG_INF_FMT("conn=%llu option=%u", conn->thread_id, option);
+
+ if (PASS != conn->m->local_tx_start(conn, this_func TSRMLS_CC)) {
+ goto end;
+ }
+ switch (option) {
+ case MYSQL_OPT_CONNECT_ATTR_ADD:
+ if (!conn->options->connect_attr) {
+ DBG_INF("Initializing connect_attr hash");
+ conn->options->connect_attr = mnd_pemalloc(sizeof(HashTable), conn->persistent);
+ if (!conn->options->connect_attr) {
+ goto oom;
+ }
+ zend_hash_init(conn->options->connect_attr, 0, NULL, NULL, conn->persistent);
+ }
+ DBG_INF_FMT("Adding [%s][%s]", key, value);
+ {
+ const char * copyv = mnd_pestrdup(value, 1);
+ if (!copyv) {
+ goto oom;
+ }
+ zend_hash_update(conn->options->connect_attr, key, strlen(key), &copyv, sizeof(char *), NULL);
+ }
+ break;
+ default:
+ ret = FAIL;
+ }
+ conn->m->local_tx_end(conn, this_func, ret TSRMLS_CC);
+ DBG_RETURN(ret);
+oom:
+ SET_OOM_ERROR(*conn->error_info);
+ conn->m->local_tx_end(conn, this_func, FAIL TSRMLS_CC);
+end:
+ DBG_RETURN(FAIL);
+}
+/* }}} */
+
+
/* {{{ mysqlnd_conn_data::use_result */
static MYSQLND_RES *
MYSQLND_METHOD(mysqlnd_conn_data, use_result)(MYSQLND_CONN_DATA * const conn TSRMLS_DC)
@@ -2662,7 +2747,9 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_conn_data)
MYSQLND_METHOD(mysqlnd_conn_data, get_updated_connect_flags),
MYSQLND_METHOD(mysqlnd_conn_data, connect_handshake),
MYSQLND_METHOD(mysqlnd_conn_data, simple_command_send_request),
- MYSQLND_METHOD(mysqlnd_conn_data, fetch_auth_plugin_by_name)
+ MYSQLND_METHOD(mysqlnd_conn_data, fetch_auth_plugin_by_name),
+
+ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)
MYSQLND_CLASS_METHODS_END;
View
1 ext/mysqlnd/mysqlnd.h
@@ -207,6 +207,7 @@ PHPAPI void mysqlnd_set_local_infile_handler(MYSQLND_CONN_DATA * const conn, con
#define mysqlnd_set_character_set(conn, cs) ((conn)->data)->m->set_charset((conn)->data, (cs) TSRMLS_CC)
#define mysqlnd_stat(conn, msg, msg_len) ((conn)->data)->m->get_server_statistics(((conn)->data), (msg), (msg_len) TSRMLS_CC)
#define mysqlnd_options(conn, opt, value) ((conn)->data)->m->set_client_option((conn)->data, (opt), (value) TSRMLS_CC)
+#define mysqlnd_options4(conn, opt, k, v) ((conn)->data)->m->set_client_option_2d((conn)->data, (opt), (k), (v) TSRMLS_CC)
#define mysqlnd_set_server_option(conn, op) ((conn)->data)->m->set_server_option((conn)->data, (op) TSRMLS_CC)
/* Escaping */
View
5 ext/mysqlnd/mysqlnd_auth.c
@@ -28,7 +28,6 @@
#include "mysqlnd_charset.h"
#include "mysqlnd_debug.h"
-
/* {{{ mysqlnd_auth_handshake */
enum_func_status
mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
@@ -99,6 +98,10 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
auth_packet->auth_data = auth_plugin_data;
auth_packet->auth_data_len = auth_plugin_data_len;
auth_packet->auth_plugin_name = auth_protocol;
+
+ if (conn->server_capabilities & CLIENT_CONNECT_ATTRS) {
+ auth_packet->connect_attr = conn->options->connect_attr;
+ }
if (!PACKET_WRITE(auth_packet, conn)) {
goto end;
View
3 ext/mysqlnd/mysqlnd_enum_n_def.h
@@ -168,6 +168,9 @@ typedef enum mysqlnd_option
MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
MYSQL_PLUGIN_DIR,
MYSQL_DEFAULT_AUTH,
+ MYSQL_OPT_CONNECT_ATTR_RESET,
+ MYSQL_OPT_CONNECT_ATTR_ADD,
+ MYSQL_OPT_CONNECT_ATTR_DELETE,
MYSQL_SERVER_PUBLIC_KEY,
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
View
3 ext/mysqlnd/mysqlnd_libmysql_compat.h
@@ -106,7 +106,8 @@
#define mysql_stmt_more_results(s) mysqlnd_stmt_more_results((s))
#define mysql_thread_safe() mysqlnd_thread_safe()
#define mysql_info(r) mysqlnd_info((r))
-#define mysql_options(r,a,b) mysqlnd_options((r), (a), (b))
+#define mysql_options(c,a,v) mysqlnd_options((c), (a), (v))
+#define mysql_options4(c,a,k,v) mysqlnd_options4((c), (a), (k), (v))
#define mysql_stmt_init(r) mysqlnd_stmt_init((r))
#define mysql_free_result(r) mysqlnd_free_result((r), FALSE)
#define mysql_store_result(r) mysqlnd_store_result((r))
View
6 ext/mysqlnd/mysqlnd_structs.h
@@ -172,7 +172,7 @@ typedef struct st_mysqlnd_options
The ABI will be broken and the methods structure will be somewhere else
in the memory which can crash external code. Feel free to reuse these.
*/
- char * unused2;
+ HashTable * connect_attr;
char * unused3;
char * unused4;
char * unused5;
@@ -489,6 +489,8 @@ typedef enum_func_status (*func_mysqlnd_conn_data__connect_handshake)(MYSQLND_CO
typedef enum_func_status (*func_mysqlnd_conn_data__simple_command_send_request)(MYSQLND_CONN_DATA * conn, enum php_mysqlnd_server_command command, const zend_uchar * const arg, size_t arg_len, zend_bool silent, zend_bool ignore_upsert_status TSRMLS_DC);
typedef struct st_mysqlnd_authentication_plugin * (*func_mysqlnd_conn_data__fetch_auth_plugin_by_name)(const char * const requested_protocol TSRMLS_DC);
+typedef enum_func_status (*func_mysqlnd_conn_data__set_client_option_2d)(MYSQLND_CONN_DATA * const conn, enum mysqlnd_option option, const char * const key, const char * const value TSRMLS_DC);
+
struct st_mysqlnd_conn_data_methods
{
func_mysqlnd_conn_data__init init;
@@ -573,6 +575,8 @@ struct st_mysqlnd_conn_data_methods
func_mysqlnd_conn_data__connect_handshake connect_handshake;
func_mysqlnd_conn_data__simple_command_send_request simple_command_send_request;
func_mysqlnd_conn_data__fetch_auth_plugin_by_name fetch_auth_plugin_by_name;
+
+ func_mysqlnd_conn_data__set_client_option_2d set_client_option_2d;
};
View
66 ext/mysqlnd/mysqlnd_wireprotocol.c
@@ -212,6 +212,24 @@ php_mysqlnd_net_store_length(zend_uchar *packet, uint64_t length)
/* }}} */
+/* {{{ php_mysqlnd_net_store_length_size */
+size_t
+php_mysqlnd_net_store_length_size(uint64_t length)
+{
+ if (length < (uint64_t) L64(251)) {
+ return 1;
+ }
+ if (length < (uint64_t) L64(65536)) {
+ return 3;
+ }
+ if (length < (uint64_t) L64(16777216)) {
+ return 4;
+ }
+ return 8;
+}
+/* }}} */
+
+
/* {{{ php_mysqlnd_read_error_from_line */
static enum_func_status
php_mysqlnd_read_error_from_line(zend_uchar *buf, size_t buf_len,
@@ -459,7 +477,7 @@ void php_mysqlnd_greet_free_mem(void * _packet, zend_bool stack_allocation TSRML
/* }}} */
-#define AUTH_WRITE_BUFFER_LEN (MYSQLND_HEADER_SIZE + MYSQLND_MAX_ALLOWED_USER_LEN + SCRAMBLE_LENGTH + MYSQLND_MAX_ALLOWED_DB_LEN + 1 + 1024)
+#define AUTH_WRITE_BUFFER_LEN (MYSQLND_HEADER_SIZE + MYSQLND_MAX_ALLOWED_USER_LEN + SCRAMBLE_LENGTH + MYSQLND_MAX_ALLOWED_DB_LEN + 1 + 4096)
/* {{{ php_mysqlnd_auth_write */
static
@@ -540,6 +558,52 @@ size_t php_mysqlnd_auth_write(void * _packet, MYSQLND_CONN_DATA * conn TSRMLS_DC
p+= len;
*p++= '\0';
}
+
+ if (packet->connect_attr && zend_hash_num_elements(packet->connect_attr)) {
+ HashPosition pos_value;
+ const char ** entry_value;
+ size_t ca_payload_len = 0;
+ zend_hash_internal_pointer_reset_ex(packet->connect_attr, &pos_value);
+ while (SUCCESS == zend_hash_get_current_data_ex(packet->connect_attr, (void **)&entry_value, &pos_value)) {
+ char *s_key;
+ unsigned int s_len;
+ unsigned long num_key;
+ size_t value_len = strlen(*entry_value);
+
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(packet->connect_attr, &s_key, &s_len, &num_key, 0, &pos_value)) {
+ ca_payload_len += php_mysqlnd_net_store_length_size(s_len);
+ ca_payload_len += s_len;
+ ca_payload_len += php_mysqlnd_net_store_length_size(value_len);
+ ca_payload_len += value_len;
+ }
+ zend_hash_move_forward_ex(conn->options->connect_attr, &pos_value);
+ }
+
+ if ((sizeof(buffer) - (p - buffer)) >= (ca_payload_len + php_mysqlnd_net_store_length_size(ca_payload_len))) {
+ p = php_mysqlnd_net_store_length(p, ca_payload_len);
+
+ zend_hash_internal_pointer_reset_ex(packet->connect_attr, &pos_value);
+ while (SUCCESS == zend_hash_get_current_data_ex(packet->connect_attr, (void **)&entry_value, &pos_value)) {
+ char *s_key;
+ unsigned int s_len;
+ unsigned long num_key;
+ size_t value_len = strlen(*entry_value);
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(packet->connect_attr, &s_key, &s_len, &num_key, 0, &pos_value)) {
+ /* copy key */
+ p = php_mysqlnd_net_store_length(p, s_len);
+ memcpy(p, s_key, s_len);
+ p+= s_len;
+ /* copy value */
+ p = php_mysqlnd_net_store_length(p, value_len);
+ memcpy(p, *entry_value, value_len);
+ p+= value_len;
+ }
+ zend_hash_move_forward_ex(conn->options->connect_attr, &pos_value);
+ }
+ } else {
+ /* cannot put the data - skip */
+ }
+ }
}
if (packet->is_change_user_packet) {
if (PASS != conn->m->simple_command(conn, COM_CHANGE_USER, buffer + MYSQLND_HEADER_SIZE, p - buffer - MYSQLND_HEADER_SIZE,
View
2 ext/mysqlnd/mysqlnd_wireprotocol.h
@@ -103,7 +103,7 @@ typedef struct st_mysqlnd_packet_auth {
zend_bool send_auth_data;
zend_bool is_change_user_packet;
zend_bool silent;
-
+ HashTable *connect_attr;
} MYSQLND_PACKET_AUTH;
/* Auth response packet */
View
6 ext/pdo_oci/oci_driver.c
@@ -227,8 +227,10 @@ static int oci_handle_closer(pdo_dbh_t *dbh TSRMLS_DC) /* {{{ */
H->server = NULL;
}
- OCIHandleFree(H->err, OCI_HTYPE_ERROR);
- H->err = NULL;
+ if (H->err) {
+ OCIHandleFree(H->err, OCI_HTYPE_ERROR);
+ H->err = NULL;
+ }
if (H->charset && H->env) {
OCIHandleFree(H->env, OCI_HTYPE_ENV);
View
3 ext/pdo_oci/oci_statement.c
@@ -99,7 +99,7 @@ static int oci_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
switch (S->cols[i].dtype) {
case SQLT_BLOB:
case SQLT_CLOB:
- /* do nothing */
+ OCIDescriptorFree(S->cols[i].data, OCI_DTYPE_LOB);
break;
default:
efree(S->cols[i].data);
@@ -654,7 +654,6 @@ static int oci_blob_close(php_stream *stream, int close_handle TSRMLS_DC)
if (close_handle) {
OCILobClose(self->S->H->svc, self->S->err, self->lob);
- OCIDescriptorFree(self->lob, OCI_DTYPE_LOB);
efree(self);
}
View
165 ext/pdo_oci/tests/bug57702.phpt
@@ -0,0 +1,165 @@
+--TEST--
+PDO OCI Bug #57702 (Multi-row BLOB fetches)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
+require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require('ext/pdo/tests/pdo_test.inc');
+$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
+
+// Note the PDO test setup sets PDO::ATTR_STRINGIFY_FETCHES to true
+// (and sets PDO::ATTR_CASE to PDO::CASE_LOWER)
+
+$query = "begin execute immediate 'drop table mytable'; exception when others then if sqlcode <> -942 then raise; end if; end;";
+$stmt = $db->prepare($query);
+$stmt->execute();
+
+$query = "create table bug57702 (id number, data1 blob, data2 blob)";
+$stmt = $db->prepare($query);
+$stmt->execute();
+
+function do_insert($db, $id, $data1, $data2)
+{
+ $db->beginTransaction();
+ $stmt = $db->prepare("insert into bug57702 (id, data1, data2) values (:id, empty_blob(), empty_blob()) returning data1, data2 into :blob1, :blob2");
+ $stmt->bindParam(':id', $id);
+ $stmt->bindParam(':blob1', $blob1, PDO::PARAM_LOB);
+ $stmt->bindParam(':blob2', $blob2, PDO::PARAM_LOB);
+ $blob1 = null;
+ $blob2 = null;
+ $stmt->execute();
+
+ fwrite($blob1, $data1);
+ fclose($blob1);
+ fwrite($blob2, $data2);
+ fclose($blob2);
+ $db->commit();
+}
+
+do_insert($db, 1, "row 1 col 1", "row 1 col 2");
+do_insert($db, 2, "row 2 col 1", "row 2 col 2");
+
+////////////////////
+
+echo "First Query\n";
+
+// Fetch it back
+$stmt = $db->prepare('select data1, data2 from bug57702 order by id');
+$stmt->execute();
+$row = $stmt->fetch(PDO::FETCH_ASSOC);
+var_dump($row['data1']);
+var_dump($row['data2']);
+$row = $stmt->fetch(PDO::FETCH_ASSOC);
+var_dump($row['data1']);
+var_dump($row['data2']);
+
+////////////////////
+
+echo "\nSecond Query\n";
+
+foreach($db->query("select data1 as d1, data2 as d2 from bug57702 order by id") as $row) {
+ var_dump($row['d1']);
+ var_dump($row['d2']);
+}
+
+////////////////////
+
+echo "\nThird Query\n";
+
+$stmt = $db->prepare('select data1 as d3_1, data2 as d3_2 from bug57702 order by id');
+
+$rs = $stmt->execute();
+$stmt->bindColumn('d3_1' , $clob1, PDO::PARAM_LOB);
+$stmt->bindColumn('d3_2' , $clob2, PDO::PARAM_LOB);
+
+while ($stmt->fetch(PDO::FETCH_BOUND)) {
+ var_dump($clob1);
+ var_dump($clob2);
+}
+print "done\n";
+
+////////////////////
+
+echo "\nFourth Query\n";
+
+$a = array();
+$i = 0;
+foreach($db->query("select data1 as d4_1, data2 as d4_2 from bug57702 order by id") as $row) {
+ $a[$i][0] = $row['d4_1'];
+ $a[$i][1] = $row['d4_2'];
+ $i++;
+}
+
+for ($i = 0; $i < count($a); $i++) {
+ var_dump($a[$i][0]);
+ var_dump($a[$i][1]);
+}
+
+////////////////////
+
+echo "\nFifth Query\n";
+
+$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); // Let's use streams
+
+// Since each column only has one lob descriptor, the last row is
+// shown twice because the lob descriptor for each column is reused in
+// the stream
+
+$a = array();
+$i = 0;
+foreach($db->query("select data1 as d4_1, data2 as d4_2 from bug57702 order by id") as $row) {
+ $a[$i][0] = $row['d4_1'];
+ $a[$i][1] = $row['d4_2'];
+ $i++;
+}
+
+for ($i = 0; $i < count($a); $i++) {
+ var_dump(stream_get_contents($a[$i][0]));
+ var_dump(stream_get_contents($a[$i][1]));
+}
+
+// Cleanup
+$query = "drop table bug57702";
+$stmt = $db->prepare($query);
+$stmt->execute();
+
+print "done\n";
+
+?>
+--EXPECTF--
+First Query
+string(11) "row 1 col 1"
+string(11) "row 1 col 2"
+string(11) "row 2 col 1"
+string(11) "row 2 col 2"
+
+Second Query
+string(11) "row 1 col 1"
+string(11) "row 1 col 2"
+string(11) "row 2 col 1"
+string(11) "row 2 col 2"
+
+Third Query
+string(11) "row 1 col 1"
+string(11) "row 1 col 2"
+string(11) "row 2 col 1"
+string(11) "row 2 col 2"
+done
+
+Fourth Query
+string(11) "row 1 col 1"
+string(11) "row 1 col 2"
+string(11) "row 2 col 1"
+string(11) "row 2 col 2"
+
+Fifth Query
+string(11) "row 2 col 1"
+string(11) "row 2 col 2"
+string(11) "row 2 col 1"
+string(11) "row 2 col 2"
+done
View
6 ext/pdo_sqlite/sqlite_statement.c
@@ -112,9 +112,15 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
}
} else {
convert_to_long(param->parameter);
+#if LONG_MAX > 2147483647
+ if (SQLITE_OK == sqlite3_bind_int64(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
+ return 1;
+ }
+#else
if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
return 1;
}
+#endif
}
pdo_sqlite_error_stmt(stmt);
return 0;
View
27 ext/pdo_sqlite/tests/bug_63916-2.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #63916 PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_sqlite')) die('skip');
+if (PHP_INT_SIZE > 4) die('skip');
+?>
+--FILE--
+<?php
+$num = PHP_INT_MAX; // 32 bits
+$conn = new PDO('sqlite::memory:');
+$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');
+
+$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
+$stmt->bindValue(':id', 1, PDO::PARAM_INT);
+$stmt->bindValue(':num', $num, PDO::PARAM_INT);
+$stmt->execute();
+
+$stmt = $conn->query('SELECT num FROM users');
+$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
+
+var_dump($num,$result[0]);
+
+?>
+--EXPECT--
+int(2147483647)
+string(10) "2147483647"
View
27 ext/pdo_sqlite/tests/bug_63916.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #63916 PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_sqlite')) die('skip');
+if (PHP_INT_SIZE < 8) die('skip');
+?>
+--FILE--
+<?php
+$num = 100004313234244; // exceeds 32 bits
+$conn = new PDO('sqlite::memory:');
+$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');
+
+$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
+$stmt->bindValue(':id', 1, PDO::PARAM_INT);
+$stmt->bindValue(':num', $num, PDO::PARAM_INT);
+$stmt->execute();
+
+$stmt = $conn->query('SELECT num FROM users');
+$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
+
+var_dump($num,$result[0]);
+
+?>
+--EXPECT--
+int(100004313234244)
+string(15) "100004313234244"
View
2 ext/pgsql/pgsql.c
@@ -1736,7 +1736,7 @@ PHP_FUNCTION(pg_query_params)
} else {
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
- convert_to_string(&tmp_val);
+ convert_to_cstring(&tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
zval_dtor(&tmp_val);
View
23 ext/pgsql/tests/bug46408.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #46408 (Locale number format settings can cause pg_query_params to break with numerics)
+--SKIPIF--