Commit e3f5aa9f authored by zYne's avatar zYne

Boolean type bugs fixed, fixes #101

Ticket: 101
parent 2c16937d
......@@ -235,6 +235,17 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
return array();
}
/**
* convertBoolean
* converts boolean to integers
*
* @param mixed $item
* @return void
*/
public static function convertBoolean(&$item) {
if(is_bool($item))
$item = (int) $item;
}
/**
* execute
* executes the dql query and populates all collections
......@@ -246,6 +257,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$this->data = array();
$this->collections = array();
array_walk($params, array(__CLASS__, 'convertBoolean'));
if( ! $this->view)
$query = $this->getQuery();
else
......
......@@ -75,13 +75,18 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$enumIndex = $table->enumIndex($field, trim($value,"'"));
$alias = $this->query->getTableAlias($reference);
$table = $this->query->getTable($alias);
if(trim($value) == 'true')
$value = 1;
elseif(trim($value) == 'false')
$value = 0;
switch($operator) {
case '<':
case '>':
case '=':
if($enumIndex !== false)
$value = $enumIndex;
$value = $enumIndex;
$where = $alias.'.'.$field.' '.$operator.' '.$value;
break;
......
......@@ -324,6 +324,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
case "enum":
$this->data[$name] = $this->table->enumValue($name, $tmp[$name]);
break;
case "boolean":
case "integer":
if($tmp[$name] !== self::$null)
settype($tmp[$name], $type);
default:
$this->data[$name] = $tmp[$name];
endswitch;
......@@ -889,6 +893,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
case 'gzip':
$a[$v] = gzcompress($this->data[$v],5);
break;
case 'boolean':
$a[$v] = (int) $this->data[$v];
break;
case 'enum':
$a[$v] = $this->table->enumIndex($v,$this->data[$v]);
break;
......
......@@ -13,8 +13,7 @@ Following data types are availible in doctrine:
<li /><b> object </b>
<ul> The same as type 'object' in php. Automatically serialized when saved into database and unserialized when retrieved from database.</ul>
<li /><b> enum </b>
<ul> Unified 'enum' type. Automatically converts the string values into index numbers and vice versa. The possible values for the column
can be specified with Doctrine_Record::setEnumValues(columnName, array values).</ul>
<ul> </ul>
<li /><b> timestamp </b>
<dd /> Database 'timestamp' type
<li /><b> clob</b>
......
......@@ -102,20 +102,7 @@ $menu = array("Getting started" =>
"Enum emulation",
),
"Data types" => array(
"Boolean",
"Integer",
"Float",
"String",
"Array",
"Object",
"Blob",
"Clob",
"Timestamp",
"Date",
"Enum",
"Gzip",
),
"Record identifiers" => array(
"Introduction",
"Autoincremented",
......@@ -126,16 +113,20 @@ $menu = array("Getting started" =>
"Schema reference" =>
array(
"Data types" => array(
"PHP based types" =>
array(
"Boolean",
"Integer",
"Float",
"String",
"Array",
"Object",
),
),
"Blob",
"Clob",
"Timestamp",
"Date",
"Enum",
"Gzip",
),
),
"Basic Components" =>
array(
......@@ -153,6 +144,7 @@ $menu = array("Getting started" =>
"Getting record state",
"Getting object copy",
"Serializing",
"Existence checking",
"Callbacks"),
"Connection"
=> array("Introduction",
......@@ -199,6 +191,10 @@ $menu = array("Getting started" =>
"Using SQL",
"Adding components",
"Method overloading"),
"DB" => array(
"Introduction",
"Connecting to a database",
"Using event listeners"),
/**
"Statement - <font color='red'>UNDER CONSTRUCTION</font>" => array("Introduction",
"Setting parameters",
......@@ -263,6 +259,8 @@ $menu = array("Getting started" =>
"List of events",
"Listening events",
"Chaining",
"AccessorInvoker",
"Creating a logger",
),
"Validators" => array(
"Intruduction",
......@@ -275,15 +273,6 @@ $menu = array("Getting started" =>
"Managing views",
"Using views"
),
/**
"Hook" => array(
"Introduction",
"Parameter hooking",
"Paging",
"Setting conditions",
"Sorting"
),
*/
"Cache" => array(
"Introduction",
"Query cache"),
......
......@@ -31,15 +31,33 @@ class Doctrine_BooleanTestCase extends Doctrine_UnitTestCase {
$test = $test->getTable()->find($test->id);
$this->assertEqual($test->is_working, true);
}
public function testNormalQuerying() {
$query = new Doctrine_Query($this->connection);
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = 0');
$this->assertEqual(count($ret), 1);
public function testFetching() {
$query = new Doctrine_Query($this->connection);
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = 1');
Doctrine_Lib::formatSql($query->getQuery());
$this->assertEqual(count($ret), 1);
}
public function testPreparedQueries() {
$query = new Doctrine_Query($this->connection);
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = ?', array(false));
$this->assertEqual(count($ret), 1);
$query = new Doctrine_Query($this->connection);
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = ?', array(false));
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = ?', array(true));
$this->assertEqual(count($ret), 1);
}
public function testFetchingWithSmartConversion() {
$query = new Doctrine_Query($this->connection);
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = false');
$this->assertEqual(count($ret), 1);
$query = new Doctrine_Query($this->connection);
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = ?', array(true));
$ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = true');
Doctrine_Lib::formatSql($query->getQuery());
$this->assertEqual(count($ret), 1);
}
......
......@@ -16,7 +16,7 @@ class Doctrine_DataDict_Sqlite_TestCase extends Doctrine_UnitTestCase {
}
public function testListTables() {
$result = $this->dict->listTables();
}
public function testIntegerType() {
$this->assertEqual($this->columns['col_int']->isUnique(), false);
......
......@@ -32,12 +32,11 @@ require_once("ImportTestCase.php");
require_once("BooleanTestCase.php");
require_once("EnumTestCase.php");
require_once("RelationAccessTestCase.php");
require_once("DataDictSqliteTestCase.php");
error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests");
$test->addTestCase(new Doctrine_DB_TestCase());
$test->addTestCase(new Doctrine_ConnectionTestCase());
......@@ -76,9 +75,9 @@ $test->addTestCase(new Doctrine_RawSql_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_SchemaTestCase());
//$test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_ImportTestCase());
//$test->addTestCase(new Doctrine_ImportTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase());
......@@ -93,6 +92,9 @@ $test->addTestCase(new Doctrine_EnumTestCase());
$test->addTestCase(new Doctrine_RelationAccessTestCase());
$test->addTestCase(new Doctrine_EventListener_Chain_TestCase());
$test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......@@ -124,9 +126,9 @@ if (TextReporter::inCli()) {
} else {
if (isset($_POST))
{
$dsn = $_POST['dsn'];
$username = $_POST['username'];
$password = $_POST['password'];
$dsn = isset($_POST['dsn'])?$_POST['dsn']:null;
$username = isset($_POST['username'])?$_POST['username']:null;
$password = isset($_POST['password'])?$_POST['password']:null;
}
$test->run(new MyReporter());
$output = ob_get_clean();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment