Beispiel #1
0
PHP_METHOD(Phalcon_Flash, _showMessage){

	zval *message = NULL, *classes = NULL, *css_classes = NULL, *msg = NULL;
	zval *c0 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL;
	zval *t0 = NULL, *t1 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &message, &classes) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (Z_TYPE_P(classes) == IS_ARRAY) { 
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, " ", 1);
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_fast_join(r0, c0, classes TSRMLS_CC);
		PHALCON_CPY_WRT(css_classes, r0);
	} else {
		PHALCON_CPY_WRT(css_classes, classes);
	}
	if (Z_TYPE_P(message) == IS_ARRAY) { 
		if (phalcon_valid_foreach(message TSRMLS_CC)) {
			ah0 = Z_ARRVAL_P(message);
			zend_hash_internal_pointer_reset_ex(ah0, &hp0);
			fes_3b3c_0:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_3b3c_0;
			}
			PHALCON_INIT_VAR(msg);
			ZVAL_ZVAL(msg, *hd, 1, 0);
			PHALCON_INIT_VAR(r1);
			PHALCON_INIT_VAR(t0);
			zend_get_constant("PHP_EOL", strlen("PHP_EOL"), t0 TSRMLS_CC);
			PHALCON_CONCAT_SVSVSV(r1, "<div class=\"", css_classes, "\">", msg, "</div>", t0);
			zend_print_zval(r1, 1);
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_3b3c_0;
			fee_3b3c_0:
			if(0){}
		} else {
			return;
		}
	} else {
		PHALCON_ALLOC_ZVAL_MM(r2);
		PHALCON_ALLOC_ZVAL_MM(t1);
		zend_get_constant("PHP_EOL", strlen("PHP_EOL"), t1 TSRMLS_CC);
		PHALCON_CONCAT_SVSVSV(r2, "<div class=\"", css_classes, "\">", message, "</div>", t1);
		zend_print_zval(r2, 1);
	}
	
	PHALCON_MM_RESTORE();
}
Beispiel #2
0
/**
 * Returns the prefix for all the generated urls. By default /
 *
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_Url, getBaseUri){

	zval *base_uri = NULL, *slash, *one, *minus_one = NULL, *php_self;
	zval *dirname, *dir_parts, *slice, *uri = NULL;
	zval *g0 = NULL;
	zval *c0 = NULL;
	int eval_int;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(base_uri);
	phalcon_read_property(&base_uri, this_ptr, SL("_baseUri"), PH_NOISY_CC);
	if (Z_TYPE_P(base_uri) == IS_NULL) {
		PHALCON_INIT_VAR(slash);
		ZVAL_STRING(slash, "/", 1);
		phalcon_get_global(&g0, SL("_SERVER")+1 TSRMLS_CC);
		eval_int = phalcon_array_isset_string(g0, SS("PHP_SELF"));
		if (eval_int) {
			PHALCON_INIT_VAR(one);
			ZVAL_LONG(one, 1);
			
			PHALCON_INIT_VAR(c0);
			ZVAL_LONG(c0, -1);
			PHALCON_CPY_WRT(minus_one, c0);
			
			PHALCON_INIT_VAR(php_self);
			phalcon_array_fetch_string(&php_self, g0, SL("PHP_SELF"), PH_NOISY_CC);
			
			PHALCON_INIT_VAR(dirname);
			PHALCON_CALL_FUNC_PARAMS_1(dirname, "dirname", php_self);
			
			PHALCON_INIT_VAR(dir_parts);
			phalcon_fast_explode(dir_parts, slash, dirname TSRMLS_CC);
			
			PHALCON_INIT_VAR(slice);
			PHALCON_CALL_FUNC_PARAMS_3(slice, "array_slice", dir_parts, one, minus_one);
			
			PHALCON_INIT_VAR(uri);
			phalcon_fast_join(uri, slash, slice TSRMLS_CC);
		} else {
			PHALCON_INIT_NVAR(uri);
			ZVAL_STRING(uri, "", 1);
		}
		
		if (PHALCON_COMPARE_STRING(uri, "")) {
			PHALCON_CPY_WRT(base_uri, slash);
		} else {
			PHALCON_INIT_NVAR(base_uri);
			PHALCON_CONCAT_VVV(base_uri, slash, uri, slash);
		}
		
		phalcon_update_property_zval(this_ptr, SL("_baseUri"), base_uri TSRMLS_CC);
	}
	
	
	RETURN_CCTOR(base_uri);
}
Beispiel #3
0
/**
 * Gets external uri where app is executed
 *
 * @return string
 */
PHP_METHOD(Phalcon_Controller_Front, getBaseUri){

	zval *uri = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL;
	zval *g0 = NULL;
	zval *c0 = NULL, *c1 = NULL, *c2 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, "_baseUri", sizeof("_baseUri")-1, PHALCON_NOISY TSRMLS_CC);
	if (!zend_is_true(t0)) {
		phalcon_get_global(&g0, "_SERVER", sizeof("_SERVER") TSRMLS_CC);
		eval_int = phalcon_array_isset_string(g0, "PHP_SELF", strlen("PHP_SELF")+1);
		if (eval_int) {
			PHALCON_INIT_VAR(c0);
			ZVAL_STRING(c0, "/", 1);
			PHALCON_ALLOC_ZVAL_MM(r0);
			PHALCON_INIT_VAR(c1);
			ZVAL_STRING(c1, "/", 1);
			PHALCON_ALLOC_ZVAL_MM(r1);
			PHALCON_ALLOC_ZVAL_MM(r2);
			phalcon_array_fetch_string(&r2, g0, "PHP_SELF", strlen("PHP_SELF"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_CALL_FUNC_PARAMS_1(r1, "dirname", r2, 0x049);
			PHALCON_ALLOC_ZVAL_MM(r3);
			phalcon_fast_explode(r3, c1, r1 TSRMLS_CC);
			PHALCON_INIT_VAR(c2);
			ZVAL_LONG(c2, 1);
			PHALCON_INIT_VAR(t2);
			ZVAL_LONG(t2, 1);
			PHALCON_INIT_VAR(t1);
			ZVAL_LONG(t1, -1);
			PHALCON_ALLOC_ZVAL_MM(r4);
			mul_function(r4, t1, t2 TSRMLS_CC);
			PHALCON_CALL_FUNC_PARAMS_3(r0, "array_slice", r3, c2, r4, 0x01F);
			PHALCON_ALLOC_ZVAL_MM(r5);
			phalcon_fast_join(r5, c0, r0 TSRMLS_CC);
			PHALCON_CPY_WRT(uri, r5);
		} else {
			PHALCON_INIT_VAR(uri);
			ZVAL_STRING(uri, "", 1);
		}
		if (!zend_is_true(uri)) {
			phalcon_update_property_string(this_ptr, "_baseUri", strlen("_baseUri"), "/" TSRMLS_CC);
		} else {
			PHALCON_ALLOC_ZVAL_MM(r6);
			PHALCON_CONCAT_SVS(r6, "/", uri, "/");
			phalcon_update_property_zval(this_ptr, "_baseUri", strlen("_baseUri"), r6 TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(t3);
	phalcon_read_property(&t3, this_ptr, "_baseUri", sizeof("_baseUri")-1, PHALCON_NOISY TSRMLS_CC);
	
	PHALCON_RETURN_CHECK_CTOR(t3);
}
Beispiel #4
0
/**
 * Gets external uri where app is executed
 *
 * @return string
 */
PHP_METHOD(Phalcon_Controller_Front, getBaseUri){

	zval *base_uri = NULL, *slash = NULL, *uri = NULL;
	zval *g0 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL;
	zval *c0 = NULL;
	zval *t0 = NULL, *t1 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_INIT_VAR(base_uri);
	phalcon_read_property(&base_uri, this_ptr, SL("_baseUri"), PH_NOISY_CC);
	if (!zend_is_true(base_uri)) {
		PHALCON_INIT_VAR(slash);
		ZVAL_STRING(slash, "/", 1);
		phalcon_get_global(&g0, SL("_SERVER")+1 TSRMLS_CC);
		eval_int = phalcon_array_isset_string(g0, SL("PHP_SELF")+1);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(r0);
			phalcon_array_fetch_string(&r0, g0, SL("PHP_SELF"), PH_NOISY_CC);
			PHALCON_ALLOC_ZVAL_MM(r1);
			PHALCON_CALL_FUNC_PARAMS_1(r1, "dirname", r0);
			PHALCON_ALLOC_ZVAL_MM(r2);
			phalcon_fast_explode(r2, slash, r1 TSRMLS_CC);
			PHALCON_INIT_VAR(c0);
			ZVAL_LONG(c0, 1);
			PHALCON_INIT_VAR(t1);
			ZVAL_LONG(t1, 1);
			PHALCON_INIT_VAR(t0);
			ZVAL_LONG(t0, -1);
			PHALCON_ALLOC_ZVAL_MM(r3);
			mul_function(r3, t0, t1 TSRMLS_CC);
			PHALCON_ALLOC_ZVAL_MM(r4);
			PHALCON_CALL_FUNC_PARAMS_3(r4, "array_slice", r2, c0, r3);
			PHALCON_INIT_VAR(uri);
			phalcon_fast_join(uri, slash, r4 TSRMLS_CC);
		} else {
			PHALCON_INIT_VAR(uri);
			ZVAL_STRING(uri, "", 1);
		}
		
		if (!zend_is_true(uri)) {
			PHALCON_CPY_WRT(base_uri, slash);
		} else {
			PHALCON_INIT_VAR(base_uri);
			PHALCON_CONCAT_VVV(base_uri, slash, uri, slash);
		}
		
		phalcon_update_property_zval(this_ptr, SL("_baseUri"), base_uri TSRMLS_CC);
	}
	
	
	RETURN_CCTOR(base_uri);
}
Beispiel #5
0
/**
 * Executes validator
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Model_Validator_Exclusionin, validate) {

    zval *domain = NULL, *field_name = NULL;
    zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
    zval *r7 = NULL;
    zval *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL;

    PHALCON_MM_GROW();
    PHALCON_ALLOC_ZVAL_MM(r0);
    PHALCON_CALL_METHOD(r0, this_ptr, "isrequired", PHALCON_NO_CHECK);
    if (zend_is_true(r0)) {
        PHALCON_ALLOC_ZVAL_MM(r1);
        PHALCON_INIT_VAR(c0);
        ZVAL_STRING(c0, "domain", 1);
        PHALCON_CALL_METHOD_PARAMS_1(r1, this_ptr, "issetoption", c0, PHALCON_NO_CHECK);
        if (zend_is_true(r1)) {
            PHALCON_ALLOC_ZVAL_MM(r2);
            PHALCON_INIT_VAR(c1);
            ZVAL_STRING(c1, "domain", 1);
            PHALCON_CALL_METHOD_PARAMS_1(r2, this_ptr, "getoption", c1, PHALCON_NO_CHECK);
            PHALCON_CPY_WRT(domain, r2);

            PHALCON_ALLOC_ZVAL_MM(r3);

            PHALCON_ALLOC_ZVAL_MM(r4);
            PHALCON_CALL_METHOD(r4, this_ptr, "getvalue", PHALCON_NO_CHECK);
            PHALCON_CALL_FUNC_PARAMS_2(r3, "in_array", r4, domain, 0x03E);
            if (zend_is_true(r3)) {
                PHALCON_ALLOC_ZVAL_MM(r5);
                PHALCON_CALL_METHOD(r5, this_ptr, "getfieldname", PHALCON_NO_CHECK);
                PHALCON_CPY_WRT(field_name, r5);

                PHALCON_ALLOC_ZVAL_MM(r6);

                PHALCON_INIT_VAR(c2);
                ZVAL_STRING(c2, ", ", 1);

                PHALCON_ALLOC_ZVAL_MM(r7);
                phalcon_fast_join(r7, c2, domain TSRMLS_CC);
                PHALCON_CONCAT_SVSV(r6, "Value of field '", field_name, "' must not be part of list: ", r7);

                PHALCON_INIT_VAR(c3);
                ZVAL_STRING(c3, "exclusion", 1);
                PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "appendmessage", r6, field_name, c3, PHALCON_NO_CHECK);
                PHALCON_MM_RESTORE();
                RETURN_FALSE;
            }
        }
    }
    PHALCON_MM_RESTORE();
    RETURN_TRUE;
}
Beispiel #6
0
/**
 * Gets a list of columns
 *
 * @param array $columnList
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Postgresql, getColumnList){

	zval *column_list = NULL, *str_list = NULL, *column = NULL, *column_quoted = NULL;
	zval *comma = NULL, *joined_list = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &column_list) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(str_list);
	array_init(str_list);
	
	if (!phalcon_valid_foreach(column_list TSRMLS_CC)) {
		return;
	}
	
	ah0 = Z_ARRVAL_P(column_list);
	zend_hash_internal_pointer_reset_ex(ah0, &hp0);
	
	ph_cycle_start_0:
	
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto ph_cycle_end_0;
		}
		
		PHALCON_GET_FOREACH_VALUE(column);
		
		PHALCON_INIT_VAR(column_quoted);
		PHALCON_CONCAT_SVS(column_quoted, "\"", column, "\"");
		phalcon_array_append(&str_list, column_quoted, PH_SEPARATE TSRMLS_CC);
		
		zend_hash_move_forward_ex(ah0, &hp0);
		goto ph_cycle_start_0;
	
	ph_cycle_end_0:
	
	PHALCON_INIT_VAR(comma);
	ZVAL_STRING(comma, ", ", 1);
	
	PHALCON_INIT_VAR(joined_list);
	phalcon_fast_join(joined_list, comma, str_list TSRMLS_CC);
	
	RETURN_CTOR(joined_list);
}
Beispiel #7
0
/**
 * Gets a list of columns
 *
 * @param array $columnList
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnList){

	zval *column_list = NULL, *str_list = NULL, *column = NULL;
	zval *a0 = NULL;
	zval *r0 = NULL, *r1 = NULL;
	zval *c0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &column_list) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(a0);
	array_init(a0);
	PHALCON_CPY_WRT(str_list, a0);
	if (phalcon_valid_foreach(column_list TSRMLS_CC)) {
		ah0 = Z_ARRVAL_P(column_list);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_52be_0:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_52be_0;
		}
		
		PHALCON_INIT_VAR(column);
		ZVAL_ZVAL(column, *hd, 1, 0);
		PHALCON_INIT_VAR(r0);
		PHALCON_CONCAT_SVS(r0, "`", column, "`");
		phalcon_array_append(&str_list, r0, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_52be_0;
		fee_52be_0:
		if(0){}
	} else {
		return;
	}
	
	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, ", ", 1);
	
	PHALCON_ALLOC_ZVAL_MM(r1);
	phalcon_fast_join(r1, c0, str_list TSRMLS_CC);
	PHALCON_RETURN_DZVAL(r1);
}
Beispiel #8
0
/**
 * Generates SQL to create a table in MySQL
 *
 * @param 	string $tableName
 * @param string $schemaName
 * @param array $definition
 * @return 	string
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){

	zval *table_name = NULL, *schema_name = NULL, *definition = NULL;
	zval *table = NULL, *temporary = NULL, *sql = NULL, *create_lines = NULL, *columns = NULL;
	zval *column = NULL, *column_name = NULL, *column_definition = NULL;
	zval *column_line = NULL, *attribute = NULL, *indexes = NULL, *index = NULL;
	zval *index_name = NULL, *column_list = NULL, *index_sql = NULL, *references = NULL;
	zval *reference = NULL, *name = NULL, *referenced_table = NULL, *referenced_columns = NULL;
	zval *constaint_sql = NULL, *reference_sql = NULL, *joined_lines = NULL;
	zval *options = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL;
	zval *t0 = NULL, *t1 = NULL;
	zval *c0 = NULL;
	HashTable *ah0, *ah1, *ah2;
	HashPosition hp0, hp1, hp2;
	zval **hd;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &table_name, &schema_name, &definition) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	eval_int = phalcon_array_isset_string(definition, SL("columns")+1);
	if (!eval_int) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array");
		return;
	}
	if (zend_is_true(schema_name)) {
		PHALCON_INIT_VAR(table);
		PHALCON_CONCAT_SVSVS(table, "`", schema_name, "`.`", table_name, "`");
	} else {
		PHALCON_INIT_VAR(table);
		PHALCON_CONCAT_SVS(table, "`", table_name, "`");
	}
	
	PHALCON_INIT_VAR(temporary);
	ZVAL_BOOL(temporary, 0);
	eval_int = phalcon_array_isset_string(definition, SL("options")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_array_fetch_string(&r0, definition, SL("options"), PH_NOISY_CC);
		eval_int = phalcon_array_isset_string(r0, SL("temporary")+1);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(r1);
			phalcon_array_fetch_string(&r1, definition, SL("options"), PH_NOISY_CC);
			PHALCON_ALLOC_ZVAL_MM(r2);
			phalcon_array_fetch_string(&r2, r1, SL("temporary"), PH_NOISY_CC);
			if (zend_is_true(r2)) {
				PHALCON_INIT_VAR(temporary);
				ZVAL_BOOL(temporary, 1);
			}
		}
	}
	
	if (Z_TYPE_P(temporary) == IS_BOOL && Z_BVAL_P(temporary)) {
		PHALCON_INIT_VAR(sql);
		PHALCON_CONCAT_SVS(sql, "CREATE TEMPORARY TABLE ", table, " (\n\t");
	} else {
		PHALCON_INIT_VAR(sql);
		PHALCON_CONCAT_SVS(sql, "CREATE TABLE ", table, " (\n\t");
	}
	
	PHALCON_INIT_VAR(create_lines);
	array_init(create_lines);
	
	PHALCON_INIT_VAR(columns);
	phalcon_array_fetch_string(&columns, definition, SL("columns"), PH_NOISY_CC);
	if (!phalcon_valid_foreach(columns TSRMLS_CC)) {
		return;
	}
	
	ah0 = Z_ARRVAL_P(columns);
	zend_hash_internal_pointer_reset_ex(ah0, &hp0);
	fes_52be_2:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_52be_2;
		}
		
		PHALCON_INIT_VAR(column);
		ZVAL_ZVAL(column, *hd, 1, 0);
		PHALCON_INIT_VAR(column_name);
		PHALCON_CALL_METHOD(column_name, column, "getname", PH_NO_CHECK);
		
		PHALCON_INIT_VAR(column_definition);
		PHALCON_CALL_METHOD_PARAMS_1(column_definition, this_ptr, "getcolumndefinition", column, PH_NO_CHECK);
		
		PHALCON_INIT_VAR(column_line);
		PHALCON_CONCAT_SVSV(column_line, "`", column_name, "` ", column_definition);
		
		PHALCON_INIT_VAR(attribute);
		PHALCON_CALL_METHOD(attribute, column, "isnotnull", PH_NO_CHECK);
		if (zend_is_true(attribute)) {
			PHALCON_INIT_VAR(t0);
			ZVAL_STRING(t0, " NOT NULL", 1);
			phalcon_concat_self(&column_line, t0 TSRMLS_CC);
		}
		
		PHALCON_INIT_VAR(attribute);
		PHALCON_CALL_METHOD(attribute, column, "isautoincrement", PH_NO_CHECK);
		if (zend_is_true(attribute)) {
			PHALCON_INIT_VAR(t1);
			ZVAL_STRING(t1, " AUTO_INCREMENT", 1);
			phalcon_concat_self(&column_line, t1 TSRMLS_CC);
		}
		
		phalcon_array_append(&create_lines, column_line, PH_SEPARATE TSRMLS_CC);
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_52be_2;
	fee_52be_2:
	
	eval_int = phalcon_array_isset_string(definition, SL("indexes")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(indexes);
		phalcon_array_fetch_string(&indexes, definition, SL("indexes"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(indexes TSRMLS_CC)) {
			return;
		}
		
		ah1 = Z_ARRVAL_P(indexes);
		zend_hash_internal_pointer_reset_ex(ah1, &hp1);
		fes_52be_3:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_52be_3;
			}
			
			PHALCON_INIT_VAR(index);
			ZVAL_ZVAL(index, *hd, 1, 0);
			PHALCON_INIT_VAR(index_name);
			PHALCON_CALL_METHOD(index_name, index, "getname", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(columns);
			PHALCON_CALL_METHOD(columns, index, "getcolumns", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(column_list);
			PHALCON_CALL_METHOD_PARAMS_1(column_list, this_ptr, "getcolumnlist", columns, PH_NO_CHECK);
			if (PHALCON_COMPARE_STRING(index_name, "PRIMARY")) {
				PHALCON_INIT_VAR(index_sql);
				PHALCON_CONCAT_SVS(index_sql, "PRIMARY KEY (", column_list, ")");
			} else {
				PHALCON_INIT_VAR(index_sql);
				PHALCON_CONCAT_SVSVS(index_sql, "KEY `", index_name, "` (", column_list, ")");
			}
			
			phalcon_array_append(&create_lines, index_sql, PH_SEPARATE TSRMLS_CC);
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_52be_3;
		fee_52be_3:
		if(0){}
		
	}
	
	eval_int = phalcon_array_isset_string(definition, SL("references")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(references);
		phalcon_array_fetch_string(&references, definition, SL("references"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(references TSRMLS_CC)) {
			return;
		}
		
		ah2 = Z_ARRVAL_P(references);
		zend_hash_internal_pointer_reset_ex(ah2, &hp2);
		fes_52be_4:
			if(zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) != SUCCESS){
				goto fee_52be_4;
			}
			
			PHALCON_INIT_VAR(reference);
			ZVAL_ZVAL(reference, *hd, 1, 0);
			PHALCON_INIT_VAR(name);
			PHALCON_CALL_METHOD(name, reference, "getname", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(columns);
			PHALCON_CALL_METHOD(columns, reference, "getcolumns", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(column_list);
			PHALCON_CALL_METHOD_PARAMS_1(column_list, this_ptr, "getcolumnlist", columns, PH_NO_CHECK);
			
			PHALCON_INIT_VAR(referenced_table);
			PHALCON_CALL_METHOD(referenced_table, reference, "getreferencedtable", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(referenced_columns);
			PHALCON_CALL_METHOD(referenced_columns, reference, "getreferencedcolumns", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(column_list);
			PHALCON_CALL_METHOD_PARAMS_1(column_list, this_ptr, "getcolumnlist", referenced_columns, PH_NO_CHECK);
			
			PHALCON_INIT_VAR(constaint_sql);
			PHALCON_CONCAT_SVSVS(constaint_sql, "CONSTRAINT `", name, "` FOREIGN KEY (", column_list, ")");
			
			PHALCON_INIT_VAR(reference_sql);
			PHALCON_CONCAT_VSVSVS(reference_sql, constaint_sql, " REFERENCES `", referenced_table, "`(", column_list, ")");
			phalcon_array_append(&create_lines, reference_sql, PH_SEPARATE TSRMLS_CC);
			zend_hash_move_forward_ex(ah2, &hp2);
			goto fes_52be_4;
		fee_52be_4:
		if(0){}
		
	}
	
	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, ",\n\t", 1);
	
	PHALCON_INIT_VAR(joined_lines);
	phalcon_fast_join(joined_lines, c0, create_lines TSRMLS_CC);
	
	PHALCON_ALLOC_ZVAL_MM(r3);
	PHALCON_CONCAT_VS(r3, joined_lines, "\n)");
	phalcon_concat_self(&sql, r3 TSRMLS_CC);
	eval_int = phalcon_array_isset_string(definition, SL("options")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(options);
		PHALCON_CALL_METHOD_PARAMS_1(options, this_ptr, "_gettableoptions", definition, PH_NO_CHECK);
		
		PHALCON_ALLOC_ZVAL_MM(r4);
		PHALCON_CONCAT_SV(r4, " ", options);
		phalcon_concat_self(&sql, r4 TSRMLS_CC);
	}
	
	
	RETURN_CTOR(sql);
}
Beispiel #9
0
/**
 * Generates SQL to add the table creation options
 *
 * @param array $definition
 * @return array
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){

	zval *definition = NULL, *table_options = NULL, *engine = NULL, *sql_engine = NULL;
	zval *auto_increment = NULL, *sql_autoincrement = NULL;
	zval *table_collation = NULL, *collation_parts = NULL, *sql_charset = NULL;
	zval *sql_collate = NULL, *number_options = NULL, *sql_table_options = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL;
	zval *c0 = NULL, *c1 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(table_options);
	array_init(table_options);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	phalcon_array_fetch_string(&r0, definition, SL("options"), PH_NOISY_CC);
	eval_int = phalcon_array_isset_string(r0, SL("ENGINE")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		phalcon_array_fetch_string(&r1, definition, SL("options"), PH_NOISY_CC);
		PHALCON_INIT_VAR(engine);
		phalcon_array_fetch_string(&engine, r1, SL("ENGINE"), PH_NOISY_CC);
		
		PHALCON_ALLOC_ZVAL_MM(r2);
		phalcon_array_fetch_string(&r2, definition, SL("options"), PH_NOISY_CC);
		
		PHALCON_ALLOC_ZVAL_MM(r3);
		phalcon_array_fetch_string(&r3, r2, SL("ENGINE"), PH_NOISY_CC);
		if (zend_is_true(r3)) {
			PHALCON_INIT_VAR(sql_engine);
			PHALCON_CONCAT_SV(sql_engine, "ENGINE=", engine);
			phalcon_array_append(&table_options, sql_engine, PH_SEPARATE TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r4);
	phalcon_array_fetch_string(&r4, definition, SL("options"), PH_NOISY_CC);
	eval_int = phalcon_array_isset_string(r4, SL("AUTO_INCREMENT")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r5);
		phalcon_array_fetch_string(&r5, definition, SL("options"), PH_NOISY_CC);
		PHALCON_INIT_VAR(auto_increment);
		phalcon_array_fetch_string(&auto_increment, r5, SL("AUTO_INCREMENT"), PH_NOISY_CC);
		if (zend_is_true(auto_increment)) {
			PHALCON_INIT_VAR(sql_autoincrement);
			PHALCON_CONCAT_SV(sql_autoincrement, "AUTO_INCREMENT=", auto_increment);
			phalcon_array_append(&table_options, sql_autoincrement, PH_SEPARATE TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r6);
	phalcon_array_fetch_string(&r6, definition, SL("options"), PH_NOISY_CC);
	eval_int = phalcon_array_isset_string(r6, SL("TABLE_COLLATION")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r7);
		phalcon_array_fetch_string(&r7, definition, SL("options"), PH_NOISY_CC);
		PHALCON_INIT_VAR(table_collation);
		phalcon_array_fetch_string(&table_collation, r7, SL("TABLE_COLLATION"), PH_NOISY_CC);
		if (zend_is_true(table_collation)) {
			PHALCON_INIT_VAR(c0);
			ZVAL_STRING(c0, "_", 1);
			PHALCON_INIT_VAR(collation_parts);
			phalcon_fast_explode(collation_parts, c0, table_collation TSRMLS_CC);
			
			PHALCON_ALLOC_ZVAL_MM(r8);
			phalcon_array_fetch_long(&r8, collation_parts, 0, PH_NOISY_CC);
			
			PHALCON_INIT_VAR(sql_charset);
			PHALCON_CONCAT_SV(sql_charset, "DEFAULT CHARSET=", r8);
			phalcon_array_append(&table_options, sql_charset, PH_SEPARATE TSRMLS_CC);
			
			PHALCON_INIT_VAR(sql_collate);
			PHALCON_CONCAT_SV(sql_collate, "COLLATE=", table_collation);
			phalcon_array_append(&table_options, sql_collate, PH_SEPARATE TSRMLS_CC);
		}
	}
	
	PHALCON_INIT_VAR(number_options);
	phalcon_fast_count(number_options, table_options TSRMLS_CC);
	if (!phalcon_compare_strict_long(number_options, 0 TSRMLS_CC)) {
		PHALCON_INIT_VAR(c1);
		ZVAL_STRING(c1, " ", 1);
		PHALCON_INIT_VAR(sql_table_options);
		phalcon_fast_join(sql_table_options, c1, table_options TSRMLS_CC);
		
		RETURN_CTOR(sql_table_options);
	}
	
	PHALCON_MM_RESTORE();
	RETURN_NULL();
}
Beispiel #10
0
/**
 * Get the conditions of query
 *
 * @return string $query
 */
PHP_METHOD(Phalcon_Model_Query, getConditions){

	zval *controller_front = NULL, *model_manager = NULL, *model_name = NULL;
	zval *entity = NULL, *meta_data = NULL, *attributes = NULL, *numeric_types = NULL;
	zval *i = NULL, *parameters = NULL, *conditions = NULL, *value = NULL, *param = NULL;
	zval *condition = NULL, *index = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL;
	zval *t7 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL;
	zval *i0 = NULL;
	zval *a0 = NULL, *a1 = NULL;
	zval *c0 = NULL;
	HashTable *ah0, *ah1, *ah2;
	HashPosition hp0, hp1, hp2;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY TSRMLS_CC);
	if (!zend_is_true(t0)) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		PHALCON_CALL_STATIC(r0, "phalcon_controller_front", "getinstance");
		PHALCON_CPY_WRT(controller_front, r0);
		
		PHALCON_ALLOC_ZVAL_MM(r1);
		PHALCON_CALL_METHOD(r1, controller_front, "getmodelcomponent", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(model_manager, r1);
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "setmanager", model_manager, PHALCON_NO_CHECK);
	} else {
		PHALCON_ALLOC_ZVAL_MM(t1);
		phalcon_read_property(&t1, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(model_manager, t1);
	}
	
	PHALCON_ALLOC_ZVAL_MM(t2);
	phalcon_read_property(&t2, this_ptr, "_models", sizeof("_models")-1, PHALCON_NOISY TSRMLS_CC);
	if (phalcon_valid_foreach(t2 TSRMLS_CC)) {
		ah0 = Z_ARRVAL_P(t2);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_a355_0:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_a355_0;
		}
		
		PHALCON_INIT_VAR(model_name);
		ZVAL_ZVAL(model_name, *hd, 1, 0);
		PHALCON_INIT_VAR(r2);
		PHALCON_CALL_METHOD_PARAMS_1(r2, model_manager, "getmodel", model_name, PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(entity, r2);
		if (!zend_is_true(entity)) {
			PHALCON_INIT_VAR(i0);
			object_init_ex(i0, phalcon_model_exception_ce);
			PHALCON_INIT_VAR(r3);
			PHALCON_CONCAT_BOTH(r3,  "The model ", model_name, " does not exist");
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r3, PHALCON_CHECK);
			phalcon_throw_exception(i0 TSRMLS_CC);
			return;
		}
		
		
		PHALCON_INIT_VAR(r4);
		PHALCON_CALL_METHOD(r4, model_manager, "getmetadata", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(meta_data, r4);
		
		PHALCON_INIT_VAR(r5);
		PHALCON_CALL_METHOD_PARAMS_1(r5, meta_data, "getattributes", entity, PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(attributes, r5);
		
		PHALCON_INIT_VAR(r6);
		PHALCON_CALL_METHOD_PARAMS_1(r6, meta_data, "getdatatypesnumeric", entity, PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(numeric_types, r6);
		
		PHALCON_INIT_VAR(t3);
		phalcon_read_property(&t3, this_ptr, "_data", sizeof("_data")-1, PHALCON_NOISY TSRMLS_CC);
		
		PHALCON_INIT_VAR(r7);
		phalcon_fast_count(r7, t3 TSRMLS_CC);
		if (zend_is_true(r7)) {
			PHALCON_INIT_VAR(i);
			ZVAL_LONG(i, 0);
			
			PHALCON_INIT_VAR(a0);
			array_init(a0);
			PHALCON_CPY_WRT(parameters, a0);
			
			PHALCON_INIT_VAR(a1);
			array_init(a1);
			PHALCON_CPY_WRT(conditions, a1);
			
			PHALCON_INIT_VAR(t4);
			phalcon_read_property(&t4, this_ptr, "_data", sizeof("_data")-1, PHALCON_NOISY TSRMLS_CC);
			if (phalcon_valid_foreach(t4 TSRMLS_CC)) {
				ah1 = Z_ARRVAL_P(t4);
				zend_hash_internal_pointer_reset_ex(ah1, &hp1);
				fes_a355_1:
				if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
					goto fee_a355_1;
				} else {
					PHALCON_INIT_VAR(param);
					PHALCON_GET_FOREACH_KEY(param, ah1, hp1);
				}
				PHALCON_INIT_VAR(value);
				ZVAL_ZVAL(value, *hd, 1, 0);
				PHALCON_INIT_VAR(r8);
				PHALCON_CALL_FUNC_PARAMS_2(r8, "in_array", param, attributes, 0x03E);
				if (zend_is_true(r8)) {
					PHALCON_INIT_VAR(t5);
					ZVAL_STRING(t5, "", 1);
					PHALCON_INIT_VAR(r9);
					is_not_identical_function(r9, t5, value TSRMLS_CC);
					PHALCON_INIT_VAR(r11);
					PHALCON_CALL_FUNC_PARAMS_1(r11, "is_null", value, 0x041);
					PHALCON_INIT_VAR(r10);
					boolean_not_function(r10, r11 TSRMLS_CC);
					PHALCON_INIT_VAR(r12);
					phalcon_and_function(r12, r9, r10);
					if (zend_is_true(r12)) {
						if (!PHALCON_COMPARE_STRING(value, "@")) {
							eval_int = phalcon_array_isset(numeric_types, param);
							if (eval_int) {
								PHALCON_INIT_VAR(r13);
								PHALCON_CONCAT_VBOTH(r13, param, " = ?", i);
								PHALCON_CPY_WRT(condition, r13);
								phalcon_array_update(&parameters, i, &value, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
							} else {
								PHALCON_INIT_VAR(r14);
								PHALCON_CONCAT_VBOTH(r14, param, " LIKE ?", i);
								PHALCON_CPY_WRT(condition, r14);
								
								PHALCON_INIT_VAR(r15);
								PHALCON_CONCAT_BOTH(r15,  "%", value, "%");
								phalcon_array_update(&parameters, i, &r15, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
							}
							phalcon_array_append(&conditions, condition, PHALCON_SEPARATE_PLZ TSRMLS_CC);
						}
					}
				}
				PHALCON_SEPARATE(i);
				increment_function(i);
				zend_hash_move_forward_ex(ah1, &hp1);
				goto fes_a355_1;
				fee_a355_1:
				if(0){}
			} else {
				return;
			}
		} else {
			PHALCON_INIT_VAR(t6);
			phalcon_read_property(&t6, this_ptr, "_parameters", sizeof("_parameters")-1, PHALCON_NOISY TSRMLS_CC);
			PHALCON_CPY_WRT(parameters, t6);
			
			PHALCON_INIT_VAR(t7);
			phalcon_read_property(&t7, this_ptr, "_conditions", sizeof("_conditions")-1, PHALCON_NOISY TSRMLS_CC);
			PHALCON_CPY_WRT(conditions, t7);
		}
		
		
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, " AND ", 1);
		
		PHALCON_INIT_VAR(r16);
		phalcon_fast_join(r16, c0, conditions TSRMLS_CC);
		PHALCON_CPY_WRT(conditions, r16);
		if (phalcon_valid_foreach(parameters TSRMLS_CC)) {
			ah2 = Z_ARRVAL_P(parameters);
			zend_hash_internal_pointer_reset_ex(ah2, &hp2);
			fes_a355_2:
			if(zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) != SUCCESS){
				goto fee_a355_2;
			} else {
				PHALCON_INIT_VAR(index);
				PHALCON_GET_FOREACH_KEY(index, ah2, hp2);
			}
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			PHALCON_INIT_VAR(r17);
			PHALCON_INIT_VAR(r18);
			PHALCON_CONCAT_LEFT(r18, "?", index);
			PHALCON_CALL_FUNC_PARAMS_3(r17, "str_replace", r18, value, conditions, 0x003);
			PHALCON_CPY_WRT(conditions, r17);
			zend_hash_move_forward_ex(ah2, &hp2);
			goto fes_a355_2;
			fee_a355_2:
			if(0){}
		} else {
			return;
		}
		if (PHALCON_COMPARE_STRING(conditions, "")) {
			PHALCON_INIT_VAR(conditions);
			ZVAL_STRING(conditions, "1=1", 1);
		}
		
		
		PHALCON_RETURN_CHECK_CTOR(conditions);
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_a355_0;
		fee_a355_0:
		if(0){}
	} else {
		return;
	}
	
	PHALCON_MM_RESTORE();
}
Beispiel #11
0
/**
 * Inserts data into a table using custom RBDM SQL syntax
 *
 * @param string $table
 * @param array $values
 * @param array $fields
 * @return boolean
 */
PHP_METHOD(Phalcon_Db, insert){

	zval *table = NULL, *values = NULL, *fields = NULL, *placeholders = NULL, *value = NULL;
	zval *n = NULL, *comma = NULL, *joined_values = NULL, *insert_sql = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL;
	zval *i0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &table, &values, &fields) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_SEPARATE_PARAM(values);
	
	if (!fields) {
		PHALCON_ALLOC_ZVAL_MM(fields);
		ZVAL_NULL(fields);
	}
	
	if (Z_TYPE_P(values) == IS_ARRAY) { 
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_fast_count(r0, values TSRMLS_CC);
		if (!zend_is_true(r0)) {
			PHALCON_ALLOC_ZVAL_MM(i0);
			object_init_ex(i0, phalcon_db_exception_ce);
			PHALCON_ALLOC_ZVAL_MM(r1);
			PHALCON_CONCAT_SVS(r1, "Unable to insert into ", table, " without data");
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r1, PH_CHECK);
			phalcon_throw_exception(i0 TSRMLS_CC);
			return;
		}
		
		PHALCON_INIT_VAR(placeholders);
		array_init(placeholders);
		if (!phalcon_valid_foreach(values TSRMLS_CC)) {
			return;
		}
		
		ALLOC_HASHTABLE(ah0);
		zend_hash_init(ah0, 0, NULL, NULL, 0);
		zend_hash_copy(ah0, Z_ARRVAL_P(values), NULL, NULL, sizeof(zval*));
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_e7f0_1:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_e7f0_1;
			}
			
			PHALCON_INIT_VAR(n);
			PHALCON_GET_FOREACH_KEY(n, ah0, hp0);
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			if (Z_TYPE_P(value) == IS_OBJECT) {
				PHALCON_INIT_VAR(r2);
				PHALCON_CALL_FUNC_PARAMS_1(r2, "strval", value);
				phalcon_array_append(&placeholders, r2, PH_SEPARATE TSRMLS_CC);
				PHALCON_SEPARATE_PARAM(values);
				phalcon_array_unset(values, n);
			} else {
				phalcon_array_append_string(&placeholders, SL("?"), PH_SEPARATE TSRMLS_CC);
			}
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_e7f0_1;
		fee_e7f0_1:
		zend_hash_destroy(ah0);
		efree(ah0);
		
		PHALCON_INIT_VAR(comma);
		ZVAL_STRING(comma, ", ", 1);
		
		PHALCON_INIT_VAR(joined_values);
		phalcon_fast_join(joined_values, comma, placeholders TSRMLS_CC);
		if (Z_TYPE_P(fields) == IS_ARRAY) { 
			PHALCON_ALLOC_ZVAL_MM(r3);
			phalcon_fast_join(r3, comma, fields TSRMLS_CC);
			PHALCON_INIT_VAR(insert_sql);
			PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", table, " (", r3, ") VALUES (", joined_values, ")");
		} else {
			PHALCON_INIT_VAR(insert_sql);
			PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", table, " VALUES (", joined_values, ")");
		}
		
		PHALCON_ALLOC_ZVAL_MM(r4);
		PHALCON_CALL_METHOD_PARAMS_2(r4, this_ptr, "execute", insert_sql, values, PH_NO_CHECK);
		RETURN_CTOR(r4);
	}
	PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array");
	return;
}
Beispiel #12
0
/**
 * Generates SQL to create a table in MySQL
 *
 * @param string $tableName
 * @param string $schemaName
 * @param array $definition
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){

	zval *table_name = NULL, *schema_name = NULL, *definition = NULL;
	zval *table = NULL, *temporary = NULL, *sql = NULL, *create_lines = NULL, *column = NULL;
	zval *column_line = NULL, *index = NULL, *index_name = NULL, *column_list = NULL;
	zval *reference = NULL, *reference_sql = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL, *r19 = NULL, *r20 = NULL;
	zval *r21 = NULL, *r22 = NULL, *r23 = NULL;
	zval *t0 = NULL, *t1 = NULL;
	zval *c0 = NULL;
	HashTable *ah0, *ah1, *ah2;
	HashPosition hp0, hp1, hp2;
	zval **hd;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &table_name, &schema_name, &definition) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (zend_is_true(schema_name)) {
		PHALCON_INIT_VAR(table);
		PHALCON_CONCAT_SVSVS(table, "`", schema_name, "`.`", table_name, "`");
	} else {
		PHALCON_INIT_VAR(table);
		PHALCON_CONCAT_SVS(table, "`", table_name, "`");
	}
	
	PHALCON_INIT_VAR(temporary);
	ZVAL_BOOL(temporary, 0);
	eval_int = phalcon_array_isset_string(definition, SL("options")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_array_fetch_string(&r0, definition, SL("options"), PH_NOISY_CC);
		eval_int = phalcon_array_isset_string(r0, SL("temporary")+1);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(r1);
			phalcon_array_fetch_string(&r1, definition, SL("options"), PH_NOISY_CC);
			PHALCON_ALLOC_ZVAL_MM(r2);
			phalcon_array_fetch_string(&r2, r1, SL("temporary"), PH_NOISY_CC);
			if (zend_is_true(r2)) {
				PHALCON_INIT_VAR(temporary);
				ZVAL_BOOL(temporary, 1);
			}
		}
	}
	
	if (zend_is_true(temporary)) {
		PHALCON_INIT_VAR(sql);
		PHALCON_CONCAT_SVS(sql, "CREATE TEMPORARY TABLE ", table, " (\n\t");
	} else {
		PHALCON_INIT_VAR(sql);
		PHALCON_CONCAT_SVS(sql, "CREATE TABLE ", table, " (\n\t");
	}
	
	PHALCON_INIT_VAR(create_lines);
	array_init(create_lines);
	
	PHALCON_ALLOC_ZVAL_MM(r3);
	phalcon_array_fetch_string(&r3, definition, SL("columns"), PH_NOISY_CC);
	if (!phalcon_valid_foreach(r3 TSRMLS_CC)) {
		return;
	}
	
	ah0 = Z_ARRVAL_P(r3);
	zend_hash_internal_pointer_reset_ex(ah0, &hp0);
	fes_52be_2:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_52be_2;
		}
		
		PHALCON_INIT_VAR(column);
		ZVAL_ZVAL(column, *hd, 1, 0);
		PHALCON_INIT_VAR(r4);
		PHALCON_CALL_METHOD(r4, column, "getname", PH_NO_CHECK);
		PHALCON_INIT_VAR(r5);
		PHALCON_CALL_SELF_PARAMS_1(r5, this_ptr, "getcolumndefinition", column);
		PHALCON_INIT_VAR(column_line);
		PHALCON_CONCAT_SVSV(column_line, "`", r4, "` ", r5);
		
		PHALCON_INIT_VAR(r6);
		PHALCON_CALL_METHOD(r6, column, "isnotnull", PH_NO_CHECK);
		if (zend_is_true(r6)) {
			PHALCON_INIT_VAR(t0);
			ZVAL_STRING(t0, " NOT NULL", 1);
			phalcon_concat_self(&column_line, t0 TSRMLS_CC);
		}
		
		PHALCON_INIT_VAR(r7);
		PHALCON_CALL_METHOD(r7, column, "isautoincrement", PH_NO_CHECK);
		if (zend_is_true(r7)) {
			PHALCON_INIT_VAR(t1);
			ZVAL_STRING(t1, " AUTO_INCREMENT", 1);
			phalcon_concat_self(&column_line, t1 TSRMLS_CC);
		}
		
		phalcon_array_append(&create_lines, column_line, PH_SEPARATE TSRMLS_CC);
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_52be_2;
	fee_52be_2:
	if(0){}
	
	eval_int = phalcon_array_isset_string(definition, SL("indexes")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r8);
		phalcon_array_fetch_string(&r8, definition, SL("indexes"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(r8 TSRMLS_CC)) {
			return;
		}
		
		ah1 = Z_ARRVAL_P(r8);
		zend_hash_internal_pointer_reset_ex(ah1, &hp1);
		fes_52be_3:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_52be_3;
			}
			
			PHALCON_INIT_VAR(index);
			ZVAL_ZVAL(index, *hd, 1, 0);
			PHALCON_INIT_VAR(index_name);
			PHALCON_CALL_METHOD(index_name, index, "getname", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(r9);
			PHALCON_CALL_METHOD(r9, index, "getcolumns", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(column_list);
			PHALCON_CALL_SELF_PARAMS_1(column_list, this_ptr, "getcolumnlist", r9);
			if (PHALCON_COMPARE_STRING(index_name, "PRIMARY")) {
				PHALCON_INIT_VAR(r10);
				PHALCON_CONCAT_SVS(r10, "PRIMARY KEY (", column_list, ")");
				phalcon_array_append(&create_lines, r10, PH_SEPARATE TSRMLS_CC);
			} else {
				PHALCON_INIT_VAR(r11);
				PHALCON_CONCAT_SVSVS(r11, "KEY `", index_name, "` (", column_list, ")");
				phalcon_array_append(&create_lines, r11, PH_SEPARATE TSRMLS_CC);
			}
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_52be_3;
		fee_52be_3:
		if(0){}
		
	}
	
	eval_int = phalcon_array_isset_string(definition, SL("references")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r12);
		phalcon_array_fetch_string(&r12, definition, SL("references"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(r12 TSRMLS_CC)) {
			return;
		}
		
		ah2 = Z_ARRVAL_P(r12);
		zend_hash_internal_pointer_reset_ex(ah2, &hp2);
		fes_52be_4:
			if(zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) != SUCCESS){
				goto fee_52be_4;
			}
			
			PHALCON_INIT_VAR(reference);
			ZVAL_ZVAL(reference, *hd, 1, 0);
			PHALCON_INIT_VAR(r13);
			PHALCON_CALL_METHOD(r13, reference, "getname", PH_NO_CHECK);
			PHALCON_INIT_VAR(r14);
			PHALCON_CALL_METHOD(r14, reference, "getcolumns", PH_NO_CHECK);
			PHALCON_INIT_VAR(r15);
			PHALCON_CALL_SELF_PARAMS_1(r15, this_ptr, "getcolumnlist", r14);
			PHALCON_INIT_VAR(reference_sql);
			PHALCON_CONCAT_SVSV(reference_sql, "CONSTRAINT `", r13, "` FOREIGN KEY (", r15);
			
			PHALCON_INIT_VAR(r16);
			PHALCON_CALL_METHOD(r16, reference, "getreferencedtable", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(r17);
			PHALCON_CALL_METHOD(r17, reference, "getreferencedcolumns", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(r18);
			PHALCON_CALL_SELF_PARAMS_1(r18, this_ptr, "getcolumnlist", r17);
			
			PHALCON_INIT_VAR(r19);
			PHALCON_CONCAT_SVSVS(r19, ") REFERENCES `", r16, "`(", r18, ")");
			phalcon_concat_self(&reference_sql, r19 TSRMLS_CC);
			phalcon_array_append(&create_lines, reference_sql, PH_SEPARATE TSRMLS_CC);
			zend_hash_move_forward_ex(ah2, &hp2);
			goto fes_52be_4;
		fee_52be_4:
		if(0){}
		
	}
	
	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, ",\n\t", 1);
	
	PHALCON_ALLOC_ZVAL_MM(r20);
	phalcon_fast_join(r20, c0, create_lines TSRMLS_CC);
	
	PHALCON_ALLOC_ZVAL_MM(r21);
	PHALCON_CONCAT_VS(r21, r20, "\n)");
	phalcon_concat_self(&sql, r21 TSRMLS_CC);
	eval_int = phalcon_array_isset_string(definition, SL("options")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r22);
		PHALCON_CALL_SELF_PARAMS_1(r22, this_ptr, "_gettableoptions", definition);
		PHALCON_ALLOC_ZVAL_MM(r23);
		PHALCON_CONCAT_SV(r23, " ", r22);
		phalcon_concat_self(&sql, r23 TSRMLS_CC);
	}
	
	
	RETURN_CTOR(sql);
}
Beispiel #13
0
/**
 * Generates SQL to add the table creation options
 *
 * @param array $definition
 * @return array
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){

	zval *definition = NULL, *table_options = NULL, *engine = NULL, *auto_increment = NULL;
	zval *table_collation = NULL, *collation_parts = NULL;
	zval *a0 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL;
	zval *c0 = NULL, *c1 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(a0);
	array_init(a0);
	PHALCON_CPY_WRT(table_options, a0);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	phalcon_array_fetch_string(&r0, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
	eval_int = phalcon_array_isset_string(r0, "ENGINE", strlen("ENGINE")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		phalcon_array_fetch_string(&r1, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r2);
		phalcon_array_fetch_string(&r2, r1, "ENGINE", strlen("ENGINE"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(engine, r2);
		
		PHALCON_ALLOC_ZVAL_MM(r3);
		phalcon_array_fetch_string(&r3, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		
		PHALCON_ALLOC_ZVAL_MM(r4);
		phalcon_array_fetch_string(&r4, r3, "ENGINE", strlen("ENGINE"), PHALCON_NOISY TSRMLS_CC);
		if (zend_is_true(r4)) {
			PHALCON_ALLOC_ZVAL_MM(r5);
			PHALCON_CONCAT_SV(r5, "ENGINE=", engine);
			phalcon_array_append(&table_options, r5, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r6);
	phalcon_array_fetch_string(&r6, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
	eval_int = phalcon_array_isset_string(r6, "AUTO_INCREMENT", strlen("AUTO_INCREMENT")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r7);
		phalcon_array_fetch_string(&r7, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r8);
		phalcon_array_fetch_string(&r8, r7, "AUTO_INCREMENT", strlen("AUTO_INCREMENT"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(auto_increment, r8);
		if (zend_is_true(auto_increment)) {
			PHALCON_ALLOC_ZVAL_MM(r9);
			PHALCON_CONCAT_SV(r9, "AUTO_INCREMENT=", auto_increment);
			phalcon_array_append(&table_options, r9, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r10);
	phalcon_array_fetch_string(&r10, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
	eval_int = phalcon_array_isset_string(r10, "TABLE_COLLATION", strlen("TABLE_COLLATION")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r11);
		phalcon_array_fetch_string(&r11, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r12);
		phalcon_array_fetch_string(&r12, r11, "TABLE_COLLATION", strlen("TABLE_COLLATION"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(table_collation, r12);
		if (zend_is_true(table_collation)) {
			PHALCON_INIT_VAR(c0);
			ZVAL_STRING(c0, "_", 1);
			PHALCON_ALLOC_ZVAL_MM(r13);
			phalcon_fast_explode(r13, c0, table_collation TSRMLS_CC);
			PHALCON_CPY_WRT(collation_parts, r13);
			
			PHALCON_ALLOC_ZVAL_MM(r14);
			
			PHALCON_ALLOC_ZVAL_MM(r15);
			phalcon_array_fetch_long(&r15, collation_parts, 0, PHALCON_NOISY TSRMLS_CC);
			PHALCON_CONCAT_SV(r14, "DEFAULT CHARSET=", r15);
			phalcon_array_append(&table_options, r14, PHALCON_SEPARATE_PLZ TSRMLS_CC);
			
			PHALCON_ALLOC_ZVAL_MM(r16);
			PHALCON_CONCAT_SV(r16, "COLLATE=", table_collation);
			phalcon_array_append(&table_options, r16, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r17);
	phalcon_fast_count(r17, table_options TSRMLS_CC);
	if (zend_is_true(r17)) {
		PHALCON_INIT_VAR(c1);
		ZVAL_STRING(c1, " ", 1);
		PHALCON_ALLOC_ZVAL_MM(r18);
		phalcon_fast_join(r18, c1, table_options TSRMLS_CC);
		PHALCON_RETURN_DZVAL(r18);
	}
	
	PHALCON_MM_RESTORE();
	RETURN_NULL();
}
Beispiel #14
0
/**
 * Helper method to query records based on a relation definition
 *
 * @param array $relation
 * @param string $method
 * @param Phalcon\Mvc\Model $record
 */
PHP_METHOD(Phalcon_Mvc_Model_Manager, _getRelationRecords){

	zval *relation = NULL, *method = NULL, *record = NULL, *conditions = NULL, *placeholders = NULL;
	zval *field = NULL, *value = NULL, *referenced_field = NULL, *condition = NULL;
	zval *i = NULL, *fields = NULL, *number_args = NULL, *function_arguments = NULL;
	zval *key = NULL, *join_conditions = NULL, *find_params = NULL, *arguments = NULL;
	zval *reference_table = NULL, *referenced_entity = NULL;
	zval *call_object = NULL, *records = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL;
	zval *c0 = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &relation, &method, &record) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(conditions);
	array_init(conditions);
	
	PHALCON_INIT_VAR(placeholders);
	array_init(placeholders);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	phalcon_array_fetch_string(&r0, relation, SL("fi"), PH_NOISY_CC);
	if (Z_TYPE_P(r0) != IS_ARRAY) { 
		PHALCON_INIT_VAR(field);
		phalcon_array_fetch_string(&field, relation, SL("fi"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(value);
		PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK);
		
		PHALCON_INIT_VAR(referenced_field);
		phalcon_array_fetch_string(&referenced_field, relation, SL("rf"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(condition);
		PHALCON_CONCAT_VS(condition, referenced_field, " = ?0");
		phalcon_array_update_long(&conditions, 0, &condition, PH_COPY | PH_SEPARATE TSRMLS_CC);
		phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC);
	} else {
		PHALCON_INIT_VAR(i);
		ZVAL_LONG(i, 0);
		
		PHALCON_INIT_VAR(fields);
		phalcon_array_fetch_string(&fields, relation, SL("fi"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(fields TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(fields);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_74b5_0:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_74b5_0;
			}
			
			PHALCON_INIT_VAR(field);
			ZVAL_ZVAL(field, *hd, 1, 0);
			PHALCON_INIT_VAR(value);
			PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK);
			
			PHALCON_INIT_VAR(r1);
			phalcon_array_fetch_string(&r1, relation, SL("rf"), PH_NOISY_CC);
			
			PHALCON_INIT_VAR(referenced_field);
			phalcon_array_fetch(&referenced_field, r1, i, PH_NOISY_CC);
			
			PHALCON_INIT_VAR(condition);
			PHALCON_CONCAT_VSV(condition, referenced_field, " = ?", i);
			phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC);
			phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC);
			PHALCON_SEPARATE(i);
			increment_function(i);
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_74b5_0;
		fee_74b5_0:
		if(0){}
		
	}
	
	PHALCON_INIT_VAR(number_args);
	PHALCON_CALL_FUNC(number_args, "func_num_args");
	
	PHALCON_INIT_VAR(t0);
	ZVAL_LONG(t0, 4);
	
	PHALCON_ALLOC_ZVAL_MM(r2);
	is_smaller_function(r2, t0, number_args TSRMLS_CC);
	if (zend_is_true(r2)) {
		PHALCON_INIT_VAR(function_arguments);
		PHALCON_CALL_FUNC(function_arguments, "func_get_args");
		if (!phalcon_valid_foreach(function_arguments TSRMLS_CC)) {
			return;
		}
		
		ah1 = Z_ARRVAL_P(function_arguments);
		zend_hash_internal_pointer_reset_ex(ah1, &hp1);
		fes_74b5_1:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_74b5_1;
			}
			
			PHALCON_INIT_VAR(key);
			PHALCON_GET_FOREACH_KEY(key, ah1, hp1);
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			PHALCON_INIT_VAR(t1);
			ZVAL_LONG(t1, 0);
			PHALCON_INIT_VAR(r3);
			is_equal_function(r3, key, t1 TSRMLS_CC);
			PHALCON_INIT_VAR(t2);
			ZVAL_STRING(t2, "conditions", 1);
			PHALCON_INIT_VAR(r4);
			is_equal_function(r4, key, t2 TSRMLS_CC);
			PHALCON_INIT_VAR(r5);
			ZVAL_BOOL(r5, zend_is_true(r3) || zend_is_true(r4));
			if (zend_is_true(r5)) {
				phalcon_array_append(&conditions, value, PH_SEPARATE TSRMLS_CC);
			}
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_74b5_1;
		fee_74b5_1:
		if(0){}
		
	}
	
	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, " AND ", 1);
	
	PHALCON_INIT_VAR(join_conditions);
	phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC);
	
	PHALCON_INIT_VAR(find_params);
	array_init(find_params);
	phalcon_array_append(&find_params, join_conditions, PH_SEPARATE TSRMLS_CC);
	phalcon_array_update_string(&find_params, SL("bind"), &placeholders, PH_COPY | PH_SEPARATE TSRMLS_CC);
	
	PHALCON_INIT_VAR(arguments);
	array_init(arguments);
	phalcon_array_append(&arguments, find_params, PH_SEPARATE TSRMLS_CC);
	
	PHALCON_INIT_VAR(reference_table);
	phalcon_array_fetch_string(&reference_table, relation, SL("rt"), PH_NOISY_CC);
	ce0 = phalcon_fetch_class(reference_table TSRMLS_CC);
	
	PHALCON_INIT_VAR(referenced_entity);
	object_init_ex(referenced_entity, ce0);
	PHALCON_CALL_METHOD_NORETURN(referenced_entity, "__construct", PH_CHECK);
	
	PHALCON_ALLOC_ZVAL_MM(r6);
	PHALCON_CALL_METHOD(r6, record, "getconnectionservice", PH_NO_CHECK);
	PHALCON_CALL_METHOD_PARAMS_1_NORETURN(referenced_entity, "setconnectionservice", r6, PH_NO_CHECK);
	
	PHALCON_INIT_VAR(call_object);
	array_init(call_object);
	phalcon_array_append(&call_object, referenced_entity, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&call_object, method, PH_SEPARATE TSRMLS_CC);
	
	PHALCON_INIT_VAR(records);
	PHALCON_CALL_FUNC_PARAMS_2(records, "call_user_func_array", call_object, arguments);
	
	RETURN_CCTOR(records);
}
Beispiel #15
0
/**
 * Builds a SELECT statement
 *
 * @param array $definition
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect, select){

	zval *definition = NULL, *columns = NULL, *comma = NULL, *columns_sql = NULL;
	zval *tables = NULL, *tables_sql = NULL, *sql = NULL, *joins = NULL, *join = NULL, *type = NULL;
	zval *source = NULL, *sql_join = NULL, *and_word = NULL, *join_conditions_array = NULL;
	zval *join_conditions = NULL, *on_join = NULL, *where_conditions = NULL;
	zval *where_clause = NULL, *group_fields = NULL, *group_clause = NULL;
	zval *having_conditions = NULL, *having_clause = NULL, *order_fields = NULL;
	zval *order_clause = NULL, *limit_value = NULL, *limit_clause = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	eval_int = phalcon_array_isset_string(definition, SL("tables")+1);
	if (!eval_int) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'tables' is required in the definition array");
		return;
	}
	eval_int = phalcon_array_isset_string(definition, SL("columns")+1);
	if (!eval_int) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array");
		return;
	}
	
	PHALCON_INIT_VAR(columns);
	phalcon_array_fetch_string(&columns, definition, SL("columns"), PH_NOISY_CC);
	if (Z_TYPE_P(columns) == IS_ARRAY) { 
		PHALCON_INIT_VAR(comma);
		ZVAL_STRING(comma, ",", 1);
		
		PHALCON_INIT_VAR(columns_sql);
		phalcon_fast_join(columns_sql, comma, columns TSRMLS_CC);
	} else {
		PHALCON_CPY_WRT(columns_sql, columns);
	}
	
	PHALCON_INIT_VAR(tables);
	phalcon_array_fetch_string(&tables, definition, SL("tables"), PH_NOISY_CC);
	if (Z_TYPE_P(tables) == IS_ARRAY) { 
		PHALCON_INIT_VAR(comma);
		ZVAL_STRING(comma, ",", 1);
		
		PHALCON_INIT_VAR(tables_sql);
		phalcon_fast_join(tables_sql, comma, tables TSRMLS_CC);
	} else {
		PHALCON_CPY_WRT(tables_sql, tables);
	}
	
	PHALCON_INIT_VAR(sql);
	PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql);
	eval_int = phalcon_array_isset_string(definition, SL("joins")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(joins);
		phalcon_array_fetch_string(&joins, definition, SL("joins"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(joins TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(joins);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_62b2_0:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_62b2_0;
			}
			
			PHALCON_INIT_VAR(join);
			ZVAL_ZVAL(join, *hd, 1, 0);
			PHALCON_INIT_VAR(type);
			phalcon_array_fetch_string(&type, join, SL("type"), PH_NOISY_CC);
			
			PHALCON_INIT_VAR(source);
			phalcon_array_fetch_string(&source, join, SL("source"), PH_NOISY_CC);
			
			PHALCON_INIT_VAR(sql_join);
			PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", source);
			eval_int = phalcon_array_isset_string(join, SL("conditions")+1);
			if (eval_int) {
				PHALCON_INIT_VAR(and_word);
				ZVAL_STRING(and_word, " AND ", 1);
				
				PHALCON_INIT_VAR(join_conditions_array);
				phalcon_array_fetch_string(&join_conditions_array, join, SL("conditions"), PH_NOISY_CC);
				
				PHALCON_INIT_VAR(join_conditions);
				phalcon_fast_join(join_conditions, and_word, join_conditions_array TSRMLS_CC);
				
				PHALCON_INIT_VAR(on_join);
				PHALCON_CONCAT_SV(on_join, " ON ", join_conditions);
				phalcon_concat_self(&sql_join, on_join TSRMLS_CC);
			}
			
			phalcon_concat_self(&sql, sql_join TSRMLS_CC);
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_62b2_0;
		fee_62b2_0:
		if(0){}
		
	}
	
	eval_int = phalcon_array_isset_string(definition, SL("where")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(where_conditions);
		phalcon_array_fetch_string(&where_conditions, definition, SL("where"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(where_clause);
		PHALCON_CONCAT_SV(where_clause, " WHERE ", where_conditions);
		phalcon_concat_self(&sql, where_clause TSRMLS_CC);
	}
	
	eval_int = phalcon_array_isset_string(definition, SL("group")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(group_fields);
		phalcon_array_fetch_string(&group_fields, definition, SL("group"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(group_clause);
		PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_fields);
		phalcon_concat_self(&sql, group_clause TSRMLS_CC);
		eval_int = phalcon_array_isset_string(definition, SL("having")+1);
		if (eval_int) {
			PHALCON_INIT_VAR(having_conditions);
			phalcon_array_fetch_string(&having_conditions, definition, SL("having"), PH_NOISY_CC);
			
			PHALCON_INIT_VAR(having_clause);
			PHALCON_CONCAT_SV(having_clause, " HAVING ", having_conditions);
			phalcon_concat_self(&sql, having_clause TSRMLS_CC);
		}
	}
	
	eval_int = phalcon_array_isset_string(definition, SL("order")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(order_fields);
		phalcon_array_fetch_string(&order_fields, definition, SL("order"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(order_clause);
		PHALCON_CONCAT_SV(order_clause, " ORDER BY ", order_fields);
		phalcon_concat_self(&sql, order_clause TSRMLS_CC);
	}
	
	eval_int = phalcon_array_isset_string(definition, SL("limit")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(limit_value);
		phalcon_array_fetch_string(&limit_value, definition, SL("limit"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(limit_clause);
		PHALCON_CONCAT_SV(limit_clause, " LIMIT ", limit_value);
		phalcon_concat_self(&sql, limit_clause TSRMLS_CC);
	}
	
	
	RETURN_CTOR(sql);
}
Beispiel #16
0
/**
 * Outputs a message formatting it with HTML
 *
 * @param string $type
 * @param string $message
 */
PHP_METHOD(Phalcon_Flash, outputMessage){

	zval *type = NULL, *message = NULL, *automatic_html = NULL, *classes = NULL;
	zval *type_classes = NULL, *space = NULL, *joined_classes = NULL;
	zval *css_classes = NULL, *eol = NULL, *implicit_flush = NULL, *content = NULL;
	zval *msg = NULL, *html_message = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &type, &message) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(automatic_html);
	phalcon_read_property(&automatic_html, this_ptr, SL("_automaticHtml"), PH_NOISY_CC);
	if (PHALCON_IS_TRUE(automatic_html)) {
		PHALCON_INIT_VAR(classes);
		phalcon_read_property(&classes, this_ptr, SL("_cssClasses"), PH_NOISY_CC);
		eval_int = phalcon_array_isset(classes, type);
		if (eval_int) {
			PHALCON_INIT_VAR(type_classes);
			phalcon_array_fetch(&type_classes, classes, type, PH_NOISY_CC);
			if (Z_TYPE_P(type_classes) == IS_ARRAY) { 
				PHALCON_INIT_VAR(space);
				ZVAL_STRING(space, " ", 1);
				
				PHALCON_INIT_VAR(joined_classes);
				phalcon_fast_join(joined_classes, space, type_classes TSRMLS_CC);
				
				PHALCON_INIT_VAR(css_classes);
				PHALCON_CONCAT_SVS(css_classes, " class=\"", joined_classes, "\"");
			} else {
				PHALCON_INIT_VAR(css_classes);
				PHALCON_CONCAT_SVS(css_classes, " class=\"", type_classes, "\"");
			}
		} else {
			PHALCON_INIT_VAR(css_classes);
			ZVAL_STRING(css_classes, "", 1);
		}
		
		PHALCON_INIT_VAR(eol);
		zend_get_constant(SL("PHP_EOL"), eol TSRMLS_CC);
	}
	
	PHALCON_INIT_VAR(implicit_flush);
	phalcon_read_property(&implicit_flush, this_ptr, SL("_implicitFlush"), PH_NOISY_CC);
	if (Z_TYPE_P(message) == IS_ARRAY) { 
		if (PHALCON_IS_FALSE(implicit_flush)) {
			PHALCON_INIT_VAR(content);
			ZVAL_STRING(content, "", 1);
		}
		if (!phalcon_valid_foreach(message TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(message);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_3b3c_0:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_3b3c_0;
			}
			
			PHALCON_INIT_VAR(msg);
			ZVAL_ZVAL(msg, *hd, 1, 0);
			if (PHALCON_IS_TRUE(automatic_html)) {
				PHALCON_INIT_VAR(html_message);
				PHALCON_CONCAT_SVSVSV(html_message, "<div", css_classes, ">", msg, "</div>", eol);
			} else {
				PHALCON_CPY_WRT(html_message, msg);
			}
			if (PHALCON_IS_TRUE(implicit_flush)) {
				zend_print_zval(html_message, 1);
			} else {
				phalcon_concat_self(&content, html_message TSRMLS_CC);
			}
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_3b3c_0;
		fee_3b3c_0:
		
		if (PHALCON_IS_FALSE(implicit_flush)) {
			
			RETURN_CTOR(content);
		}
	} else {
		if (PHALCON_IS_TRUE(automatic_html)) {
			PHALCON_INIT_VAR(html_message);
			PHALCON_CONCAT_SVSVSV(html_message, "<div", css_classes, ">", message, "</div>", eol);
		} else {
			PHALCON_CPY_WRT(html_message, message);
		}
		if (PHALCON_IS_TRUE(implicit_flush)) {
			zend_print_zval(html_message, 1);
		} else {
			
			RETURN_CCTOR(html_message);
		}
	}
	
	PHALCON_MM_RESTORE();
}
Beispiel #17
0
/**
 * Updates data on a table using custom RBDM SQL syntax
 *
 * @param string $table
 * @param array $fields
 * @param array $values
 * @param string $whereCondition
 * @return boolean
 */
PHP_METHOD(Phalcon_Db, update){

	zval *table = NULL, *fields = NULL, *values = NULL, *where_condition = NULL;
	zval *placeholders = NULL, *value = NULL, *position = NULL, *field = NULL, *set_clause_part = NULL;
	zval *comma = NULL, *set_clause = NULL, *update_sql = NULL, *success = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|z", &table, &fields, &values, &where_condition) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_SEPARATE_PARAM(values);
	
	if (!where_condition) {
		PHALCON_ALLOC_ZVAL_MM(where_condition);
		ZVAL_NULL(where_condition);
	}
	
	PHALCON_INIT_VAR(placeholders);
	array_init(placeholders);
	
	if (!phalcon_valid_foreach(values TSRMLS_CC)) {
		return;
	}
	
	ALLOC_HASHTABLE(ah0);
	zend_hash_init(ah0, 0, NULL, NULL, 0);
	zend_hash_copy(ah0, Z_ARRVAL_P(values), NULL, NULL, sizeof(zval*));
	zend_hash_internal_pointer_reset_ex(ah0, &hp0);
	
	ph_cycle_start_0:
	
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto ph_cycle_end_0;
		}
		
		PHALCON_INIT_VAR(position);
		PHALCON_GET_FOREACH_KEY(position, ah0, hp0);
		PHALCON_GET_FOREACH_VALUE(value);
		
		eval_int = phalcon_array_isset(fields, position);
		if (eval_int) {
			PHALCON_INIT_VAR(field);
			phalcon_array_fetch(&field, fields, position, PH_NOISY_CC);
			if (Z_TYPE_P(value) == IS_OBJECT) {
				PHALCON_INIT_VAR(set_clause_part);
				PHALCON_CONCAT_VSV(set_clause_part, field, " = ", value);
				phalcon_array_append(&placeholders, set_clause_part, PH_SEPARATE TSRMLS_CC);
				PHALCON_SEPARATE_PARAM(values);
				phalcon_array_unset(values, position);
			} else {
				if (Z_TYPE_P(value) == IS_NULL) {
					PHALCON_INIT_VAR(set_clause_part);
					PHALCON_CONCAT_VS(set_clause_part, field, " = null");
					PHALCON_SEPARATE_PARAM(values);
					phalcon_array_unset(values, position);
				} else {
					PHALCON_INIT_VAR(set_clause_part);
					PHALCON_CONCAT_VS(set_clause_part, field, " = ?");
				}
				phalcon_array_append(&placeholders, set_clause_part, PH_SEPARATE TSRMLS_CC);
			}
		} else {
			PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The number of values in the update is not the same as fields");
			return;
		}
		
		zend_hash_move_forward_ex(ah0, &hp0);
		goto ph_cycle_start_0;
	
	ph_cycle_end_0:
	zend_hash_destroy(ah0);
	efree(ah0);
	
	PHALCON_INIT_VAR(comma);
	ZVAL_STRING(comma, ", ", 1);
	
	PHALCON_INIT_VAR(set_clause);
	phalcon_fast_join(set_clause, comma, placeholders TSRMLS_CC);
	if (Z_TYPE_P(where_condition) != IS_NULL) {
		PHALCON_INIT_VAR(update_sql);
		PHALCON_CONCAT_SVSVSV(update_sql, "UPDATE ", table, " SET ", set_clause, " WHERE ", where_condition);
	} else {
		PHALCON_INIT_VAR(update_sql);
		PHALCON_CONCAT_SVSV(update_sql, "UPDATE ", table, " SET ", set_clause);
	}
	
	PHALCON_INIT_VAR(success);
	PHALCON_CALL_METHOD_PARAMS_2(success, this_ptr, "execute", update_sql, values, PH_NO_CHECK);
	
	RETURN_CCTOR(success);
}
Beispiel #18
0
/**
 * Builds a Phalcon\Mvc\Model\Criteria based on an input array like $_POST
 *
 * @param Phalcon\DI $dependencyInjector
 * @param string $modelName
 * @param array $data
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){

	zval *dependency_injector = NULL, *model_name = NULL, *data = NULL;
	zval *conditions = NULL, *number_data = NULL, *service = NULL, *meta_data = NULL;
	zval *model = NULL, *data_types = NULL, *bind = NULL, *value = NULL, *field = NULL, *type = NULL;
	zval *condition = NULL, *value_pattern = NULL, *criteria = NULL, *number_conditions = NULL;
	zval *join_conditions = NULL;
	zval *c0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &dependency_injector, &model_name, &data) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (Z_TYPE_P(data) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array");
		return;
	}
	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services");
		return;
	}
	
	PHALCON_INIT_VAR(conditions);
	array_init(conditions);
	
	PHALCON_INIT_VAR(number_data);
	phalcon_fast_count(number_data, data TSRMLS_CC);
	if (!phalcon_compare_strict_long(number_data, 0 TSRMLS_CC)) {
		PHALCON_INIT_VAR(service);
		ZVAL_STRING(service, "modelsMetadata", 1);
		
		PHALCON_INIT_VAR(meta_data);
		PHALCON_CALL_METHOD_PARAMS_1(meta_data, dependency_injector, "getshared", service, PH_NO_CHECK);
		ce0 = phalcon_fetch_class(model_name TSRMLS_CC);
		
		PHALCON_INIT_VAR(model);
		object_init_ex(model, ce0);
		PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK);
		
		PHALCON_INIT_VAR(data_types);
		PHALCON_CALL_METHOD_PARAMS_1(data_types, meta_data, "getdatatypes", model, PH_NO_CHECK);
		
		PHALCON_INIT_VAR(bind);
		array_init(bind);
		if (!phalcon_valid_foreach(data TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(data);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_1d26_0:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_1d26_0;
			}
			
			PHALCON_INIT_VAR(field);
			PHALCON_GET_FOREACH_KEY(field, ah0, hp0);
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			eval_int = phalcon_array_isset(data_types, field);
			if (eval_int) {
				if (Z_TYPE_P(value) != IS_NULL) {
					if (!PHALCON_COMPARE_STRING(value, "")) {
						PHALCON_INIT_VAR(type);
						phalcon_array_fetch(&type, data_types, field, PH_NOISY_CC);
						if (phalcon_compare_strict_long(type, 2 TSRMLS_CC)) {
							PHALCON_INIT_VAR(condition);
							PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":");
							
							PHALCON_INIT_VAR(value_pattern);
							PHALCON_CONCAT_SVS(value_pattern, "%", value, "%");
							phalcon_array_update_zval(&bind, field, &value_pattern, PH_COPY | PH_SEPARATE TSRMLS_CC);
						} else {
							PHALCON_INIT_VAR(condition);
							PHALCON_CONCAT_VSVS(condition, field, "=:", field, ":");
							phalcon_array_update_zval(&bind, field, &value, PH_COPY | PH_SEPARATE TSRMLS_CC);
						}
						
						phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC);
					}
				}
			}
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_1d26_0;
		fee_1d26_0:
		if(0){}
		
	}
	
	PHALCON_INIT_VAR(criteria);
	object_init_ex(criteria, phalcon_mvc_model_criteria_ce);
	PHALCON_CALL_METHOD_NORETURN(criteria, "__construct", PH_CHECK);
	
	PHALCON_INIT_VAR(number_conditions);
	phalcon_fast_count(number_conditions, conditions TSRMLS_CC);
	if (!phalcon_compare_strict_long(number_conditions, 0 TSRMLS_CC)) {
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, " AND ", 1);
		PHALCON_INIT_VAR(join_conditions);
		phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC);
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(criteria, "where", join_conditions, PH_NO_CHECK);
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(criteria, "bind", bind, PH_NO_CHECK);
	}
	
	
	RETURN_CTOR(criteria);
}
Beispiel #19
0
/**
 * Updates data on a table using custom RBDM SQL syntax
 *
 * 
 *
 * @param string $table
 * @param array $fields
 * @param array $values
 * @param string $whereCondition
 * @param boolean $automaticQuotes
 * @return boolean
 */
PHP_METHOD(Phalcon_Db, update){

	zval *table = NULL, *fields = NULL, *values = NULL, *where_condition = NULL;
	zval *automatic_quotes = NULL, *i = NULL, *update_values = NULL, *update_sql = NULL;
	zval *field = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL;
	zval *a0 = NULL;
	zval *c0 = NULL;
	zval *t0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|zz", &table, &fields, &values, &where_condition, &automatic_quotes) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_SEPARATE_PARAM(values);
	
	if (!where_condition) {
		PHALCON_INIT_VAR(where_condition);
		ZVAL_NULL(where_condition);
	}
	
	if (!automatic_quotes) {
		PHALCON_INIT_VAR(automatic_quotes);
		ZVAL_BOOL(automatic_quotes, 0);
	}
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	phalcon_fast_count(r0, fields TSRMLS_CC);
	PHALCON_ALLOC_ZVAL_MM(r1);
	phalcon_fast_count(r1, values TSRMLS_CC);
	PHALCON_INIT_VAR(r2);
	is_not_equal_function(r2, r0, r1 TSRMLS_CC);
	if (zend_is_true(r2)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The number of values to update is not the same as fields");
		return;
	}
	
	PHALCON_INIT_VAR(i);
	ZVAL_LONG(i, 0);
	
	PHALCON_INIT_VAR(a0);
	array_init(a0);
	PHALCON_CPY_WRT(update_values, a0);
	
	PHALCON_ALLOC_ZVAL_MM(r3);
	PHALCON_CONCAT_SVS(r3, "UPDATE ", table, " SET ");
	PHALCON_CPY_WRT(update_sql, r3);
	if (phalcon_valid_foreach(fields TSRMLS_CC)) {
		ah0 = Z_ARRVAL_P(fields);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_e7f0_2:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_e7f0_2;
		}
		
		PHALCON_INIT_VAR(field);
		ZVAL_ZVAL(field, *hd, 1, 0);
		if (zend_is_true(automatic_quotes)) {
			PHALCON_INIT_VAR(r4);
			phalcon_array_fetch(&r4, values, i, PHALCON_NOISY TSRMLS_CC);
			if (Z_TYPE_P(r4) == IS_OBJECT) {
				PHALCON_INIT_VAR(r5);
				phalcon_array_fetch(&r5, values, i, PHALCON_NOISY TSRMLS_CC);
				PHALCON_INIT_VAR(r6);
				phalcon_instance_of(r6, r5, phalcon_db_rawvalue_ce TSRMLS_CC);
				if (zend_is_true(r6)) {
					PHALCON_INIT_VAR(r7);
					PHALCON_INIT_VAR(r8);
					PHALCON_INIT_VAR(r9);
					phalcon_array_fetch(&r9, values, i, PHALCON_NOISY TSRMLS_CC);
					PHALCON_CALL_METHOD(r8, r9, "getvalue", PHALCON_NO_CHECK);
					PHALCON_CALL_METHOD_PARAMS_1(r7, this_ptr, "escapestring", r8, PHALCON_NO_CHECK);
					phalcon_array_update(&values, i, &r7, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
					goto fes_e7f0_2;
				}
			}
			
			PHALCON_INIT_VAR(r10);
			
			PHALCON_INIT_VAR(r11);
			
			PHALCON_INIT_VAR(r12);
			phalcon_array_fetch(&r12, values, i, PHALCON_NOISY TSRMLS_CC);
			PHALCON_CALL_METHOD_PARAMS_1(r11, this_ptr, "escapestring", r12, PHALCON_NO_CHECK);
			PHALCON_CONCAT_SVS(r10, "'", r11, "'");
			phalcon_array_update(&values, i, &r10, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
		}
		
		PHALCON_INIT_VAR(r13);
		
		PHALCON_INIT_VAR(r14);
		phalcon_array_fetch(&r14, values, i, PHALCON_NOISY TSRMLS_CC);
		PHALCON_CONCAT_VSV(r13, field, " = ", r14);
		phalcon_array_append(&update_values, r13, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		PHALCON_SEPARATE(i);
		increment_function(i);
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_e7f0_2;
		fee_e7f0_2:
		if(0){}
	} else {
		return;
	}
	
	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, ", ", 1);
	
	PHALCON_ALLOC_ZVAL_MM(r15);
	phalcon_fast_join(r15, c0, update_values TSRMLS_CC);
	phalcon_concat_self(&update_sql, r15 TSRMLS_CC);
	
	PHALCON_INIT_VAR(t0);
	ZVAL_NULL(t0);
	
	PHALCON_INIT_VAR(r16);
	is_not_equal_function(r16, where_condition, t0 TSRMLS_CC);
	if (zend_is_true(r16)) {
		PHALCON_ALLOC_ZVAL_MM(r17);
		PHALCON_CONCAT_SV(r17, " WHERE ", where_condition);
		phalcon_concat_self(&update_sql, r17 TSRMLS_CC);
	}
	
	PHALCON_ALLOC_ZVAL_MM(r18);
	PHALCON_CALL_METHOD_PARAMS_1(r18, this_ptr, "query", update_sql, PHALCON_NO_CHECK);
	PHALCON_RETURN_DZVAL(r18);
}
Beispiel #20
0
/**
 * Inserts data into a table using custom RBDM SQL syntax
 *
 * 
 *
 * @param string $table
 * @param array $values
 * @param array $fields
 * @param boolean $automaticQuotes
 * @return boolean
 */
PHP_METHOD(Phalcon_Db, insert){

	zval *table = NULL, *values = NULL, *fields = NULL, *automatic_quotes = NULL;
	zval *value = NULL, *key = NULL, *joined_values = NULL, *insert_sql = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL;
	zval *i0 = NULL;
	zval *c0 = NULL, *c1 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|zz", &table, &values, &fields, &automatic_quotes) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_SEPARATE_PARAM(values);
	
	if (!fields) {
		PHALCON_INIT_VAR(fields);
		ZVAL_NULL(fields);
	}
	
	if (!automatic_quotes) {
		PHALCON_INIT_VAR(automatic_quotes);
		ZVAL_BOOL(automatic_quotes, 0);
	}
	
	if (Z_TYPE_P(values) == IS_ARRAY) { 
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_fast_count(r0, values TSRMLS_CC);
		if (!zend_is_true(r0)) {
			PHALCON_ALLOC_ZVAL_MM(i0);
			object_init_ex(i0, phalcon_db_exception_ce);
			PHALCON_ALLOC_ZVAL_MM(r1);
			PHALCON_CONCAT_SVS(r1, "Unable to insert into ", table, " without data");
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r1, PHALCON_CHECK);
			phalcon_throw_exception(i0 TSRMLS_CC);
			return;
		} else {
			if (zend_is_true(automatic_quotes)) {
				if (phalcon_valid_foreach(values TSRMLS_CC)) {
					ALLOC_HASHTABLE(ah0);
					zend_hash_init(ah0, 0, NULL, NULL, 0);
					zend_hash_copy(ah0, Z_ARRVAL_P(values), NULL, NULL, sizeof(zval*));
					zend_hash_internal_pointer_reset_ex(ah0, &hp0);
					fes_e7f0_1:
					if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
						goto fee_e7f0_1;
					} else {
						PHALCON_INIT_VAR(key);
						PHALCON_GET_FOREACH_KEY(key, ah0, hp0);
					}
					PHALCON_INIT_VAR(value);
					ZVAL_ZVAL(value, *hd, 1, 0);
					if (Z_TYPE_P(value) == IS_OBJECT) {
						PHALCON_INIT_VAR(r2);
						phalcon_instance_of(r2, value, phalcon_db_rawvalue_ce TSRMLS_CC);
						if (zend_is_true(r2)) {
							PHALCON_INIT_VAR(r3);
							PHALCON_CALL_METHOD_PARAMS_1(r3, this_ptr, "escapestring", value, PHALCON_NO_CHECK);
							phalcon_array_update(&values, key, &r3, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
							goto fes_e7f0_1;
						}
					}
					
					PHALCON_INIT_VAR(r4);
					
					PHALCON_INIT_VAR(r5);
					PHALCON_CALL_METHOD_PARAMS_1(r5, this_ptr, "escapestring", value, PHALCON_NO_CHECK);
					PHALCON_CONCAT_SVS(r4, "'", r5, "'");
					phalcon_array_update(&values, key, &r4, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
					zend_hash_move_forward_ex(ah0, &hp0);
					goto fes_e7f0_1;
					fee_e7f0_1:
					zend_hash_destroy(ah0);
					efree(ah0);
				} else {
					return;
				}
			}
		}
		
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, ", ", 1);
		
		PHALCON_ALLOC_ZVAL_MM(r6);
		phalcon_fast_join(r6, c0, values TSRMLS_CC);
		PHALCON_CPY_WRT(joined_values, r6);
		if (Z_TYPE_P(fields) == IS_ARRAY) { 
			PHALCON_ALLOC_ZVAL_MM(r7);
			PHALCON_INIT_VAR(c1);
			ZVAL_STRING(c1, ", ", 1);
			PHALCON_ALLOC_ZVAL_MM(r8);
			phalcon_fast_join(r8, c1, fields TSRMLS_CC);
			PHALCON_CONCAT_SVSVSVS(r7, "INSERT INTO ", table, " (", r8, ") VALUES (", joined_values, ")");
			PHALCON_CPY_WRT(insert_sql, r7);
		} else {
			PHALCON_ALLOC_ZVAL_MM(r9);
			PHALCON_CONCAT_SVSVS(r9, "INSERT INTO ", table, " VALUES (", joined_values, ")");
			PHALCON_CPY_WRT(insert_sql, r9);
		}
		
		PHALCON_ALLOC_ZVAL_MM(r10);
		PHALCON_CALL_METHOD_PARAMS_1(r10, this_ptr, "query", insert_sql, PHALCON_NO_CHECK);
		PHALCON_RETURN_DZVAL(r10);
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array");
		return;
	}
	
	PHALCON_MM_RESTORE();
}
Beispiel #21
0
/**
 * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor.
 * Call it when you need to restore a database connection
 *
 * @param array $descriptor
 * @return boolean
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){

	zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts = NULL;
	zval *value = NULL, *key = NULL, *dsn = NULL, *options = NULL, *persistent = NULL;
	zval *r0 = NULL, *r1 = NULL;
	zval *t0 = NULL;
	zval *c0 = NULL;
	zval *i0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (!descriptor) {
		PHALCON_ALLOC_ZVAL_MM(descriptor);
		ZVAL_NULL(descriptor);
	} else {
		PHALCON_SEPARATE_PARAM(descriptor);
	}
	
	if (!zend_is_true(descriptor)) {
		PHALCON_INIT_VAR(descriptor);
		phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC);
	}
	eval_int = phalcon_array_isset_string(descriptor, SL("username")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(username);
		phalcon_array_fetch_string(&username, descriptor, SL("username"), PH_NOISY_CC);
		PHALCON_SEPARATE_PARAM(descriptor);
		phalcon_array_unset_string(descriptor, SL("username")+1);
	} else {
		PHALCON_INIT_VAR(username);
		ZVAL_NULL(username);
	}
	
	eval_int = phalcon_array_isset_string(descriptor, SL("password")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(password);
		phalcon_array_fetch_string(&password, descriptor, SL("password"), PH_NOISY_CC);
		PHALCON_SEPARATE_PARAM(descriptor);
		phalcon_array_unset_string(descriptor, SL("password")+1);
	} else {
		PHALCON_INIT_VAR(password);
		ZVAL_NULL(password);
	}
	
	PHALCON_INIT_VAR(dsn_parts);
	array_init(dsn_parts);
	if (!phalcon_valid_foreach(descriptor TSRMLS_CC)) {
		return;
	}
	
	ah0 = Z_ARRVAL_P(descriptor);
	zend_hash_internal_pointer_reset_ex(ah0, &hp0);
	fes_7f5d_0:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_7f5d_0;
		}
		
		PHALCON_INIT_VAR(key);
		PHALCON_GET_FOREACH_KEY(key, ah0, hp0);
		PHALCON_INIT_VAR(value);
		ZVAL_ZVAL(value, *hd, 1, 0);
		PHALCON_INIT_VAR(r0);
		PHALCON_CONCAT_VSV(r0, key, "=", value);
		phalcon_array_append(&dsn_parts, r0, PH_SEPARATE TSRMLS_CC);
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_7f5d_0;
	fee_7f5d_0:
	if(0){}
	
	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, SL("_type"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, ";", 1);
	
	PHALCON_ALLOC_ZVAL_MM(r1);
	phalcon_fast_join(r1, c0, dsn_parts TSRMLS_CC);
	
	PHALCON_INIT_VAR(dsn);
	PHALCON_CONCAT_VSV(dsn, t0, ":", r1);
	
	PHALCON_INIT_VAR(options);
	array_init(options);
	add_index_long(options, 3, 0);
	add_index_long(options, 8, 2);
	add_index_long(options, 10, 1);
	eval_int = phalcon_array_isset_string(descriptor, SL("persistent")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(persistent);
		phalcon_array_fetch_string(&persistent, descriptor, SL("persistent"), PH_NOISY_CC);
		if (zend_is_true(persistent)) {
			phalcon_array_update_long_bool(&options, 12, 1, PH_SEPARATE TSRMLS_CC);
		}
	}
	
	ce0 = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
	
	PHALCON_ALLOC_ZVAL_MM(i0);
	object_init_ex(i0, ce0);
	PHALCON_CALL_METHOD_PARAMS_4_NORETURN(i0, "__construct", dsn, username, password, options, PH_CHECK);
	phalcon_update_property_zval(this_ptr, SL("_pdo"), i0 TSRMLS_CC);
	PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo", "__construct", descriptor);
	
	PHALCON_MM_RESTORE();
}
Beispiel #22
0
/**
 * Inserts data into a table using custom RBDM SQL syntax
 *
 * @param string $table
 * @param array $values
 * @param array $fields
 * @return boolean
 */
PHP_METHOD(Phalcon_Db, insert){

	zval *table = NULL, *values = NULL, *fields = NULL, *number_values = NULL, *exception_message = NULL;
	zval *exception = NULL, *placeholders = NULL, *value = NULL, *position = NULL;
	zval *str_value = NULL, *comma = NULL, *joined_values = NULL, *joined_fields = NULL;
	zval *insert_sql = NULL, *success = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &table, &values, &fields) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_SEPARATE_PARAM(values);
	
	if (!fields) {
		PHALCON_ALLOC_ZVAL_MM(fields);
		ZVAL_NULL(fields);
	}
	
	if (Z_TYPE_P(values) == IS_ARRAY) { 
		PHALCON_INIT_VAR(number_values);
		phalcon_fast_count(number_values, values TSRMLS_CC);
		if (phalcon_compare_strict_long(number_values, 0 TSRMLS_CC)) {
			PHALCON_INIT_VAR(exception_message);
			PHALCON_CONCAT_SVS(exception_message, "Unable to insert into ", table, " without data");
			
			PHALCON_INIT_VAR(exception);
			object_init_ex(exception, phalcon_db_exception_ce);
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK);
			phalcon_throw_exception(exception TSRMLS_CC);
			return;
		}
		
		PHALCON_INIT_VAR(placeholders);
		array_init(placeholders);
		
		if (!phalcon_valid_foreach(values TSRMLS_CC)) {
			return;
		}
		
		ALLOC_HASHTABLE(ah0);
		zend_hash_init(ah0, 0, NULL, NULL, 0);
		zend_hash_copy(ah0, Z_ARRVAL_P(values), NULL, NULL, sizeof(zval*));
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		
		ph_cycle_start_0:
		
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto ph_cycle_end_0;
			}
			
			PHALCON_INIT_VAR(position);
			PHALCON_GET_FOREACH_KEY(position, ah0, hp0);
			PHALCON_GET_FOREACH_VALUE(value);
			
			if (Z_TYPE_P(value) == IS_OBJECT) {
				PHALCON_INIT_VAR(str_value);
				PHALCON_CALL_FUNC_PARAMS_1(str_value, "strval", value);
				phalcon_array_append(&placeholders, str_value, PH_SEPARATE TSRMLS_CC);
				PHALCON_SEPARATE_PARAM(values);
				phalcon_array_unset(values, position);
			} else {
				if (Z_TYPE_P(value) == IS_NULL) {
					phalcon_array_append_string(&placeholders, SL("null"), PH_SEPARATE TSRMLS_CC);
					PHALCON_SEPARATE_PARAM(values);
					phalcon_array_unset(values, position);
				} else {
					phalcon_array_append_string(&placeholders, SL("?"), PH_SEPARATE TSRMLS_CC);
				}
			}
			
			zend_hash_move_forward_ex(ah0, &hp0);
			goto ph_cycle_start_0;
		
		ph_cycle_end_0:
		zend_hash_destroy(ah0);
		efree(ah0);
		
		PHALCON_INIT_VAR(comma);
		ZVAL_STRING(comma, ", ", 1);
		
		PHALCON_INIT_VAR(joined_values);
		phalcon_fast_join(joined_values, comma, placeholders TSRMLS_CC);
		if (Z_TYPE_P(fields) == IS_ARRAY) { 
			PHALCON_INIT_VAR(joined_fields);
			phalcon_fast_join(joined_fields, comma, fields TSRMLS_CC);
			
			PHALCON_INIT_VAR(insert_sql);
			PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", table, " (", joined_fields, ") VALUES (", joined_values, ")");
		} else {
			PHALCON_INIT_VAR(insert_sql);
			PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", table, " VALUES (", joined_values, ")");
		}
		
		PHALCON_INIT_VAR(success);
		PHALCON_CALL_METHOD_PARAMS_2(success, this_ptr, "execute", insert_sql, values, PH_NO_CHECK);
		
		RETURN_CCTOR(success);
	}
	PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array");
	return;
}
Beispiel #23
0
/**
 * Executes validator
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Mvc_Model_Validator_Exclusionin, validate){

	zval *record = NULL, *field_name = NULL, *domain = NULL, *value = NULL;
	zval *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL, *c4 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &record) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, "field", 1);
	PHALCON_INIT_VAR(field_name);
	PHALCON_CALL_METHOD_PARAMS_1(field_name, this_ptr, "getoption", c0, PH_NO_CHECK);
	if (Z_TYPE_P(field_name) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string");
		return;
	}
	
	PHALCON_INIT_VAR(c1);
	ZVAL_STRING(c1, "domain", 1);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_CALL_METHOD_PARAMS_1(r0, this_ptr, "issetoption", c1, PH_NO_CHECK);
	if (!zend_is_true(r0)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'domain' is required for this validator");
		return;
	}
	
	PHALCON_INIT_VAR(c2);
	ZVAL_STRING(c2, "domain", 1);
	
	PHALCON_INIT_VAR(domain);
	PHALCON_CALL_METHOD_PARAMS_1(domain, this_ptr, "getoption", c2, PH_NO_CHECK);
	if (Z_TYPE_P(domain) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Option 'domain' must be an array");
		return;
	}
	
	PHALCON_INIT_VAR(value);
	PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field_name, PH_NO_CHECK);
	
	PHALCON_ALLOC_ZVAL_MM(r1);
	PHALCON_CALL_FUNC_PARAMS_2(r1, "in_array", value, domain);
	if (zend_is_true(r1)) {
		PHALCON_INIT_VAR(c3);
		ZVAL_STRING(c3, ", ", 1);
		PHALCON_ALLOC_ZVAL_MM(r2);
		phalcon_fast_join(r2, c3, domain TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r3);
		PHALCON_CONCAT_SVSV(r3, "Value of field '", field_name, "' must not be part of list: ", r2);
		PHALCON_INIT_VAR(c4);
		ZVAL_STRING(c4, "exclusion", 1);
		PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "appendmessage", r3, field_name, c4, PH_NO_CHECK);
		PHALCON_MM_RESTORE();
		RETURN_FALSE;
	}
	
	PHALCON_MM_RESTORE();
	RETURN_TRUE;
}
Beispiel #24
0
/**
 * Executes the validator
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Model_Validator_Uniqueness, validate){

	zval *record = NULL, *field = NULL, *conditions = NULL, *compose_field = NULL;
	zval *value = NULL, *manager = NULL, *meta_data = NULL, *primary_fields = NULL;
	zval *primary_field = NULL, *options = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL, *r19 = NULL, *r20 = NULL;
	zval *i0 = NULL;
	zval *a0 = NULL;
	zval *c0 = NULL, *c1 = NULL, *c2 = NULL;
	zval *t0 = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_CALL_METHOD(r0, this_ptr, "isrequired", PHALCON_NO_CHECK);
	if (zend_is_true(r0)) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		PHALCON_CALL_METHOD(r1, this_ptr, "getrecord", PHALCON_NO_CHECK);
		PHALCON_ALLOC_ZVAL_MM(i0);
		if (phalcon_clone(i0, r1 TSRMLS_CC) == FAILURE){
			return;
		}
		PHALCON_CPY_WRT(record, i0);
		
		PHALCON_ALLOC_ZVAL_MM(r2);
		PHALCON_CALL_METHOD(r2, this_ptr, "getfieldname", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(field, r2);
		
		PHALCON_INIT_VAR(a0);
		array_init(a0);
		PHALCON_CPY_WRT(conditions, a0);
		if (Z_TYPE_P(field) == IS_ARRAY) { 
			if (phalcon_valid_foreach(field TSRMLS_CC)) {
				ah0 = Z_ARRVAL_P(field);
				zend_hash_internal_pointer_reset_ex(ah0, &hp0);
				fes_d73d_0:
				if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
					goto fee_d73d_0;
				}
				PHALCON_INIT_VAR(compose_field);
				ZVAL_ZVAL(compose_field, *hd, 1, 0);
				PHALCON_INIT_VAR(r3);
				PHALCON_INIT_VAR(r4);
				PHALCON_CALL_METHOD_PARAMS_1(r4, record, "readattribute", compose_field, PHALCON_NO_CHECK);
				PHALCON_CALL_FUNC_PARAMS_1(r3, "addslashes", r4, 0x00F);
				PHALCON_CPY_WRT(value, r3);
				
				PHALCON_INIT_VAR(r5);
				PHALCON_CONCAT_VSVS(r5, compose_field, "='", value, "'");
				phalcon_array_append(&conditions, r5, PHALCON_SEPARATE_PLZ TSRMLS_CC);
				zend_hash_move_forward_ex(ah0, &hp0);
				goto fes_d73d_0;
				fee_d73d_0:
				if(0){}
			} else {
				return;
			}
		} else {
			PHALCON_ALLOC_ZVAL_MM(r6);
			PHALCON_ALLOC_ZVAL_MM(r7);
			PHALCON_CALL_METHOD(r7, this_ptr, "getvalue", PHALCON_NO_CHECK);
			PHALCON_CALL_FUNC_PARAMS_1(r6, "addslashes", r7, 0x00F);
			PHALCON_CPY_WRT(value, r6);
			
			PHALCON_ALLOC_ZVAL_MM(r8);
			PHALCON_CONCAT_VSVS(r8, field, "='", value, "'");
			phalcon_array_append(&conditions, r8, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
		
		PHALCON_ALLOC_ZVAL_MM(r9);
		PHALCON_CALL_METHOD(r9, record, "getmanager", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(manager, r9);
		
		PHALCON_ALLOC_ZVAL_MM(r10);
		PHALCON_CALL_METHOD(r10, manager, "getmetadata", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(meta_data, r10);
		
		PHALCON_ALLOC_ZVAL_MM(r11);
		PHALCON_CALL_METHOD_PARAMS_1(r11, meta_data, "getprimarykeyattributes", record, PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(primary_fields, r11);
		if (phalcon_valid_foreach(primary_fields TSRMLS_CC)) {
			ah1 = Z_ARRVAL_P(primary_fields);
			zend_hash_internal_pointer_reset_ex(ah1, &hp1);
			fes_d73d_1:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_d73d_1;
			}
			
			PHALCON_INIT_VAR(primary_field);
			ZVAL_ZVAL(primary_field, *hd, 1, 0);
			PHALCON_INIT_VAR(r12);
			PHALCON_INIT_VAR(r13);
			PHALCON_INIT_VAR(r14);
			PHALCON_CALL_METHOD_PARAMS_1(r14, record, "readattribute", primary_field, PHALCON_NO_CHECK);
			PHALCON_CALL_FUNC_PARAMS_1(r13, "addslashes", r14, 0x00F);
			PHALCON_CONCAT_VSVS(r12, primary_field, "<>'", r13, "'");
			phalcon_array_append(&conditions, r12, PHALCON_SEPARATE_PLZ TSRMLS_CC);
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_d73d_1;
			fee_d73d_1:
			if(0){}
		} else {
			return;
		}
		
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, " AND ", 1);
		
		PHALCON_ALLOC_ZVAL_MM(r15);
		phalcon_fast_join(r15, c0, conditions TSRMLS_CC);
		PHALCON_CPY_WRT(conditions, r15);
		
		PHALCON_ALLOC_ZVAL_MM(r16);
		PHALCON_CALL_STATIC_ZVAL_PARAMS_1(r16, record, "count", conditions);
		
		PHALCON_INIT_VAR(t0);
		ZVAL_LONG(t0, 0);
		
		PHALCON_INIT_VAR(r17);
		is_smaller_function(r17, t0, r16 TSRMLS_CC);
		if (zend_is_true(r17)) {
			PHALCON_ALLOC_ZVAL_MM(r18);
			PHALCON_CALL_METHOD(r18, this_ptr, "getoptions", PHALCON_NO_CHECK);
			PHALCON_CPY_WRT(options, r18);
			eval_int = phalcon_array_isset_string(options, "message", strlen("message")+1);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(r19);
				phalcon_array_fetch_string(&r19, options, "message", strlen("message"), PHALCON_NOISY TSRMLS_CC);
				PHALCON_INIT_VAR(c1);
				ZVAL_STRING(c1, "unique", 1);
				PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "appendmessage", r19, field, c1, PHALCON_NO_CHECK);
			} else {
				PHALCON_ALLOC_ZVAL_MM(r20);
				PHALCON_CONCAT_SVS(r20, "Value of field '", field, "' is already present in another record");
				PHALCON_INIT_VAR(c2);
				ZVAL_STRING(c2, "unique", 1);
				PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "appendmessage", r20, field, c2, PHALCON_NO_CHECK);
			}
			
			PHALCON_MM_RESTORE();
			RETURN_FALSE;
		}
	}
	PHALCON_MM_RESTORE();
	RETURN_TRUE;
}
Beispiel #25
0
/**
 * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor.
 * Call it when you need to restore a database connection
 *
 * @param 	array $descriptor
 * @return 	boolean
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){

zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts = NULL;
	zval *value = NULL, *key = NULL, *dsn_attribute = NULL, *dot_comma = NULL, *dsn_attributes = NULL;
	zval *pdo_type = NULL, *dsn = NULL, *options = NULL, *persistent = NULL, *pdo = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (!descriptor) {
		PHALCON_ALLOC_ZVAL_MM(descriptor);
		ZVAL_NULL(descriptor);
	} else {
		PHALCON_SEPARATE_PARAM(descriptor);
	}

	if (Z_TYPE_P(descriptor) == IS_NULL) {
		PHALCON_INIT_VAR(descriptor);
		phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC);
	}
	eval_int = phalcon_array_isset_string(descriptor, SS("username"));
	if (eval_int) {
		PHALCON_INIT_VAR(username);
		phalcon_array_fetch_string(&username, descriptor, SL("username"), PH_NOISY_CC);
		PHALCON_SEPARATE_PARAM(descriptor);
		phalcon_array_unset_string(descriptor, SS("username"));
	} else {
		PHALCON_INIT_VAR(username);
		ZVAL_NULL(username);
	}

	eval_int = phalcon_array_isset_string(descriptor, SS("password"));
	if (eval_int) {
		PHALCON_INIT_VAR(password);
		phalcon_array_fetch_string(&password, descriptor, SL("password"), PH_NOISY_CC);
		PHALCON_SEPARATE_PARAM(descriptor);
		phalcon_array_unset_string(descriptor, SS("password"));
	} else {
		PHALCON_INIT_VAR(password);
		ZVAL_NULL(password);
	}

	eval_int = phalcon_array_isset_string(descriptor, SS("dsn"));
	if (!eval_int) {
		PHALCON_INIT_VAR(dsn_parts);
		array_init(dsn_parts);

		if (!phalcon_valid_foreach(descriptor TSRMLS_CC)) {
			return;
		}

		ah0 = Z_ARRVAL_P(descriptor);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);

		ph_cycle_start_0:

			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto ph_cycle_end_0;
			}

			PHALCON_INIT_VAR(key);
			PHALCON_GET_FOREACH_KEY(key, ah0, hp0);
			PHALCON_GET_FOREACH_VALUE(value);

			PHALCON_INIT_VAR(dsn_attribute);
			PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value);
			phalcon_array_append(&dsn_parts, dsn_attribute, PH_SEPARATE TSRMLS_CC);

			zend_hash_move_forward_ex(ah0, &hp0);
			goto ph_cycle_start_0;

		ph_cycle_end_0:

		PHALCON_INIT_VAR(dot_comma);
		ZVAL_STRING(dot_comma, ";", 1);

		PHALCON_INIT_VAR(dsn_attributes);
		phalcon_fast_join(dsn_attributes, dot_comma, dsn_parts TSRMLS_CC);
	} else {
		PHALCON_INIT_VAR(dsn_attributes);
		phalcon_array_fetch_string(&dsn_attributes, descriptor, SL("dsn"), PH_NOISY_CC);
	}

	PHALCON_INIT_VAR(pdo_type);
	phalcon_read_property(&pdo_type, this_ptr, SL("_type"), PH_NOISY_CC);

	PHALCON_INIT_VAR(dsn);
	PHALCON_CONCAT_VSV(dsn, pdo_type, ":", dsn_attributes);

	PHALCON_INIT_VAR(options);
	array_init(options);
	add_index_long(options, PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
	add_index_long(options, PDO_ATTR_CASE, PDO_CASE_LOWER);
	add_index_long(options, PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL);
	eval_int = phalcon_array_isset_string(descriptor, SS("persistent"));
	if (eval_int) {
		PHALCON_INIT_VAR(persistent);
		phalcon_array_fetch_string(&persistent, descriptor, SL("persistent"), PH_NOISY_CC);
		if (zend_is_true(persistent)) {
			phalcon_array_update_long_bool(&options, PDO_ATTR_PERSISTENT, 1, PH_SEPARATE TSRMLS_CC);
		}
	}

	ce0 = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

	PHALCON_INIT_VAR(pdo);
	object_init_ex(pdo, ce0);
	PHALCON_CALL_METHOD_PARAMS_4_NORETURN(pdo, "__construct", dsn, username, password, options, PH_CHECK);
	phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC);

	PHALCON_MM_RESTORE();}
Beispiel #26
0
/**
 * Helper method to query records based on a relation definition
 *
 * @param array $relation
 * @param string $method
 * @param Phalcon\Mvc\Model $record
 * @param array $parameters
 * @return Phalcon\Mvc\Model\Resultset\Simple
 */
PHP_METHOD(Phalcon_Mvc_Model_Manager, _getRelationRecords){

	zval *relation = NULL, *method = NULL, *record = NULL, *parameters = NULL, *placeholders = NULL;
	zval *pre_conditions = NULL, *conditions = NULL, *fields = NULL, *field = NULL;
	zval *value = NULL, *referenced_field = NULL, *condition = NULL, *i = NULL;
	zval *referenced_fields = NULL, *join_conditions = NULL;
	zval *find_params = NULL, *find_arguments = NULL, *arguments = NULL;
	zval *reference_table = NULL, *referenced_entity = NULL;
	zval *connection_service = NULL, *call_object = NULL, *records = NULL;
	zval *c0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	int eval_int;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|z", &relation, &method, &record, &parameters) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (!parameters) {
		PHALCON_ALLOC_ZVAL_MM(parameters);
		ZVAL_NULL(parameters);
	} else {
		PHALCON_SEPARATE_PARAM(parameters);
	}
	
	if (Z_TYPE_P(parameters) == IS_ARRAY) { 
		eval_int = phalcon_array_isset_string(parameters, SL("bind")+1);
		if (eval_int) {
			PHALCON_INIT_VAR(placeholders);
			phalcon_array_fetch_string(&placeholders, parameters, SL("bind"), PH_NOISY_CC);
			PHALCON_SEPARATE_PARAM(parameters);
			phalcon_array_unset_string(parameters, SL("bind")+1);
		} else {
			PHALCON_INIT_VAR(placeholders);
			array_init(placeholders);
		}
	} else {
		PHALCON_INIT_VAR(placeholders);
		array_init(placeholders);
	}
	
	PHALCON_INIT_VAR(pre_conditions);
	ZVAL_NULL(pre_conditions);
	if (Z_TYPE_P(parameters) == IS_ARRAY) { 
		eval_int = phalcon_array_isset_long(parameters, 0);
		if (eval_int) {
			PHALCON_INIT_VAR(pre_conditions);
			phalcon_array_fetch_long(&pre_conditions, parameters, 0, PH_NOISY_CC);
			PHALCON_SEPARATE_PARAM(parameters);
			phalcon_array_unset_long(parameters, 0);
		} else {
			eval_int = phalcon_array_isset_string(parameters, SL("conditions")+1);
			if (eval_int) {
				PHALCON_INIT_VAR(pre_conditions);
				phalcon_array_fetch_string(&pre_conditions, parameters, SL("conditions"), PH_NOISY_CC);
				PHALCON_SEPARATE_PARAM(parameters);
				phalcon_array_unset_string(parameters, SL("conditions")+1);
			}
		}
	} else {
		if (Z_TYPE_P(parameters) == IS_STRING) {
			PHALCON_CPY_WRT(pre_conditions, parameters);
		}
	}
	
	if (Z_TYPE_P(pre_conditions) != IS_NULL) {
		PHALCON_INIT_VAR(conditions);
		array_init(conditions);
		phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE TSRMLS_CC);
	} else {
		PHALCON_INIT_VAR(conditions);
		array_init(conditions);
	}
	
	PHALCON_INIT_VAR(fields);
	phalcon_array_fetch_string(&fields, relation, SL("fi"), PH_NOISY_CC);
	if (Z_TYPE_P(fields) != IS_ARRAY) { 
		PHALCON_CPY_WRT(field, fields);
		
		PHALCON_INIT_VAR(value);
		PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK);
		
		PHALCON_INIT_VAR(referenced_field);
		phalcon_array_fetch_string(&referenced_field, relation, SL("rf"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(condition);
		PHALCON_CONCAT_VS(condition, referenced_field, " = ?0");
		phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC);
		phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC);
	} else {
		PHALCON_INIT_VAR(i);
		ZVAL_LONG(i, 0);
		
		PHALCON_INIT_VAR(referenced_fields);
		phalcon_array_fetch_string(&referenced_fields, relation, SL("rf"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(fields TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(fields);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_74b5_0:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_74b5_0;
			}
			
			PHALCON_INIT_VAR(field);
			ZVAL_ZVAL(field, *hd, 1, 0);
			PHALCON_INIT_VAR(value);
			PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK);
			
			PHALCON_INIT_VAR(referenced_field);
			phalcon_array_fetch(&referenced_field, referenced_fields, i, PH_NOISY_CC);
			
			PHALCON_INIT_VAR(condition);
			PHALCON_CONCAT_VSV(condition, referenced_field, " = ?", i);
			phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC);
			phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC);
			PHALCON_SEPARATE(i);
			increment_function(i);
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_74b5_0;
		fee_74b5_0:
		if(0){}
		
	}
	
	PHALCON_INIT_VAR(c0);
	ZVAL_STRING(c0, " AND ", 1);
	
	PHALCON_INIT_VAR(join_conditions);
	phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC);
	
	PHALCON_INIT_VAR(find_params);
	array_init(find_params);
	phalcon_array_append(&find_params, join_conditions, PH_SEPARATE TSRMLS_CC);
	phalcon_array_update_string(&find_params, SL("bind"), &placeholders, PH_COPY | PH_SEPARATE TSRMLS_CC);
	if (Z_TYPE_P(parameters) == IS_ARRAY) { 
		PHALCON_INIT_VAR(find_arguments);
		PHALCON_CALL_FUNC_PARAMS_2(find_arguments, "array_merge", find_params, parameters);
	} else {
		PHALCON_CPY_WRT(find_arguments, find_params);
	}
	
	PHALCON_INIT_VAR(arguments);
	array_init(arguments);
	phalcon_array_append(&arguments, find_arguments, PH_SEPARATE TSRMLS_CC);
	
	PHALCON_INIT_VAR(reference_table);
	phalcon_array_fetch_string(&reference_table, relation, SL("rt"), PH_NOISY_CC);
	ce0 = phalcon_fetch_class(reference_table TSRMLS_CC);
	
	PHALCON_INIT_VAR(referenced_entity);
	object_init_ex(referenced_entity, ce0);
	PHALCON_CALL_METHOD_NORETURN(referenced_entity, "__construct", PH_CHECK);
	
	PHALCON_INIT_VAR(connection_service);
	PHALCON_CALL_METHOD(connection_service, record, "getconnectionservice", PH_NO_CHECK);
	PHALCON_CALL_METHOD_PARAMS_1_NORETURN(referenced_entity, "setconnectionservice", connection_service, PH_NO_CHECK);
	
	PHALCON_INIT_VAR(call_object);
	array_init(call_object);
	phalcon_array_append(&call_object, referenced_entity, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&call_object, method, PH_SEPARATE TSRMLS_CC);
	
	PHALCON_INIT_VAR(records);
	PHALCON_CALL_FUNC_PARAMS_2(records, "call_user_func_array", call_object, arguments);
	
	RETURN_CCTOR(records);
}
Beispiel #27
0
/**
 * Builds a HTML FORM tag
 *
 * <code>
 * echo Phalcon\Tag::form("posts/save");
 * echo Phalcon\Tag::form(array("posts/save", "method" => "post"));
 * </code>
 *
 * @param array $parameters
 * @return string
 */
PHP_METHOD(Phalcon_Tag, form){

	zval *parameters = NULL, *params = NULL, *dispatcher = NULL, *dispatch_params = NULL;
	zval *slash = NULL, *action_parameters = NULL, *action = NULL, *controller_name = NULL;
	zval *action_name = NULL, *url = NULL, *form_action = NULL, *query_parameters = NULL;
	zval *code = NULL, *avalue = NULL, *key = NULL, *attribute = NULL, *final_code = NULL;
	zval *r0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &parameters) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (!parameters) {
		PHALCON_ALLOC_ZVAL_MM(parameters);
		ZVAL_NULL(parameters);
	} else {
		PHALCON_SEPARATE_PARAM(parameters);
	}
	
	if (Z_TYPE_P(parameters) != IS_ARRAY) { 
		PHALCON_INIT_VAR(params);
		array_init(params);
		phalcon_array_append(&params, parameters, PH_SEPARATE TSRMLS_CC);
	} else {
		PHALCON_CPY_WRT(params, parameters);
	}
	
	PHALCON_INIT_VAR(dispatcher);
	PHALCON_CALL_SELF(dispatcher, this_ptr, "getdispatcherservice");
	
	PHALCON_INIT_VAR(dispatch_params);
	PHALCON_CALL_METHOD(dispatch_params, dispatcher, "getparams", PH_NO_CHECK);
	
	PHALCON_INIT_VAR(slash);
	ZVAL_STRING(slash, "/", 1);
	
	PHALCON_INIT_VAR(action_parameters);
	phalcon_fast_join(action_parameters, slash, dispatch_params TSRMLS_CC);
	eval_int = phalcon_array_isset_long(params, 0);
	if (!eval_int) {
		eval_int = phalcon_array_isset_string(params, SL("action")+1);
		if (eval_int) {
			PHALCON_INIT_VAR(action);
			phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC);
		} else {
			PHALCON_INIT_VAR(controller_name);
			PHALCON_CALL_METHOD(controller_name, dispatcher, "getcontrollername", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(action_name);
			PHALCON_CALL_METHOD(action_name, dispatcher, "getactionname", PH_NO_CHECK);
			
			PHALCON_INIT_VAR(action);
			PHALCON_CONCAT_VSV(action, controller_name, "/", action_name);
		}
	} else {
		PHALCON_INIT_VAR(action);
		phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC);
	}
	
	eval_int = phalcon_array_isset_string(params, SL("method")+1);
	if (!eval_int) {
		phalcon_array_update_string_string(&params, SL("method"), SL("post"), PH_SEPARATE TSRMLS_CC);
	}
	
	PHALCON_INIT_VAR(url);
	PHALCON_CALL_SELF(url, this_ptr, "geturlservice");
	if (zend_is_true(action_parameters)) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		PHALCON_CALL_METHOD_PARAMS_1(r0, url, "get", action, PH_NO_CHECK);
		PHALCON_CPY_WRT(action, r0);
	} else {
		PHALCON_INIT_VAR(form_action);
		PHALCON_CONCAT_VSV(form_action, action, "/", action_parameters);
		
		PHALCON_INIT_VAR(action);
		PHALCON_CALL_METHOD_PARAMS_1(action, url, "get", form_action, PH_NO_CHECK);
	}
	
	eval_int = phalcon_array_isset_string(params, SL("parameters")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(parameters);
		phalcon_array_fetch_string(&parameters, params, SL("parameters"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(query_parameters);
		PHALCON_CONCAT_SV(query_parameters, "?", parameters);
		phalcon_concat_self(&action, query_parameters TSRMLS_CC);
	}
	
	PHALCON_INIT_VAR(code);
	PHALCON_CONCAT_SVS(code, "<form action=\"", action, "\" ");
	if (!phalcon_valid_foreach(params TSRMLS_CC)) {
		return;
	}
	
	ah0 = Z_ARRVAL_P(params);
	zend_hash_internal_pointer_reset_ex(ah0, &hp0);
	fes_9b93_5:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_9b93_5;
		}
		
		PHALCON_INIT_VAR(key);
		PHALCON_GET_FOREACH_KEY(key, ah0, hp0);
		PHALCON_INIT_VAR(avalue);
		ZVAL_ZVAL(avalue, *hd, 1, 0);
		if (Z_TYPE_P(key) != IS_LONG) {
			PHALCON_INIT_VAR(attribute);
			PHALCON_CONCAT_VSVS(attribute, key, "= \"", avalue, "\" ");
			phalcon_concat_self(&code, attribute TSRMLS_CC);
		}
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_9b93_5;
	fee_9b93_5:
	
	PHALCON_INIT_VAR(final_code);
	PHALCON_CONCAT_VS(final_code, code, ">");
	
	RETURN_CTOR(final_code);
}