[DBAL-345] When inserting decimals into Oracle, getting ORA-01722: invalid number Created: 04/Sep/12 Updated: 17/Sep/12 Resolved: 17/Sep/12 |
|
| Status: | Resolved |
| Project: | Doctrine DBAL |
| Component/s: | None |
| Affects Version/s: | 2.2.2 |
| Fix Version/s: | 2.3 |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | Christian Stoller | Assignee: | Benjamin Eberlei |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | decimal, number, oracle, separator | ||
| Environment: |
Windows 7 (German), Oracle XE 11.2.0, Doctrine 2.2.2, Symfony 2.0.15 |
||
| Description |
|
When I insert decimals into database I get the following error message:
Oracle wants decimals (e.g. NUMBER(5,2)) separated by comma instead of a dot. I think the reason is that I use the german version of Windows. I tried to modify the following method of \Doctrine\DBAL\Driver\OCI8\OCI8Statement::bindValue() just for testing of course:
public function bindValue($param, $value, $type = null)
{
if (is_float($value)) {
$value = str_replace('.', ',', (string) $value); // <--
}
return $this->bindParam($param, $value, $type);
}
With this modification I do not get the error anymore. I found some Links that might be interesting regarding this issue:
|
| Comments |
| Comment by Christian Stoller [ 04/Sep/12 ] |
|
I found out that the database session has the parameter 'NLS_NUMERIC_CHARACTERS', too. SELECT parameter,value FROM v$nls_parameters WHERE parameter = 'NLS_NUMERIC_CHARACTERS' I get this result:
With doctrine I can get the parameter with this (in Symfony2): $conn = $this->getDoctrine()->getEntityManager()->getConnection(); /* @var $conn \Doctrine\DBAL\Connection */ $query = $conn->executeQuery("SELECT parameter,value FROM v\$nls_parameters WHERE parameter = 'NLS_NUMERIC_CHARACTERS'"); /* @var $query \Doctrine\DBAL\Driver\OCI8\OCI8Statement */ $result = $query->fetchAll(\PDO::FETCH_ASSOC); print_r($result); In this case I get this output:
And with ALTER SESSION SET NLS_NUMERIC_CHARACTERS = '. ' I can change the parameter. When I execute the above query before I do my insert with decimal values, everything works as expected |
| Comment by Benjamin Eberlei [ 05/Sep/12 ] |
|
There is an Oci8SessionInitListener inside Doctrine DBAL. It does not yet contain the numeric character change. Can you open a pull request on Github DBAL to add this? |
| Comment by Christian Stoller [ 13/Sep/12 ] |
|
Hi Benjamin. |
| Comment by Benjamin Eberlei [ 17/Sep/12 ] |
|
A related Github Pull-Request [GH-197] was closed |