DDC-100: Default values are not escaped #122

Closed
opened 2026-01-22 12:27:55 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 2, 2009).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user nicokaiser:

When using default values for strings, they are not escaped properly when the DB schema is created.

@Column(name="name", type="string", length=50, default="Unknown User")

results in

CREATE TABLE users (..., name VARCHAR(50) DEFAULT Unknown User NOT NULL, ...)

which fails because "Unknown User" is not escaped.

Originally created by @doctrinebot on GitHub (Nov 2, 2009). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user nicokaiser: When using default values for strings, they are not escaped properly when the DB schema is created. @Column(name="name", type="string", length=50, default="Unknown User") results in CREATE TABLE users (..., name VARCHAR(50) DEFAULT Unknown User NOT NULL, ...) which fails because "Unknown User" is not escaped.
admin closed this issue 2026-01-22 12:27:55 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 2, 2009):

Comment created by romanb:

The option for database default values might be removed but this is yet unclear.

Use PHP default values instead since that way you have the default value in your object (Doctrine wont go back to the DB just to get the DB-generated default value).

private $name = "Unknown User";
@doctrinebot commented on GitHub (Nov 2, 2009): Comment created by romanb: The option for database default values might be removed but this is yet unclear. Use PHP default values instead since that way you have the default value in your object (Doctrine wont go back to the DB just to get the DB-generated default value). ``` private $name = "Unknown User"; ```
Author
Owner

@doctrinebot commented on GitHub (Jan 19, 2010):

Comment created by romanb:

The default option should be removed once the columnDefinition is implemented. Database-level default values can then be set via the columnDefinition.

@doctrinebot commented on GitHub (Jan 19, 2010): Comment created by romanb: The default option should be removed once the columnDefinition is implemented. Database-level default values can then be set via the columnDefinition.
Author
Owner

@doctrinebot commented on GitHub (Jan 23, 2010):

Comment created by @beberlei:

Hm Roman, one problem surfaced when i did a skip try to remove defaults in ClassMetadataInfo:

    public function setVersionMapping(array &$mapping)
    {
        $this->isVersioned = true;
        $this->versionField = $mapping['fieldName'];

        if ( ! isset($mapping['default'])) {
            if ($mapping['type'] == 'integer') {
                $mapping['default'] = 1;
            } else if ($mapping['type'] == 'datetime') {
                $mapping['default'] = 'CURRENT_TIMESTAMP';
            } else {
                throw DoctrineException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']);
            }
        }
    }

Two solutions:

  1. Doctrine knows when a version column is first persisted it could set it in the Code.
  2. Doctrine\DBAL\Schema 'default' won't be removed as a feature, since its a database concept. If we only remove it from all the mapping drivers we could still utilize it at this position there.
@doctrinebot commented on GitHub (Jan 23, 2010): Comment created by @beberlei: Hm Roman, one problem surfaced when i did a skip try to remove defaults in ClassMetadataInfo: ``` public function setVersionMapping(array &$mapping) { $this->isVersioned = true; $this->versionField = $mapping['fieldName']; if ( ! isset($mapping['default'])) { if ($mapping['type'] == 'integer') { $mapping['default'] = 1; } else if ($mapping['type'] == 'datetime') { $mapping['default'] = 'CURRENT_TIMESTAMP'; } else { throw DoctrineException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']); } } } ``` Two solutions: 1. Doctrine knows when a version column is first persisted it could set it in the Code. 2. Doctrine\DBAL\Schema 'default' won't be removed as a feature, since its a database concept. If we only remove it from all the mapping drivers we could still utilize it at this position there.
Author
Owner

@doctrinebot commented on GitHub (Jan 24, 2010):

Comment created by romanb:

@Benjamin: Nr. 1 would not reliably work. In the case of a timestamp, time configuration issues come to mind. So Nr.2 is the way to go. Just remove the support in the ORM layer.

@doctrinebot commented on GitHub (Jan 24, 2010): Comment created by romanb: @Benjamin: Nr. 1 would not reliably work. In the case of a timestamp, time configuration issues come to mind. So Nr.2 is the way to go. Just remove the support in the ORM layer.
Author
Owner

@doctrinebot commented on GitHub (Jan 25, 2010):

Comment created by @beberlei:

will do, it is quite a no-brainer this way.

@doctrinebot commented on GitHub (Jan 25, 2010): Comment created by @beberlei: will do, it is quite a no-brainer this way.
Author
Owner

@doctrinebot commented on GitHub (Jan 26, 2010):

Comment created by @beberlei:

Default has been removed.

@doctrinebot commented on GitHub (Jan 26, 2010): Comment created by @beberlei: Default has been removed.
Author
Owner

@doctrinebot commented on GitHub (Jan 26, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jan 26, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#122