static void
populate_result_for_get_exists_many(as_key *key_p, zval *outer_container_p,
        zval *inner_container_p, as_error *error_p, bool null_flag TSRMLS_DC)
{
    if (!(as_val*)(key_p->valuep)) {
        if (!null_flag) {
            if (0 != add_assoc_zval(outer_container_p, (char *) key_p->digest.value, inner_container_p)) {
                PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                        "Unable to get key of a record");
                DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
            }
        } else {
            if (0 != add_assoc_null(outer_container_p, (char *) key_p->digest.value)) {
                PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                        "Unable to get key of a record");
                DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
            }
        }
    } else {
        switch (((as_val*)(key_p->valuep))->type) {
            case AS_STRING:
                if (!null_flag) {
                    if (0 != add_assoc_zval(outer_container_p, key_p->value.string.value, inner_container_p)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                } else {
                    if (0 != add_assoc_null(outer_container_p, key_p->value.string.value)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                }
                break;
            case AS_INTEGER:
                if (!null_flag) {
                    if (FAILURE == add_index_zval(outer_container_p, key_p->value.integer.value,
                                inner_container_p)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                } else {
                    if (0 != add_index_null(outer_container_p, key_p->value.integer.value)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                }
                break;
            default:
                break;
        }
    }
}
Ejemplo n.º 2
0
    void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray, unsigned int index)
    {
        if (value->IsNull() || value->IsUndefined())
        {
            add_index_null(phpArray, (unsigned long) index);
        }
        else if (value->IsBool())
        {
            if (value->ToBool())
                add_index_bool(phpArray, (unsigned long) index, 1);
            else
                add_index_bool(phpArray, (unsigned long) index, 0);
        }
        else if (value->IsNumber())
        {
            /* No way to check whether the number is an
               integer or a double here. All Kroll numbers
               are doubles, so return a double. This could
               cause some PHP to function incorrectly if it's
               doing strict type checking. */
            add_index_double(phpArray, (unsigned long) index, value->ToNumber());
        }
        else if (value->IsString())
        {
            add_index_stringl(phpArray, (unsigned long) index, (char *) value->ToString(), strlen(value->ToString()), 1);
        }
        else if (value->IsObject())
        {
            /*TODO: Implement*/
        }
        else if (value->IsMethod())
        {
            /*TODO: Implement*/
        }
        else if (value->IsList())
        {
            zval *phpValue;
            AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>();
            if (!pl.isNull())
                phpValue = pl->ToPHP();
            else
                phpValue = PHPUtils::ToPHPValue(value);

            add_index_zval(phpArray, (unsigned long) index, phpValue);
        }
    }
Ejemplo n.º 3
0
ONPHP_METHOD(QuerySkeleton, toDialectString)
{
	zval *where;
	unsigned int array_count = 0;
	
	where = ONPHP_READ_PROPERTY(getThis(), "where");
	
	if (
		(Z_TYPE_P(where) == IS_ARRAY)
		&& (array_count = zend_hash_num_elements(Z_ARRVAL_P(where)))
		&& (array_count > 0)
	) {
		zval *exp, *out, *logic, *whereLogic, *dialect;
		unsigned int i, retval_len;
		char *retval;
		char output_logic = 0;
		smart_str clause = {0};
		
		ONPHP_GET_ARGS("O", &dialect, onphp_ce_Dialect);
		
		whereLogic = ONPHP_READ_PROPERTY(getThis(), "whereLogic");
		
		smart_str_appendl(&clause, " WHERE", 6);
		
		for (i = 0; i < array_count; ++i) {
			ONPHP_ARRAY_GET(where, i, exp);
			
			ONPHP_CALL_METHOD_1(exp, "todialectstring", &out, dialect);
			
			if (Z_STRLEN_P(out)) {
				
				ONPHP_ARRAY_GET(whereLogic, i, logic);
				
				if (EG(exception)) {
					zval_ptr_dtor(&out);
					return;
				}
				
				// can be null
				if (Z_TYPE_P(logic) == IS_STRING) {
					onphp_append_zval_to_smart_string(&clause, logic);
				}
				
				smart_str_appendc(&clause, ' ');
				
				onphp_append_zval_to_smart_string(&clause, out);
				
				smart_str_appendc(&clause, ' ');
				
				output_logic = 1;
			} else if (
				(output_logic == 0)
				&& ((i + 1) <= array_count)
				&& ONPHP_ARRAY_ISSET(whereLogic, i + 1)
			) {
				add_index_null(whereLogic, i + 1);
			}
			
			zval_ptr_dtor(&out);
		}
		
		retval = (char *) php_trim(clause.c, clause.len, " ", 1, NULL, 2 TSRMLS_CC);
		smart_str_0(&clause);
		smart_str_free(&clause);
		retval_len = strlen(retval);
		
		RETURN_STRINGL(retval, retval_len, 0);
	}
	
	RETURN_NULL();
}