diff --git a/CHANGELOG b/CHANGELOG index 5754396f8f1..42f796e14e5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -94,6 +94,8 @@ - Database dialects now support BOOLEAN data type (#816) - Added support for POINT type in MySQL (#1536) - Fixed issue with RawValue('default') on composite primary key (#1534) + - Added support for the following fetch modes from PDO: FETCH_LAZY, FETCH_BOUND, FETCH_COLUMN, FETCH_CLASS, FETCH_INTO, FETCH_FUNC, FETCH_NAMED, FETCH_KEY_PAIR (#1642) + - Added support for the following fetch mode modifiers from PDO: FETCH_GROUP, FETCH_UNIQUE, FETCH_CLASSTYPE, FETCH_SERIALIZE, FETCH_PROPS_LATE (#1642) - Phalcon\Debug: - Added support for UTF-8 to \Phalcon\Debug (#1099) - Phalcon\Debug::uri now supports both http and https (#987) diff --git a/ext/db.c b/ext/db.c index 9dc2f546fa5..2ae2f78a8c7 100644 --- a/ext/db.c +++ b/ext/db.c @@ -29,6 +29,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -81,10 +83,25 @@ PHALCON_INIT_CLASS(Phalcon_Db){ PHALCON_REGISTER_CLASS(Phalcon, Db, db, phalcon_db_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_ASSOC"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOTH"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NUM"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_OBJ"), 4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_USE_DEFAULT"), (long int)PDO_FETCH_USE_DEFAULT TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_LAZY"), (long int)PDO_FETCH_LAZY TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_ASSOC"), (long int)PDO_FETCH_ASSOC TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NUM"), (long int)PDO_FETCH_NUM TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOTH"), (long int)PDO_FETCH_BOTH TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_OBJ"), (long int)PDO_FETCH_OBJ TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOUND"), (long int)PDO_FETCH_BOUND TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_COLUMN"), (long int)PDO_FETCH_COLUMN TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_CLASS"), (long int)PDO_FETCH_CLASS TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_INTO"), (long int)PDO_FETCH_INTO TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_FUNC"), (long int)PDO_FETCH_FUNC TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NAMED"), (long int)PDO_FETCH_NAMED TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_KEY_PAIR") , (long int)PDO_FETCH_KEY_PAIR TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_GROUP"), (long int)PDO_FETCH_GROUP TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_UNIQUE"), (long int)PDO_FETCH_UNIQUE TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_CLASSTYPE"), (long int)PDO_FETCH_CLASSTYPE TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_SERIALIZE"), (long int)PDO_FETCH_SERIALIZE TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_PROPS_LATE"), (long int)PDO_FETCH_PROPS_LATE TSRMLS_CC); return SUCCESS; } diff --git a/ext/db/adapter.c b/ext/db/adapter.c index db0d4256961..1efb5a27df4 100644 --- a/ext/db/adapter.c +++ b/ext/db/adapter.c @@ -28,6 +28,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -209,7 +211,7 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchOne){ if (!fetch_mode) { PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + ZVAL_LONG(fetch_mode, PDO_FETCH_BOTH); } if (!bind_params) { @@ -271,7 +273,7 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ if (!fetch_mode) { PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + ZVAL_LONG(fetch_mode, PDO_FETCH_BOTH); } if (!bind_params) { @@ -785,7 +787,7 @@ PHP_METHOD(Phalcon_Db_Adapter, tableExists){ phalcon_call_method_p2(sql, dialect, "tableexists", table_name, schema_name); PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_INIT_VAR(num); phalcon_call_method_p2(num, this_ptr, "fetchone", sql, fetch_num); @@ -825,7 +827,7 @@ PHP_METHOD(Phalcon_Db_Adapter, viewExists){ phalcon_call_method_p2(sql, dialect, "viewexists", view_name, schema_name); PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_INIT_VAR(num); phalcon_call_method_p2(num, this_ptr, "fetchone", sql, fetch_num); @@ -1303,7 +1305,7 @@ PHP_METHOD(Phalcon_Db_Adapter, listTables){ * Use fetch Num */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); /** * Execute the SQL returning the tables @@ -1367,7 +1369,7 @@ PHP_METHOD(Phalcon_Db_Adapter, listViews){ * Use fetch Num */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); /** * Execute the SQL returning the tables @@ -1427,7 +1429,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); /** * Get the SQL required to describe indexes from the Dialect @@ -1526,7 +1528,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); /** * Get the SQL required to describe the references from the Dialect @@ -1651,7 +1653,7 @@ PHP_METHOD(Phalcon_Db_Adapter, tableOptions){ phalcon_call_method_p2(sql, dialect, "tableoptions", table_name, schema_name); if (zend_is_true(sql)) { PHALCON_INIT_VAR(fetch_assoc); - ZVAL_LONG(fetch_assoc, 1); + ZVAL_LONG(fetch_assoc, PDO_FETCH_ASSOC); PHALCON_INIT_VAR(describe); phalcon_call_method_p2(describe, this_ptr, "fetchall", sql, fetch_assoc); diff --git a/ext/db/adapter/pdo/mysql.c b/ext/db/adapter/pdo/mysql.c index 8f99998aebf..0b7c3085639 100644 --- a/ext/db/adapter/pdo/mysql.c +++ b/ext/db/adapter/pdo/mysql.c @@ -29,6 +29,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -156,7 +158,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); /** * Get the describe diff --git a/ext/db/adapter/pdo/oracle.c b/ext/db/adapter/pdo/oracle.c index 2c5e8054093..ef1d249d1a3 100644 --- a/ext/db/adapter/pdo/oracle.c +++ b/ext/db/adapter/pdo/oracle.c @@ -30,6 +30,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -176,7 +178,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_INIT_VAR(describe); phalcon_call_method_p2(describe, this_ptr, "fetchall", sql, fetch_num); @@ -345,7 +347,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, lastInsertId){ PHALCON_CONCAT_SVS(sql, "SELECT ", sequence_name, ".CURRVAL FROM dual"); PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_INIT_VAR(ret); phalcon_call_method_p2(ret, this_ptr, "fetchall", sql, fetch_num); diff --git a/ext/db/adapter/pdo/postgresql.c b/ext/db/adapter/pdo/postgresql.c index 737ba636f61..ccd3358964b 100644 --- a/ext/db/adapter/pdo/postgresql.c +++ b/ext/db/adapter/pdo/postgresql.c @@ -30,6 +30,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -163,7 +165,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_INIT_VAR(describe); phalcon_call_method_p2(describe, this_ptr, "fetchall", sql, fetch_num); diff --git a/ext/db/adapter/pdo/sqlite.c b/ext/db/adapter/pdo/sqlite.c index 3c5a7706b37..093e86c8ff3 100644 --- a/ext/db/adapter/pdo/sqlite.c +++ b/ext/db/adapter/pdo/sqlite.c @@ -30,6 +30,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -157,7 +159,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeColumns){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_INIT_VAR(describe); phalcon_call_method_p2(describe, this_ptr, "fetchall", sql, fetch_num); @@ -333,7 +335,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeIndexes){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_INIT_VAR(sql); phalcon_call_method_p2(sql, dialect, "describeindexes", table, schema); @@ -444,7 +446,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeReferences){ * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + ZVAL_LONG(fetch_num, PDO_FETCH_NUM); /** * Execute the SQL describing the references diff --git a/ext/db/result/pdo.c b/ext/db/result/pdo.c index 694eaea9ac4..ae81ac494d8 100644 --- a/ext/db/result/pdo.c +++ b/ext/db/result/pdo.c @@ -29,10 +29,10 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" - -#include "ext/pdo/php_pdo_driver.h" #include "kernel/exception.h" #include "kernel/object.h" #include "kernel/fcall.h" @@ -65,7 +65,7 @@ PHALCON_INIT_CLASS(Phalcon_Db_Result_Pdo){ zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_connection"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_result"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_result_pdo_ce, SL("_fetchMode"), 4, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_result_pdo_ce, SL("_fetchMode"), PDO_FETCH_OBJ, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_pdoStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_sqlStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_bindParams"), ZEND_ACC_PROTECTED TSRMLS_CC); @@ -450,20 +450,10 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ } PHALCON_INIT_VAR(fetch_type); + ZVAL_LONG(fetch_type, fetch_mode); PHALCON_OBS_VAR(pdo_statement); phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); - if (fetch_mode == 1) { - ZVAL_LONG(fetch_type, 2); - } else if (fetch_mode == 2) { - ZVAL_LONG(fetch_type, 4); - } else if (fetch_mode == 3) { - ZVAL_LONG(fetch_type, 3); - } else if (fetch_mode == 4) { - ZVAL_LONG(fetch_type, 5); - } else { - ZVAL_LONG(fetch_type, 0); - } if (Z_LVAL_P(fetch_type) != 0) { phalcon_call_method_p1_noret(pdo_statement, "setfetchmode", fetch_type); diff --git a/ext/mvc/model.c b/ext/mvc/model.c index 4a93ed76051..72f5e1eaf8d 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -29,9 +29,10 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" - #include "kernel/fcall.h" #include "kernel/exception.h" #include "kernel/object.h" @@ -4919,7 +4920,7 @@ PHP_METHOD(Phalcon_Mvc_Model, refresh){ phalcon_call_method_p1(sql, dialect, "select", select); PHALCON_INIT_VAR(fetch_type); - ZVAL_LONG(fetch_type, 1); + ZVAL_LONG(fetch_type, PDO_FETCH_ASSOC); PHALCON_INIT_VAR(row); phalcon_call_method_p4(row, read_connection, "fetchone", sql, fetch_type, unique_params, unique_types); diff --git a/ext/mvc/model/resultset/complex.c b/ext/mvc/model/resultset/complex.c index b7df88528fd..ac9e66522d5 100644 --- a/ext/mvc/model/resultset/complex.c +++ b/ext/mvc/model/resultset/complex.c @@ -29,6 +29,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -111,7 +113,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, __construct){ */ if (Z_TYPE_P(result) == IS_OBJECT) { PHALCON_INIT_VAR(fetch_assoc); - ZVAL_LONG(fetch_assoc, 1); + ZVAL_LONG(fetch_assoc, PDO_FETCH_ASSOC); phalcon_call_method_p1_noret(result, "setfetchmode", fetch_assoc); } diff --git a/ext/mvc/model/resultset/simple.c b/ext/mvc/model/resultset/simple.c index 2494b40f147..6f7983dd216 100644 --- a/ext/mvc/model/resultset/simple.c +++ b/ext/mvc/model/resultset/simple.c @@ -28,6 +28,8 @@ #include "Zend/zend_exceptions.h" #include "Zend/zend_interfaces.h" +#include "ext/pdo/php_pdo_driver.h" + #include "kernel/main.h" #include "kernel/memory.h" @@ -102,7 +104,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, __construct){ * Use only fetch assoc */ PHALCON_INIT_VAR(fetch_assoc); - ZVAL_LONG(fetch_assoc, 1); + ZVAL_LONG(fetch_assoc, PDO_FETCH_ASSOC); phalcon_call_method_p1_noret(result, "setfetchmode", fetch_assoc); PHALCON_INIT_VAR(limit);