case IS_BOOL:
case IS_DOUBLE:
case IS_NULL:
+ case IS_UNICODE:
if (value->refcount > 1) {
value_copy = *value;
zval_copy_ctor(&value_copy);
convert_to_string(value);
/* break missing intentionally */
case IS_STRING:
+ case IS_BINARY:
xmlNodeSetContentLen(node, Z_STRVAL_P(value), Z_STRLEN_P(value));
if (value == &value_copy) {
zval_dtor(value);
case IS_BOOL:
case IS_DOUBLE:
case IS_NULL:
+ case IS_UNICODE:
convert_to_string(value);
case IS_STRING:
+ case IS_BINARY:
newnode = (xmlNodePtr)xmlNewProp(node, name, Z_STRVAL_P(value));
break;
default:
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node);
}
else {
+ zval tmp_zv;
+
if (Z_TYPE_P(member) != IS_STRING) {
- zval tmp_zv = *member;
+ tmp_zv = *member;
zval_copy_ctor(&tmp_zv);
member = &tmp_zv;
convert_to_string(member);
}
node = nnext;
}
- }
+ if (member == &tmp_zv) {
+ zval_dtor(&tmp_zv);
+ }
+ }
if (node) {
exists = 1;
}
rv = sxe->properties;
} else {
ALLOC_HASHTABLE(rv);
- zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_u_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0, UG(unicode));
sxe->properties = rv;
}
if (node->type == XML_TEXT_NODE) {
MAKE_STD_ZVAL(value);
ZVAL_STRING(value, xmlNodeListGetString(node->doc, node, 1), 1);
+ if (UG(unicode)) {
+ convert_to_unicode(value);
+ }
zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
goto next_iter;
}
case IS_STRING:
convert_to_string(object);
break;
+ case IS_BINARY:
+ convert_to_binary(object);
+ break;
+ case IS_UNICODE:
+ convert_to_unicode(object);
+ break;
case IS_BOOL:
convert_to_boolean(object);
break;
curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
}
- namelen = xmlStrlen(curnode->name);
- *str_key = estrndup(curnode->name, namelen);
- *str_key_len = namelen + 1;
- return HASH_KEY_IS_STRING;
+ if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t u_len;
+ namelen = xmlStrlen(curnode->name);
+ zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), (UChar**)str_key, &u_len, (char*)curnode->name, namelen, &status);
+ *str_key_len = u_len + 1;
+ return HASH_KEY_IS_UNICODE;
+ } else {
+ namelen = xmlStrlen(curnode->name);
+ *str_key = estrndup(curnode->name, namelen);
+ *str_key_len = namelen + 1;
+ return HASH_KEY_IS_STRING;
+ }
}
ZEND_API void php_sxe_move_forward_iterator(php_sxe_object *sxe TSRMLS_DC)
static zend_class_entry *sqlite_get_ce_query(zval *object TSRMLS_DC)
{
- return sqlite_ce_query;
+ return U_CLASS_ENTRY(sqlite_ce_query);
}
static zend_class_entry *sqlite_get_ce_ub_query(zval *object TSRMLS_DC)
{
- return sqlite_ce_ub_query;
+ return U_CLASS_ENTRY(sqlite_ce_ub_query);
}
static zval * sqlite_instanciate(zend_class_entry *pce, zval *object TSRMLS_DC)
if (object) {
/* if object is not an object then we're called from the factory() function */
if (Z_TYPE_P(object) != IS_OBJECT) {
- sqlite_instanciate(sqlite_ce_db, object TSRMLS_CC);
+ sqlite_instanciate(U_CLASS_ENTRY(sqlite_ce_db), object TSRMLS_CC);
}
/* and now register the object */
SQLITE_REGISTER_OBJECT(db, object, db)
zval *errmsg = NULL;
zval *object = getThis();
- php_set_error_handling(object ? EH_THROW : EH_NORMAL, sqlite_ce_exception TSRMLS_CC);
+ php_set_error_handling(object ? EH_THROW : EH_NORMAL, U_CLASS_ENTRY(sqlite_ce_exception) TSRMLS_CC);
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz/",
&filename, &filename_len, &mode, &errmsg)) {
php_std_error_handling();
int filename_len;
zval *errmsg = NULL;
- php_set_error_handling(EH_THROW, sqlite_ce_exception TSRMLS_CC);
+ php_set_error_handling(EH_THROW, U_CLASS_ENTRY(sqlite_ce_exception) TSRMLS_CC);
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz/",
&filename, &filename_len, &mode, &errmsg)) {
php_std_error_handling();
if (object) {
sqlite_object *obj;
if (buffered) {
- sqlite_instanciate(sqlite_ce_query, return_value TSRMLS_CC);
+ sqlite_instanciate(U_CLASS_ENTRY(sqlite_ce_query), return_value TSRMLS_CC);
} else {
- sqlite_instanciate(sqlite_ce_ub_query, return_value TSRMLS_CC);
+ sqlite_instanciate(U_CLASS_ENTRY(sqlite_ce_ub_query), return_value TSRMLS_CC);
}
obj = (sqlite_object *) zend_object_store_get_object(return_value TSRMLS_CC);
obj->type = is_result;
php_sqlite_strtolower(colname);
}
- if (result_type == PHPSQLITE_ASSOC) {
- add_assoc_string(return_value, colname, colnames[ncols + i] ? (char *)colnames[ncols + i] : "", 1);
- }
- if (result_type == PHPSQLITE_NUM) {
- add_index_string(return_value, i, colnames[ncols + i] ? (char *)colnames[ncols + i] : "", 1);
+ if (UG(unicode)) {
+ char *tmp = colnames[ncols + i] ? (char *)colnames[ncols + i] : "";
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *u_str;
+ int32_t u_len;
+
+ zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, tmp, strlen(tmp), &status);
+ if (result_type == PHPSQLITE_ASSOC) {
+ add_assoc_unicode(return_value, colname, u_str, 1);
+ }
+ if (result_type == PHPSQLITE_NUM) {
+ add_index_unicode(return_value, i, u_str, 1);
+ }
+ efree(u_str);
+ } else {
+ if (result_type == PHPSQLITE_ASSOC) {
+ add_assoc_string(return_value, colname, colnames[ncols + i] ? (char *)colnames[ncols + i] : "", 1);
+ }
+ if (result_type == PHPSQLITE_NUM) {
+ add_index_string(return_value, i, colnames[ncols + i] ? (char *)colnames[ncols + i] : "", 1);
+ }
}
}
Z_STRVAL_P(decoded) = emalloc(strlen(rowdata[j]));
Z_STRLEN_P(decoded) = php_sqlite_decode_binary(rowdata[j]+1, Z_STRVAL_P(decoded));
Z_STRVAL_P(decoded)[Z_STRLEN_P(decoded)] = '\0';
- Z_TYPE_P(decoded) = IS_STRING;
+ Z_TYPE_P(decoded) = UG(unicode)?IS_BINARY:IS_STRING;
if (!buffered) {
efree((char*)rowdata[j]);
rowdata[j] = NULL;
}
} else {
- ZVAL_STRING(decoded, (char*)rowdata[j], buffered);
+ if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *u_str;
+ int32_t u_len;
+
+ zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, (char*)rowdata[j], strlen((char*)rowdata[j]), &status);
+ ZVAL_UNICODEL(decoded, u_str, u_len, 0);
+ if (!buffered) {
+ efree(rowdata[j]);
+ }
+ } else {
+ ZVAL_STRING(decoded, (char*)rowdata[j], buffered);
+ }
if (!buffered) {
rowdata[j] = NULL;
}
char *decoded = emalloc(l);
l = php_sqlite_decode_binary(rowdata[j]+1, decoded);
decoded[l] = '\0';
- RETVAL_STRINGL(decoded, l, 0);
+ if (UG(unicode)) {
+ RETVAL_BINARYL(decoded, l, 0);
+ } else {
+ RETVAL_STRINGL(decoded, l, 0);
+ }
if (!res->buffered) {
efree((char*)rowdata[j]);
rowdata[j] = NULL;
}
+ } else if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *u_str;
+ int32_t u_len;
+
+ zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, (char*)rowdata[j], strlen((char*)rowdata[j]), &status);
+ RETVAL_UNICODEL(u_str, u_len, 0);
+ if (!res->buffered) {
+ efree(rowdata[j]);
+ rowdata[j] = NULL;
+ }
} else {
RETVAL_STRING((char*)rowdata[j], res->buffered);
if (!res->buffered) {
zend_fcall_info_cache fcc;
zval *retval_ptr;
zval *ctor_params = NULL;
+ zend_uchar class_name_type;
- php_set_error_handling(object ? EH_THROW : EH_NORMAL, sqlite_ce_exception TSRMLS_CC);
+ php_set_error_handling(object ? EH_THROW : EH_NORMAL, U_CLASS_ENTRY(sqlite_ce_exception) TSRMLS_CC);
if (object) {
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|szb", &class_name, &class_name_len, &ctor_params, &decode_binary)) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|tzb", &class_name, &class_name_len, &class_name_type, &ctor_params, &decode_binary)) {
php_std_error_handling();
return;
}
RES_FROM_OBJECT(res, object);
if (!ZEND_NUM_ARGS()) {
- ce = zend_standard_class_def;
+ ce = U_CLASS_ENTRY(zend_standard_class_def);
} else {
- ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
+ ce = zend_u_fetch_class(class_name_type, class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
}
} else {
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|szb", &zres, &class_name, &class_name_len, &ctor_params, &decode_binary)) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|tzb", &zres, &class_name, &class_name_len, &class_name_type, &ctor_params, &decode_binary)) {
php_std_error_handling();
return;
}
ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
if (ZEND_NUM_ARGS() < 2) {
- ce = zend_standard_class_def;
+ ce = U_CLASS_ENTRY(zend_standard_class_def);
} else {
- ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
+ ce = zend_u_fetch_class(class_name_type, class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
}
}
if (!ce) {
- zend_throw_exception_ex(sqlite_ce_exception, 0 TSRMLS_CC, "Could not find class '%s'", class_name);
+ zend_throw_exception_ex(U_CLASS_ENTRY(sqlite_ce_exception), 0 TSRMLS_CC, "Could not find class '%s'", class_name);
php_std_error_handling();
return;
}
* single value is an array. Also we'd have to make that one
* argument passed by reference.
*/
- zend_throw_exception(sqlite_ce_exception, "Parameter ctor_params must be an array", 0 TSRMLS_CC);
+ zend_throw_exception(U_CLASS_ENTRY(sqlite_ce_exception), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
return;
}
} else {
fcc.object_pp = &return_value;
if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(sqlite_ce_exception, 0 TSRMLS_CC, "Could not execute %s::%v()", class_name, ce->constructor->common.function_name);
+ zend_throw_exception_ex(U_CLASS_ENTRY(sqlite_ce_exception), 0 TSRMLS_CC, "Could not execute %s::%v()", class_name, ce->constructor->common.function_name);
} else {
if (retval_ptr) {
zval_ptr_dtor(&retval_ptr);
efree(fci.params);
}
} else if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
- zend_throw_exception_ex(sqlite_ce_exception, 0 TSRMLS_CC, "Class %s does not have a constructor, use NULL for parameter ctor_params or omit it", class_name);
+ zend_throw_exception_ex(U_CLASS_ENTRY(sqlite_ce_exception), 0 TSRMLS_CC, "Class %s does not have a constructor, use NULL for parameter ctor_params or omit it", class_name);
}
}
/* }}} */
const char **rowdata;
char *decoded;
int decoded_len;
+ int free_decoded = 0;
/* check range of the row */
if (res->curr_row >= res->nrows) {
efree((char*)rowdata[0]);
rowdata[0] = NULL;
}
+ free_decoded = 1;
} else if (rowdata[0]) {
decoded_len = strlen((char*)rowdata[0]);
if (res->buffered) {
- decoded = estrndup((char*)rowdata[0], decoded_len);
+ if (UG(unicode)) {
+ decoded = (char*)rowdata[0];
+ } else {
+ decoded = estrndup((char*)rowdata[0], decoded_len);
+ }
} else {
decoded = (char*)rowdata[0];
rowdata[0] = NULL;
+ free_decoded = 1;
}
} else {
decoded = NULL;
if (decoded == NULL) {
RETURN_NULL();
+ } else if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *u_str;
+ int32_t u_len;
+
+ zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, decoded, decoded_len, &status);
+ if (free_decoded) {
+ efree(decoded);
+ }
+ RETURN_UNICODEL(u_str, u_len, 0);
} else {
RETURN_STRINGL(decoded, decoded_len, 0);
}
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
- RETURN_STRING((char*)sqlite_libversion(), 1);
+ if (UG(unicode)) {
+ char *temp = (char*)sqlite_libversion();
+ UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC);
+ RETURN_UNICODE(u_temp, 0);
+ } else {
+ RETURN_STRING((char*)sqlite_libversion(), 1);
+ }
}
/* }}} */
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
- RETURN_STRING((char*)sqlite_libencoding(), 1);
+ if (UG(unicode)) {
+ char *temp = (char*)sqlite_libencoding();
+ UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC);
+ RETURN_UNICODE(u_temp, 0);
+ } else {
+ RETURN_STRING((char*)sqlite_libencoding(), 1);
+ }
}
/* }}} */
* count = obj->u.res->nrows;
return SUCCESS;
} else {
- zend_throw_exception(sqlite_ce_exception, "Row count is not available for unbuffered queries", 0 TSRMLS_CC);
+ zend_throw_exception(U_CLASS_ENTRY(sqlite_ce_exception), "Row count is not available for unbuffered queries", 0 TSRMLS_CC);
return FAILURE;
}
} /* }}} */
RETURN_FALSE;
}
- RETURN_STRING(res->col_names[field], 1);
+ if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *u_str;
+ int32_t u_len;
+
+ zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, res->col_names[field], strlen(res->col_names[field]), &status);
+ RETURN_UNICODEL(u_str, u_len, 0);
+ } else {
+ RETURN_STRING(res->col_names[field], 1);
+ }
}
/* }}} */
msg = sqlite_error_string(code);
if (msg) {
- RETURN_STRING((char*)msg, 1);
+ if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *u_str;
+ int32_t u_len;
+
+ zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, msg, strlen(msg), &status);
+ RETURN_UNICODEL(u_str, u_len, 0);
+ } else {
+ RETURN_STRING((char*)msg, 1);
+ }
} else {
RETURN_NULL();
}