Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0.14
-
Fix Version/s: 1.2.3
-
Component/s: Connection
-
Labels:None
-
Environment:Oracle Driver
Description
I've run into a problem where I'm unable to set a default value for a boolean field when creating Oracle tables using Doctrine. The summary of this issue is that when Doctrine quotes a '0' or false value for a boolean field, it comes back blank... which doesn't work as an option for the DEFAULT parameter of field definitions in table creation.
Here are the hairy details. I have a schema which looks something like this (simplified for the example):
User:
tableName: users
columns:
id: {type: integer, primary: true, autoincrement: true}
username: {type: string, length: 255, unique: true, notnull: true}
disabled: {type: boolean, default: false}
When I export the table, it's generating invalid DDL like this:
CREATE TABLE users (id NUMBER(8), username VARCHAR2(255) NOT NULL UNIQUE, disabled NUMBER(1) DEFAULT , PRIMARY KEY(id))
The important part of this is the DEFAULT parameter on the 'disabled' field definition – it's missing the value. I tracked all this down to an issue in Doctrine_Formatter->quote(), which gets called when the DDL is being created. When passed '0' as its input with a type of boolean, it apparently returns the empty string. This may ultimately be a bug in the PDO_OCI driver, because the quote method is relying on the quote method of the database handle.
I've hacked around this by overriding the behaviour of the quote method in Doctrine_Connection_Oracle. I did this by adding the following method:
/**
* Override quote behaviour for boolean to fix issues with quoting of
* boolean values.
*/
public function quote($input, $type = null)
{
if ($type === 'boolean') {
if ($input === null) {
return null;
} else {
return (($input) ? 1 : 0);
}
} else {
return parent::quote($input, $type);
}
}
It seems to work for me, but I'd appreciate it if wiser heads than me would take a look and see if this is a sign of some larger issue, and if the way I've fixed it seems appropriate. I also am unsure of how/if this needs to propogate to newer versions.