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

Can't rename a Column with MySQL #13012

Closed
Ark4ne opened this issue Aug 9, 2017 · 3 comments
Closed

Can't rename a Column with MySQL #13012

Ark4ne opened this issue Aug 9, 2017 · 3 comments
Assignees
Labels
bug A bug report status: medium Medium
Milestone

Comments

@Ark4ne
Copy link

Ark4ne commented Aug 9, 2017

Column renaming in MySQL dialect, wasn't implemented.

\Phalcon\Db\Dialect\Mysql::modifyColumn does not use the "currentColumn" variable, and therefore will never produce the column renaming request.

use \Phalcon\Db\Column;

$columnId = new Column('id', ['type' => Column::TYPE_INTEGER, 'primary' => true, 'autoIncrement' => true, 'unsigned' => true]);

$columnWrongName = new Column('wrong_name', ['type' => Column::TYPE_VARCHAR]);

$db = new \Phalcon\Db\Adapter\Pdo\Mysql([
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
    'dbname'   => 'test',
    'charset'  => 'utf8',
]);

$db->createTable('test', 'test', ['columns' => [$columnId, $columnWrongName]]);

$columnName = new Column('name', ['type' => Column::TYPE_VARCHAR]);

$db->modifyColumn('test', 'test', $columnName, $columnWrongName);

Output :

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Champ 'name' inconnu dans test in {path}/test.php:23
Stack trace:
#0 [internal function]: PDO->exec('ALTER TABLE `te...')
#1 [internal function]: Phalcon\Db\Adapter\Pdo->execute('ALTER TABLE `te...')
#2 {path}/test.php(23): Phalcon\Db\Adapter->modifyColumn('test', 'test', Object(Phalcon\Db\Column), Object(Phalcon\Db\Column))
#3 {main}

Details

  • Phalcon version: 3.x
  • PHP Version: 5.x / 7.x
  • Operating System:
  • Zephir version (if any):
  • Server:
  • Other related info (Database, table schema): MySQL
@sergeyklay
Copy link
Contributor

sergeyklay commented Nov 20, 2017

Could you please provide the latest stable version of Phalcon you are use? Also I'll need RDBMS version/name. This is why we created an issue template.

@sergeyklay sergeyklay added Need information need script to reproduce Script is required to reproduce the issue labels Nov 20, 2017
@Ark4ne
Copy link
Author

Ark4ne commented Nov 22, 2017

Hello,

I tested with the last 3 stable version 3.0.4, 3.1.1, 3.2.4. and also with branch 3.3.x.
The problem is present on all.

For Mysql, I tested on 5.5, 5.6, 5.7.

This is because the "currentColumn" variable is not used: https://github.com/phalcon/cphalcon/blob/3.3.x/phalcon/db/dialect/mysql.zep#L258

For Postgresql, this variable is well used, which makes it possible to modify the columns.

use \Phalcon\Db\Column;
use \Phalcon\Db\Adapter\Pdo\Mysql as DbMysql;

$db = new DbMysql([
  'host'     => 'localhost',
  'username' => 'root',
  'password' => '',
  'dbname'   => 'schema_test',
  'charset'  => 'utf8',
]);

$db->createTable('test', 'schema_test', [
  'columns' => [
    new Column('id', ['type' => Column::TYPE_INTEGER, 'primary' => true, 'autoIncrement' => true, 'unsigned' => true]),
    new Column('wrong_name', ['type' => Column::TYPE_VARCHAR, 'size' => 256]),
  ],
]);

$currentColumnWrongName = new Column('wrong_name', ['type' => Column::TYPE_VARCHAR]);

$columnGoodName = new Column('name', ['type' => Column::TYPE_VARCHAR]);

$db->modifyColumn('test', 'schema_test', $columnGoodName, $currentColumnWrongName );

@sergeyklay sergeyklay added Bug - Medium and removed Need information need script to reproduce Script is required to reproduce the issue labels Jan 15, 2018
@sergeyklay sergeyklay self-assigned this Jan 15, 2018
@sergeyklay sergeyklay added this to the 3.3.x milestone Jan 15, 2018
@sergeyklay
Copy link
Contributor

Fixed in the 3.3.x branch. Feel free to open a new issue if the problem appears again. Thank you for contributing.

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants