[DDC-2469] SQLite handling for ENUM-Fields Created: 24/May/13 Updated: 24/May/13 Resolved: 24/May/13 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | Mapping Drivers |
| Affects Version/s: | Git Master |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | Andy Rosslau | Assignee: | Marco Pivetta |
| Resolution: | Invalid | Votes: | 0 |
| Labels: | query, schematool, sqlite | ||
| Description |
|
SQLite doesn't support ENUMS! But when I try create the schema of the following Entity Doctrine generates this "CREATE TABLE" - Statement:
CREATE TABLE Entity ([...] NOT NULL, taxation ENUM('incl', 'excl'), maxNumbe[...]
class Entity {
...
/**
* @var string
*
* @ORM\Column(type="string", columnDefinition="ENUM('incl', 'excl')")
*/
private $taxation = self::TAXATION_INCL;
...
}
Produces this error: SQLSTATE[HY000]: General error: 1 near "'incl'": syntax error' |
| Comments |
| Comment by Marco Pivetta [ 24/May/13 ] |
|
Usage of columnDefinition in annotations or generally metadata mappings is all about vendor specific syntax. `columnDefinition` is designed to allow overriding the default ORM column generated DDL to build vendor specific syntax/types, therefore the issue is invalid |
[DDC-2465] ProxyClass load, and empty ids Created: 21/May/13 Updated: 22/May/13 Resolved: 21/May/13 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | ORM |
| Affects Version/s: | 2.3.4 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor |
| Reporter: | Gabriele Tondi | Assignee: | Marco Pivetta |
| Resolution: | Invalid | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Osx |
||
| Description |
|
If you have lazy association (example many-to-one) that have empty id (for empty i mean empty string and not null) you (correctly) get EntityNotFoundException. But i'm working with a system that sometimes put an empty string instead of null in fk fields. So i've add this little snipped of code __load method in $_proxyClassTemplate, ProxyFactory: // GT, 2013-05-21 If all identifier are empty you not need to try load if (is_array($this->_identifier)) { $isEmpty = true; foreach($this->_identifier as $iK => $iV) { if (!empty($iV)) $isEmpty = false; } if ($isEmpty) return; } // END GT EDIT |
| Comments |
| Comment by Marco Pivetta [ 21/May/13 ] |
|
What does `$this->_identifier` contain in your failing case? |
| Comment by Gabriele Tondi [ 21/May/13 ] |
|
It contains for example array( [id] => ); Because on db you find an empty string and not a null value. |
| Comment by Marco Pivetta [ 21/May/13 ] |
|
If I get it correctly, you are using empty strings to emulate NULL references, which is invalid in SQL ( I've explained it extensively at http://stackoverflow.com/questions/15502408/doctrine-2-use-default-0-values-instead-of-null-for-relation/15511715#15511715 ) Is this what you are doing? Because for any identifier that is not NULL an attempt to load it should be run, regardless of its content. |
| Comment by Gabriele Tondi [ 21/May/13 ] |
|
That's not me It's the system by which i'm sharing the db. Are there other (maybe cleaner) ways? Thanks, |
| Comment by Marco Pivetta [ 21/May/13 ] |
|
No, the only correct way to handle this is to set NULL values for the association meta-columns. Marking as invalid |
| Comment by Gabriele Tondi [ 21/May/13 ] |
|
I can't find doc about it: https://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html?highlight=column#annref-column Can you give an example? |
| Comment by Marco Pivetta [ 21/May/13 ] |
|
`$this->someAssociation = NULL;`. That's basically what I mean. |
| Comment by Gabriele Tondi [ 22/May/13 ] |
|
Mmm, didn't understand. Anyway, we've tried to fix the old Delphi Monster witch store empty strings instead of nulls... with no results. So, here is my workaround, maybe this can be useful for other developers who will be in troubles in the future.. In "UnitOfWork" class, public method "createEntity". [...] UnitOfWork.php // TODO: Is this even computed right in all cases of composite keys? foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null; // START-EDIT // GT: our moas store empty string instead of null in fk columns. // So, let's check and handle it as null! if (empty($joinColumnValue)) $joinColumnValue = null; // END-EDIT if ($joinColumnValue !== null) { if ($targetClass->containsForeignIdentifier) { $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue; } else { $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue; } } } [...] Regards, |
| Comment by Marco Pivetta [ 22/May/13 ] |
|
Gabriele Tondi the ORM does not deal with such architectures (nor with generally invalid usage of RDBMS systems). The only acceptable solution in ORM is with correct NULL values, as it should be, so this patch is invalid. |
[DDC-2208] CASE WHEN ... WHEN doesn't work Created: 19/Dec/12 Updated: 22/May/13 Resolved: 22/May/13 |
|
| Status: | Closed |
| Project: | Doctrine 2 - ORM |
| Component/s: | DQL |
| Affects Version/s: | 2.3.1 |
| Fix Version/s: | 2.4 |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | Miha Vrhovnik | Assignee: | Guilherme Blanco |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Having the following part in select DQL throws an exception.
SUM(CASE
WHEN c.startDate <= :start THEN c.endDate - :start
WHEN c.endDate >= :end THEN :end - c.startDate
ELSE 0
END)
exception: [Syntax Error] line 0, col 124: Error: Expected Doctrine\ORM\Query\Lexer::T_ELSE, got '-' It seems that it's failing inside the second THEN This one also seems to fail:
SUM(CASE
WHEN c.startDate <= :start THEN (c.endDate - :start)
WHEN c.endDate >= :end THEN (:end - c.startDate)
ELSE 0
END)
exception:
[Syntax Error] line 0, col 60: Error: Unexpected '('
Another one:
SUM(CASE
WHEN c.startDate <= :start THEN c.endDate - :start
WHEN c.endDate >= :end THEN :end - c.startDate
ELSE 0
END) = :result FROM ...
exception: [Syntax Error] line 0, col 60: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '=' |
| Comments |
| Comment by Miha Vrhovnik [ 20/Dec/12 ] |
|
I've added two more cases where the parsing fails. Do you want a separate tickets for that? |
| Comment by Fabio B. Silva [ 20/Dec/12 ] |
|
Don't worry, I'll spend some time over this... |
| Comment by Miha Vrhovnik [ 20/Dec/12 ] |
|
The 3rd case seems work just fine as a part of a HAVING clause. |
| Comment by Miha Vrhovnik [ 08/Jan/13 ] |
|
Fabio I have two more...
->addSelect('CASE
WHEN po.quantity IS NULL THEN NULL
ELSE po.quantity -
COALESCE(0, (
SELECT COUNT(rd.product) FROM xxxx rd
WHERE (rd.startDate <= :end) AND (rd.endDate >= :start) AND
rd.product = c.product)))
END
AS po.quantity
')
:edit replaced with real query |
| Comment by Miha Vrhovnik [ 08/Jan/13 ] |
|
addon: well the subquery part can be full query with joins .... |
| Comment by Guilherme Blanco [ 22/May/13 ] |
|
After further investigation, JPA 2.0 and 2.1 do not support NULL as part of ScalarExpression. |
| Comment by Miha Vrhovnik [ 22/May/13 ] |
|
Not to sound rude but, the answer is far fetched. So what if JPA is not supporting it. Yes I understand that the Doctrine is modeled after JPA but this shouldn't mean that it's not better in some regards. This is really a low blow especially if there is a need to use a query builder to build the queries. And as I said it's not only the IS NULL but the CASE statement can contain a whole subquery with it's own CASE statements etc... |
[DDC-2444] NULL IN CASE WHEN Created: 12/May/13 Updated: 22/May/13 Resolved: 22/May/13 |
|
| Status: | Closed |
| Project: | Doctrine 2 - ORM |
| Component/s: | DQL |
| Affects Version/s: | 2.3.3 |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | vahid sohrabloo | Assignee: | Guilherme Blanco |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Hi |
| Comments |
| Comment by Miha Vrhovnik [ 14/May/13 ] |
|
We could say a duplicate of: |
| Comment by Guilherme Blanco [ 22/May/13 ] |
|
After further investigation, JPA 2.0 and 2.1 do not support NULL as part of ScalarExpression. |
[DDC-2466] [GH-676] Update UnitOfWork.php Created: 22/May/13 Updated: 22/May/13 Resolved: 22/May/13 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | Doctrine Bot | Assignee: | Marco Pivetta |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Description |
|
This issue is created automatically through a Github pull request on behalf of Kynareth62: Url: https://github.com/doctrine/doctrine2/pull/676 Message: Here, if a field (type date or datetime) is defined as id, I have an error because it's an object and not a string... Can you please fix this bug ? Thank you. |
| Comments |
| Comment by Doctrine Bot [ 22/May/13 ] |
|
A related Github Pull-Request [GH-676] was closed: |
| Comment by Marco Pivetta [ 22/May/13 ] |