[DBAL-91] orm:convert-mapping SchemaException on Postgres reserved words Created: 10/Jan/11  Updated: 12/Feb/11  Resolved: 12/Feb/11

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: 2.0
Fix Version/s: 2.0.2, 2.1

Type: Bug Priority: Major
Reporter: Emil Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

CentOs 5.5, Postgres 8.1.22


Attachments: File test-creation.sql    
Issue Links:
Duplicate
is duplicated by DBAL-88 MySqlPlatform not escaping table names Resolved

 Description   

While execuiting

doctrine orm:convert-mapping --from-database yml /tmp/test.yml

I get presented an error

[Doctrine\DBAL\Schema\SchemaException]
Invalid index-name tablename_"input"_idx given, has to be [a-zA-Z0-9_]

The index "type" is quoted because this is a reserved word in Postgres. for example see the following definition:

FOREIGN KEY (something) REFERENCES somethings(id) ON UPDATE CASCADE
FOREIGN KEY (another) REFERENCES anothers(id) ON UPDATE CASCADE
FOREIGN KEY ("type") REFERENCES logtypes(id) ON UPDATE CASCADE

Only type will be quoted because it is a reserved word.



 Comments   
Comment by Benjamin Eberlei [ 10/Jan/11 ]

You have to quote with `` in Doctrine. That is translated to the underyling vendor quotation signs.

Comment by Emil [ 10/Jan/11 ]

@benjamin this considers a mapping error from database (Postgres) to YAML through the doctrine commandline tool, I do not think your comment is relevant for this issue.

Comment by Benjamin Eberlei [ 11/Jan/11 ]

@Emil it is, are you quoting the reserved word in the YML file using `` ? DBAL has some logic to fix escaping in these cases.

Comment by Emil [ 11/Jan/11 ]

@benjamin uhm, I might be baffled with the complexity of Doctrine or just plain wrong. But I'm trying to create a YML file from my database. How can I be making a mistake in the YML file with quotes?

The error message is presented because the Dcotrine ORM module tries to generate index names on columns, based on the database schema, but fails because the returned names (from the database schema) contain quotes (because they are reserved words).

Comment by Benjamin Eberlei [ 11/Jan/11 ]

Sorry, now i get it. I didnt relaize the usecase you were applying. Yes you are right

Comment by Benjamin Eberlei [ 23/Jan/11 ]

Can you give me an Example Postgresql Schema with DDL SQL that produces this error?

Comment by Emil [ 10/Feb/11 ]

These are the table creation for a test table which is able to reproduce the error.

Comment by Emil [ 10/Feb/11 ]

I hope this is enough information. The attached SQL reproduces the following error:

  1. doctrine orm:convert-mapping --from-database yml /tmp/test.yml

[Doctrine\DBAL\Schema\SchemaException]
Invalid index-name something_"input"_idx given, has to be [a-zA-Z0-9_]

orm:convert-mapping [--filter="..."] [--from-database] [-extend[="..."]] [-num-spaces[="..."]] [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version] [-a|--ansi] [-n|--no-interaction] command to-type dest-path

Comment by Benjamin Eberlei [ 12/Feb/11 ]

I can't reproduce it

Can you run the command with --verbose ? Additionally in lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php can you var_dump() $metadata after line 119?

Comment by Benjamin Eberlei [ 12/Feb/11 ]

Ok i could reproduce it now. Input is not a keyword for me though, type also not. Coudl reproduce it with "table"

Comment by Benjamin Eberlei [ 12/Feb/11 ]

Ok, this is a DBAL issue.

Comment by Benjamin Eberlei [ 12/Feb/11 ]

This is fixed and will be included in 2.0.2





[DBAL-88] MySqlPlatform not escaping table names Created: 10/Feb/11  Updated: 26/Feb/11  Resolved: 26/Feb/11

Status: Resolved
Project: Doctrine DBAL
Component/s: Platforms
Affects Version/s: 2.0
Fix Version/s: 2.0.2, 2.1

Type: Bug Priority: Major
Reporter: James Reed Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Attachments: File MySqlPlatform.php    
Issue Links:
Duplicate
duplicates DBAL-91 orm:convert-mapping SchemaException o... Resolved

 Description   

Methods in the MySql Platform that use the table name are not escaping the table name. This causes problems when your table name is the same as a reserved word in MySql. Example:

public function getListTableConstraintsSQL($table)

{ return 'SHOW INDEX FROM ' . $table; }

If my table name is User this method will fail and cause a SQL error because the word User is a reserved word in MySql. You need to escape the table name with backticks to prevent these errors. Example:

public function getListTableConstraintsSQL($table)

{ return 'SHOW INDEX FROM `' . $table . '`'; }

I encountered this problem while reverse engineering my existing MySql database. I've attached a fixed version that solved my reverse engineering problems.



 Comments   
Comment by Benjamin Eberlei [ 11/Feb/11 ]

Duplicate of DDC-976

Comment by Benjamin Eberlei [ 12/Feb/11 ]

This issue is not a duplicate, only related to DBAL-91.

Comment by Benjamin Eberlei [ 26/Feb/11 ]

Fixed





[DBAL-87] Undefined variable printer in DBAL Import Command Created: 09/Feb/11  Updated: 11/Feb/11  Resolved: 11/Feb/11

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.0.1
Fix Version/s: 2.0.2

Type: Bug Priority: Minor
Reporter: Rob Squires Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

PHP Version => 5.3.3-1ubuntu9.3



 Description   

When running dbal:import, I receive the following error :

Undefined variable: printer in /frameworks/doctrine-orm/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php on line 113

113 : $printer->writeln('OK!');

Other output is implemented using $output->write();



 Comments   
Comment by Benjamin Eberlei [ 11/Feb/11 ]

Fixed.





[DBAL-86] Documentation tells about setCustomTypes() but the method doesn't actually exist Created: 04/Feb/11  Updated: 27/Feb/11  Resolved: 27/Feb/11

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.0.0-BETA2, 2.0.0-BETA3, 2.0.0-BETA4, 2.0.0-RC1-RC3, 2.0-RC4, 2.0-RC5, 2.0, 2.0.1
Fix Version/s: 2.0.2

Type: Documentation Priority: Minor
Reporter: Boris Guéry Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

In basic mapping section

Quote:

When you have implemented the type you still need to let Doctrine know about it. This can be achieved through the Doctrine\DBAL\Configuration#setCustomTypes(array $types) method. Doctrine\ORM\Configuration is a subclass of Doctrine\DBAL\Configuration, so the methods are available on your ORM Configuration instance as well.

The method seems to have been removed on this commit 354ede



 Comments   
Comment by Benjamin Eberlei [ 07/Feb/11 ]

Ah yes, it works like the code snippet right next to this paragraph:

<?php
// in bootstrapping code

// ...

use Doctrine\DBAL\Types\Type;

// ...

// Register my type
Type::addType('mytype', 'My\Project\Types\MyType');
Comment by Benjamin Eberlei [ 27/Feb/11 ]

Fixed.





[DBAL-85] Illegal quotes in SHOW FULL TABLES WHERE Table_type = "BASE TABLE" Created: 04/Feb/11  Updated: 11/Feb/11  Resolved: 11/Feb/11

Status: Resolved
Project: Doctrine DBAL
Component/s: Platforms
Affects Version/s: None
Fix Version/s: 2.0.2

Type: Bug Priority: Major
Reporter: Karsten Dambekalns Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File base_table.patch    
Issue Links:
Duplicate
is duplicated by DDC-1019 Double quotation mark mysql query err... Resolved

 Description   

When trying to generate update SQL on MySQL running in ANSI SQL mode you get the error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BASE TABLE' in 'where clause'

This is caused by the use of identifier quotes (") instead of literal quotes (') in the query
SHOW FULL TABLES WHERE Table_type = "BASE TABLE"

This is in MySqlPlatform#getListTablesSQL()



 Comments   
Comment by Bernhard Schlas [ 07/Feb/11 ]

Here is a temporary dirty patch for this problem. ONLY FOR TESTING PURPOSE!!!

Comment by Karsten Dambekalns [ 08/Feb/11 ]

Why not simply change MySqlPlatform#getListTablesSQL()?

Comment by Bernhard Schlas [ 08/Feb/11 ]

Because did this quick and dirty patch before i read this issue. Actually i've attached a better one,

Comment by Karsten Dambekalns [ 09/Feb/11 ]

With this change it works for me.

Comment by Benjamin Eberlei [ 11/Feb/11 ]

Fixed.





[DBAL-84] Long string fields are being silently changed to 255 characters in the schema Created: 31/Jan/11  Updated: 20/Feb/11  Resolved: 20/Feb/11

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: 2.0, 2.0.1
Fix Version/s: 2.0.2, 2.1

Type: Bug Priority: Major
Reporter: Oleg Anashkin Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

I have an entity like this:

/**
 * @orm:Entity
 */
class Product
{
    /**
     * @orm:Id
     * @orm:Column(name="Merchant",type="string",length=50)
     */
    protected $merchant;

    /**
     * @orm:Column(name="Name",type="string",length=500)
     */
    protected $name;
}

When I change the length of $name field to 4000 it updates the schema like it is supposed to:

php.exe -f console doctrine:schema:update --dump-sql
ALTER TABLE product CHANGE Name Name VARCHAR(4000) NOT NULL

But when I change the length to 5000 it just silently without any warning uses value 255 instead:

php.exe -f console doctrine:schema:update --dump-sql
ALTER TABLE product CHANGE Name Name VARCHAR(255) NOT NULL

I had to look into actual table definition using mysql browser to find this issue because doctrine doesn't even warn about it. This could lead to some pretty serious bugs!



 Comments   
Comment by Benjamin Eberlei [ 20/Feb/11 ]

Fixed in master and 2.0.x





Generated at Tue Oct 21 12:39:26 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.