Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phalcon\Db Optimization #1693

Merged
merged 7 commits into from Dec 15, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Phalcon\Db\Adapter optimization
  • Loading branch information
sjinks committed Dec 14, 2013
commit 68d25841d08a6540f4a405121cf8de30e35a590b
119 changes: 56 additions & 63 deletions ext/db/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchOne){
if (Z_TYPE_P(fetch_mode) != IS_NULL) {
phalcon_call_method_p1_noret(result, "setfetchmode", fetch_mode);
}
phalcon_call_method(return_value, result, "fetch");
phalcon_return_call_method_p0(result, "fetch");
RETURN_MM();
}

Expand Down Expand Up @@ -459,14 +459,14 @@ PHP_METHOD(Phalcon_Db_Adapter, insert){
PHALCON_INIT_VAR(insert_sql);
PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", escaped_table, " (", joined_fields, ") VALUES (", joined_values, ")");
} else {
PHALCON_INIT_NVAR(insert_sql);
PHALCON_INIT_VAR(insert_sql);
PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", escaped_table, " VALUES (", joined_values, ")");
}

/**
* Perform the execution via PDO::execute
* Perform the execution via execute
*/
phalcon_call_method_p3(return_value, this_ptr, "execute", insert_sql, insert_values, bind_data_types);
phalcon_return_call_method_p3(this_ptr, "execute", insert_sql, insert_values, bind_data_types);
RETURN_MM();
}

Expand Down Expand Up @@ -646,9 +646,9 @@ PHP_METHOD(Phalcon_Db_Adapter, update){
}

/**
* Perform the update via PDO::execute
* Perform the update via execute
*/
phalcon_call_method_p3(return_value, this_ptr, "execute", update_sql, update_values, bind_data_types);
phalcon_return_call_method_p3(this_ptr, "execute", update_sql, update_values, bind_data_types);
RETURN_MM();
}

Expand Down Expand Up @@ -708,9 +708,9 @@ PHP_METHOD(Phalcon_Db_Adapter, delete){
}

/**
* Perform the update via PDO::execute
* Perform the update via execute
*/
phalcon_call_method_p3(return_value, this_ptr, "execute", sql, placeholders, data_types);
phalcon_return_call_method_p3(this_ptr, "execute", sql, placeholders, data_types);
RETURN_MM();
}

Expand All @@ -729,7 +729,7 @@ PHP_METHOD(Phalcon_Db_Adapter, getColumnList){
phalcon_fetch_params(1, 1, 0, &column_list);

dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC);
phalcon_call_method_p1(return_value, dialect, "getcolumnlist", column_list);
phalcon_return_call_method_p1(dialect, "getcolumnlist", column_list);
RETURN_MM();
}

Expand All @@ -753,7 +753,7 @@ PHP_METHOD(Phalcon_Db_Adapter, limit){
phalcon_fetch_params(1, 2, 0, &sql_query, &number);

dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC);
phalcon_call_method_p2(return_value, dialect, "limit", sql_query, number);
phalcon_return_call_method_p2(dialect, "limit", sql_query, number);
RETURN_MM();
}

Expand Down Expand Up @@ -852,7 +852,7 @@ PHP_METHOD(Phalcon_Db_Adapter, forUpdate){
phalcon_fetch_params(1, 1, 0, &sql_query);

dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC);
phalcon_call_method_p1(return_value, dialect, "forupdate", sql_query);
phalcon_return_call_method_p1(dialect, "forupdate", sql_query);
RETURN_MM();
}

Expand All @@ -871,7 +871,7 @@ PHP_METHOD(Phalcon_Db_Adapter, sharedLock){
phalcon_fetch_params(1, 1, 0, &sql_query);

dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC);
phalcon_call_method_p1(return_value, dialect, "sharedlock", sql_query);
phalcon_return_call_method_p1(dialect, "sharedlock", sql_query);
RETURN_MM();
}

Expand All @@ -893,7 +893,7 @@ PHP_METHOD(Phalcon_Db_Adapter, createTable){

phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition);

if (Z_TYPE_P(definition) != IS_ARRAY) {
if (Z_TYPE_P(definition) != IS_ARRAY) {
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Invalid definition to create the table '", table_name, "'");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message);
Expand All @@ -914,7 +914,7 @@ PHP_METHOD(Phalcon_Db_Adapter, createTable){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "createtable", table_name, schema_name, definition);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand Down Expand Up @@ -947,7 +947,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropTable){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "droptable", table_name, schema_name, if_exists);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand Down Expand Up @@ -988,7 +988,7 @@ PHP_METHOD(Phalcon_Db_Adapter, createView){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "createview", view_name, definition, schema_name);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand Down Expand Up @@ -1021,7 +1021,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropView){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "dropview", view_name, schema_name, if_exists);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1046,7 +1046,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addColumn){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "addcolumn", table_name, schema_name, column);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1071,7 +1071,7 @@ PHP_METHOD(Phalcon_Db_Adapter, modifyColumn){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "modifycolumn", table_name, schema_name, column);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1096,7 +1096,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropColumn){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "dropcolumn", table_name, schema_name, column_name);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1121,7 +1121,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addIndex){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "addindex", table_name, schema_name, index);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1146,7 +1146,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropIndex){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "dropindex", table_name, schema_name, index_name);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1171,7 +1171,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addPrimaryKey){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "addprimarykey", table_name, schema_name, index);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1194,7 +1194,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropPrimaryKey){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p2(sql, dialect, "dropprimarykey", table_name, schema_name);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1219,7 +1219,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addForeignKey){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "addforeignkey", table_name, schema_name, reference);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1244,7 +1244,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropForeignKey){

PHALCON_INIT_VAR(sql);
phalcon_call_method_p3(sql, dialect, "dropforeignkey", table_name, schema_name, reference_name);
phalcon_call_method_p1(return_value, this_ptr, "execute", sql);
phalcon_return_call_method_p1(this_ptr, "execute", sql);
RETURN_MM();
}

Expand All @@ -1263,7 +1263,7 @@ PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){
phalcon_fetch_params(1, 1, 0, &column);

dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC);
phalcon_call_method_p1(return_value, dialect, "getcolumndefinition", column);
phalcon_return_call_method_p1(dialect, "getcolumndefinition", column);
RETURN_MM();
}

Expand All @@ -1280,10 +1280,8 @@ PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){
PHP_METHOD(Phalcon_Db_Adapter, listTables){

zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables;
zval *table = NULL, *table_name = NULL;
HashTable *ah0;
zval **table, *table_name;
HashPosition hp0;
zval **hd;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -1313,19 +1311,18 @@ PHP_METHOD(Phalcon_Db_Adapter, listTables){
PHALCON_INIT_VAR(tables);
phalcon_call_method_p2(tables, this_ptr, "fetchall", sql, fetch_num);

array_init(return_value);

phalcon_is_iterable(tables, &ah0, &hp0, 0, 0);

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

PHALCON_GET_HVALUE(table);

PHALCON_OBS_NVAR(table_name);
phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY);
phalcon_array_append(&return_value, table_name, PH_SEPARATE);

zend_hash_move_forward_ex(ah0, &hp0);
if (Z_TYPE_P(tables) == IS_ARRAY) {
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(tables)));

for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tables), &hp0);
zend_hash_get_current_data_ex(Z_ARRVAL_P(tables), (void**)&table, &hp0) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(tables), &hp0)
) {
if (phalcon_array_isset_long_fetch(&table_name, *table, 0)) {
phalcon_array_append(&return_value, table_name, 0);
}
}
}

PHALCON_MM_RESTORE();
Expand All @@ -1344,10 +1341,8 @@ PHP_METHOD(Phalcon_Db_Adapter, listTables){
PHP_METHOD(Phalcon_Db_Adapter, listViews){

zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables;
zval *table = NULL, *table_name = NULL;
HashTable *ah0;
zval **table, *table_name;
HashPosition hp0;
zval **hd;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -1377,19 +1372,18 @@ PHP_METHOD(Phalcon_Db_Adapter, listViews){
PHALCON_INIT_VAR(tables);
phalcon_call_method_p2(tables, this_ptr, "fetchall", sql, fetch_num);

array_init(return_value);

phalcon_is_iterable(tables, &ah0, &hp0, 0, 0);

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

PHALCON_GET_HVALUE(table);

PHALCON_OBS_NVAR(table_name);
phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY);
phalcon_array_append(&return_value, table_name, PH_SEPARATE);

zend_hash_move_forward_ex(ah0, &hp0);
if (Z_TYPE_P(tables) == IS_ARRAY) {
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(tables)));

for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tables), &hp0);
zend_hash_get_current_data_ex(Z_ARRVAL_P(tables), (void**)&table, &hp0) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(tables), &hp0)
) {
if (phalcon_array_isset_long_fetch(&table_name, *table, 0)) {
phalcon_array_append(&return_value, table_name, 0);
}
}
}

PHALCON_MM_RESTORE();
Expand Down Expand Up @@ -1457,7 +1451,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){
if (!phalcon_array_isset(indexes, key_name)) {
PHALCON_INIT_NVAR(empty_arr);
array_init(empty_arr);
phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE);
phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY);
}

PHALCON_OBS_NVAR(column_name);
Expand All @@ -1483,7 +1477,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){
object_init_ex(index, phalcon_db_index_ce);
phalcon_call_method_p2_noret(index, "__construct", name, index_columns);

phalcon_array_update_zval(&return_value, name, &index, PH_COPY | PH_SEPARATE);
phalcon_array_update_zval(&return_value, name, &index, PH_COPY);

zend_hash_move_forward_ex(ah1, &hp1);
}
Expand Down Expand Up @@ -1839,7 +1833,7 @@ PHP_METHOD(Phalcon_Db_Adapter, getDefaultIdValue){

PHALCON_MM_GROW();

PHALCON_INIT_VAR(null_value);
PHALCON_ALLOC_GHOST_ZVAL(null_value);
ZVAL_STRING(null_value, "null", 1);
object_init_ex(return_value, phalcon_db_rawvalue_ce);
phalcon_call_method_p1_noret(return_value, "__construct", null_value);
Expand Down Expand Up @@ -1956,4 +1950,3 @@ PHP_METHOD(Phalcon_Db_Adapter, getDialectType){

RETURN_MEMBER(this_ptr, "_dialectType");
}