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

a bug of db class #1695

Closed
dancebear opened this issue Dec 14, 2013 · 3 comments
Closed

a bug of db class #1695

dancebear opened this issue Dec 14, 2013 · 3 comments

Comments

@dancebear
Copy link
Contributor

The method modifyColumn of database class will lost the AUTO_INCREMENT attribute of fields.
Because modifyColumn method does not determine whether the field contains AUTO_INCREMENT attribute.

the same bug is also at addColumn method ,which means you can not add a column that contains the attribute AUTO_INCREMENT

数据库类的modifyColumn方法会丢失字段的AUTO_INCREMENT属性;因为modifyColumn方法没有判断字段是否包含AUTO_INCREMENT属性。
addColumn 包含同样的问题,即无法添加AUTO_INCREMENT字段。

@ghost
Copy link

ghost commented Dec 15, 2013

AUTO_INCREMENT won't work with addColumn() because the auto increment column has to be a PRIMARY KEY and Phalcon\Db\Column is unaware of indices.

For modifyColumn() you will need to apply the following patch:

--- a/ext/db/dialect/mysql.c
+++ b/ext/db/dialect/mysql.c
@@ -247,16 +247,14 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, addColumn){
 PHP_METHOD(Phalcon_Db_Dialect_Mysql, modifyColumn){

        zval *table_name, *schema_name, *column, *sql = NULL, *name;
-       zval *column_definition, *is_not_null;
+       zval *column_definition, *is_not_null, *is_autoincrement;

        PHALCON_MM_GROW();

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

-       if (Z_TYPE_P(column) != IS_OBJECT) {
-               PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column");
-               return;
-       }
+       PHALCON_VERIFY_INTERFACE_EX(column, phalcon_db_columninterface_ce, phalcon_db_exception_ce, 1);
+
        if (zend_is_true(schema_name)) {
                PHALCON_INIT_VAR(sql);
                PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` MODIFY ");
@@ -278,6 +276,13 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, modifyColumn){
                phalcon_concat_self_str(&sql, SL(" NOT NULL") TSRMLS_CC);
        }

+       PHALCON_INIT_VAR(is_autoincrement);
+       phalcon_call_method(is_autoincrement, column, "isautoincrement");
+
+       if (zend_is_true(is_autoincrement)) {
+               phalcon_concat_self_str(&sql, SL(" AUTO_INCREMENT") TSRMLS_CC);
+       }
+
        RETURN_CTOR(sql);
 }

@ghost
Copy link

ghost commented Dec 15, 2013

Please check now.

@dancebear
Copy link
Contributor Author

ok thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants