diff --git a/Doctrine/Collection.php b/Doctrine/Collection.php
index e6296a3d0..ded1b9a55 100644
--- a/Doctrine/Collection.php
+++ b/Doctrine/Collection.php
@@ -273,8 +273,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$query .= " WHERE ".implode(" AND ",$where);
}
- $params = array_merge($params, array_values($this->table->getInheritanceMap()));
-
$coll = $this->table->execute($query, $params, $limit, $offset);
if( ! isset($offset)) {
diff --git a/Doctrine/DB.php b/Doctrine/DB.php
index 13bb36faf..46809dfd4 100644
--- a/Doctrine/DB.php
+++ b/Doctrine/DB.php
@@ -131,7 +131,6 @@ class Doctrine_DBStatement extends PDOStatement {
*/
public function execute(array $params = null) {
$time = microtime();
-
$result = parent::execute($params);
$exectime = (microtime() - $time);
diff --git a/Doctrine/DataDict.php b/Doctrine/DataDict.php
index cea676062..95db8b3f4 100644
--- a/Doctrine/DataDict.php
+++ b/Doctrine/DataDict.php
@@ -1,6 +1,8 @@
getRoot()."/adodb-hack/adodb.inc.php");
@@ -8,13 +10,23 @@ class Doctrine_DataDict {
$this->dbh = $dbh;
$this->dict = NewDataDictionary($dbh);
}
-
+ /**
+ * metaColumns
+ *
+ * @param Doctrine_Table $table
+ * @return array
+ */
public function metaColumns(Doctrine_Table $table) {
return $this->dict->metaColumns($table->getTableName());
}
-
-
- public function createTable($tablename, $columns) {
+ /**
+ * createTable
+ *
+ * @param string $tablename
+ * @param array $columns
+ * @return boolean
+ */
+ public function createTable($tablename, array $columns) {
foreach($columns as $name => $args) {
$r[] = $name." ".$this->getADOType($args[0],$args[1])." ".str_replace("|"," ",$args[2]);
}
@@ -28,8 +40,6 @@ class Doctrine_DataDict {
try {
$this->dbh->query($sql);
} catch(PDOException $e) {
- if($this->dbh->getAttribute(PDO::ATTR_DRIVER_NAME) == "sqlite")
- throw $e;
$return = false;
}
}
diff --git a/Doctrine/Lib.php b/Doctrine/Lib.php
index cbb9bfd7c..505774b6c 100644
--- a/Doctrine/Lib.php
+++ b/Doctrine/Lib.php
@@ -111,12 +111,12 @@ class Doctrine_Lib {
*/
public static function getTableAsString(Doctrine_Table $table) {
$r[] = "
";
- $r[] = "Component : ".$this->getComponentName();
- $r[] = "Table : ".$this->getTableName();
- $r[] = "Repository : ".$this->getRepository()->count()." objects";
+ $r[] = "Component : ".$table->getComponentName();
+ $r[] = "Table : ".$table->getTableName();
+ $r[] = "Repository : ".$table->getRepository()->count()." objects";
if($table->getCache() instanceof Doctrine_Cache_File) {
- $r[] = "Cache : ".$this->getCache()->count()." objects";
- $r[] = "Cache hits : ".array_sum($this->getCache()->getStats())." hits";
+ $r[] = "Cache : ".$table->getCache()->count()." objects";
+ $r[] = "Cache hits : ".array_sum($table->getCache()->getStats())." hits";
}
$r[] = "
";
return implode("\n",$r)."
";
diff --git a/Doctrine/Record.php b/Doctrine/Record.php
index 465172d50..79cb59eba 100644
--- a/Doctrine/Record.php
+++ b/Doctrine/Record.php
@@ -417,7 +417,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$id = array_values($id);
- $query = $this->table->getQuery()." WHERE ".implode(" = ? && ",$this->table->getPrimaryKeys())." = ?";
+ $query = $this->table->getQuery()." WHERE ".implode(" = ? AND ",$this->table->getPrimaryKeys())." = ?";
$this->data = $this->table->getSession()->execute($query,$id)->fetch(PDO::FETCH_ASSOC);
$this->modified = array();
@@ -809,7 +809,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
foreach($r["delete"] as $record) {
$query = "DELETE FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." = ?"
- ." && ".$fk->getLocal()." = ?";
+ ." AND ".$fk->getLocal()." = ?";
$this->table->getSession()->execute($query, array($record->getID(),$this->getID()));
}
foreach($r["add"] as $record) {
@@ -1037,6 +1037,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
final public function loadReference($name) {
+
$fk = $this->table->getForeignKey($name);
$table = $fk->getTable();
@@ -1123,7 +1124,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->originals[$name] = clone $coll;
- } elseif($fk instanceof Doctrine_Association) {
+ } elseif($fk instanceof Doctrine_Association) {
+
$asf = $fk->getAssociationFactory();
$query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local." = ?";
diff --git a/Doctrine/Relation.php b/Doctrine/Relation.php
index f14d921d4..3b526da12 100644
--- a/Doctrine/Relation.php
+++ b/Doctrine/Relation.php
@@ -45,6 +45,10 @@ class Doctrine_Relation {
* @var integer $type bind type
*/
private $type;
+ /**
+ * @var string $alias relation alias
+ */
+ private $alias;
/**
* @param Doctrine_Table $table
@@ -59,6 +63,12 @@ class Doctrine_Relation {
$this->foreign = $foreign;
$this->type = $type;
}
+ /**
+ * @return string the relation alias
+ */
+ public function getAlias() {
+ return $this->alias;
+ }
/**
* @return integer the relation type, either 0 or 1
*/
diff --git a/Doctrine/Session.php b/Doctrine/Session.php
index 04afe1ea3..56a185b61 100644
--- a/Doctrine/Session.php
+++ b/Doctrine/Session.php
@@ -798,7 +798,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$params = array_merge($params, $id);
- $sql = "UPDATE ".$record->getTable()->getTableName()." SET ".implode(", ",$set)." WHERE ".implode(" = ? && ",$record->getTable()->getPrimaryKeys())." = ?";
+ $sql = "UPDATE ".$record->getTable()->getTableName()." SET ".implode(", ",$set)." WHERE ".implode(" = ? AND ",$record->getTable()->getPrimaryKeys())." = ?";
$stmt = $this->dbh->prepare($sql);
$stmt->execute($params);
diff --git a/Doctrine/Table.php b/Doctrine/Table.php
index c0da3d237..e97a9d7fc 100644
--- a/Doctrine/Table.php
+++ b/Doctrine/Table.php
@@ -870,17 +870,25 @@ class Doctrine_Table extends Doctrine_Configurable {
}
/**
* getDefinitionOf
+ *
+ * @return mixed array on success, false on failure
*/
public function getDefinitionOf($column) {
if(isset($this->columns[$column]))
return $this->columns[$column];
+
+ return false;
}
/**
* getTypeOf
+ *
+ * @return mixed string on success, false on failure
*/
public function getTypeOf($column) {
if(isset($this->columns[$column]))
return $this->columns[$column][0];
+
+ return false;
}
/**
* setData
diff --git a/Doctrine/adodb-hack/adodb-datadict.inc.php b/Doctrine/adodb-hack/adodb-datadict.inc.php
index eadd3dc8b..db30d64c7 100644
--- a/Doctrine/adodb-hack/adodb-datadict.inc.php
+++ b/Doctrine/adodb-hack/adodb-datadict.inc.php
@@ -957,6 +957,7 @@ class ADODB_DataDict {
}
$s = "CREATE TABLE $tabname (\n";
$s .= implode(",\n", $lines);
+
if (sizeof($pkey)>0) {
$s .= ",\n PRIMARY KEY (";
$s .= implode(", ",$pkey).")";
diff --git a/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php b/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php
index 7476e512c..b76af462c 100644
--- a/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php
+++ b/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php
@@ -24,31 +24,77 @@ class ADODB2_sqlite extends ADODB_DataDict {
function ActualType($meta)
{
switch($meta) {
- case 'C': return 'VARCHAR';
+ case 'C': return 'TEXT';
case 'XL':
- case 'X': return 'VARCHAR(250)';
+ case 'X': return 'TEXT';
- case 'C2': return 'VARCHAR';
- case 'X2': return 'VARCHAR(250)';
-
- case 'B': return 'VARCHAR';
+ case 'C2': return 'TEXT';
+ case 'X2': return 'TEXT';
+
+ case 'B': return 'BLOB';
case 'D': return 'DATE';
case 'T': return 'DATE';
- case 'L': return 'DECIMAL(1)';
- case 'I': return 'DECIMAL(10)';
- case 'I1': return 'DECIMAL(3)';
- case 'I2': return 'DECIMAL(5)';
- case 'I4': return 'DECIMAL(10)';
- case 'I8': return 'DECIMAL(20)';
+ case 'L': return 'REAL';
+ case 'I': return 'INTEGER';
+ case 'I1': return 'INTEGER';
+ case 'I2': return 'INTEGER';
+ case 'I4': return 'INTEGER';
+ case 'I8': return 'INTEGER';
- case 'F': return 'DECIMAL(32,8)';
+ case 'F': return 'REAL';
case 'N': return 'DECIMAL';
default:
return $meta;
}
}
+ // return string must begin with space
+ function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
+ {
+ $suffix = '';
+ if ($funsigned) $suffix .= ' UNSIGNED';
+ if ($fnotnull) $suffix .= ' NOT NULL';
+ if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
+ if ($fautoinc) $suffix .= ' PRIMARY KEY AUTOINCREMENT';
+ if ($fconstraint) $suffix .= ' '.$fconstraint;
+ return $suffix;
+ }
+
+ function _TableSQL($tabname,$lines,$pkey,$tableoptions)
+ {
+ $sql = array();
+
+ if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
+ $sql[] = sprintf($this->dropTable,$tabname);
+ if ($this->autoIncrement) {
+ $sInc = $this->_DropAutoIncrement($tabname);
+ if ($sInc) $sql[] = $sInc;
+ }
+ if ( isset ($tableoptions['DROP']) ) {
+ return $sql;
+ }
+ }
+ $s = "CREATE TABLE $tabname (\n";
+ $s .= implode(",\n", $lines);
+ /**
+ if (sizeof($pkey)>0) {
+ $s .= ",\n PRIMARY KEY (";
+ $s .= implode(", ",$pkey).")";
+ }
+ */
+ if (isset($tableoptions['CONSTRAINTS']))
+ $s .= "\n".$tableoptions['CONSTRAINTS'];
+
+ if (isset($tableoptions[$this->upperName.'_CONSTRAINTS']))
+ $s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
+
+ $s .= "\n)";
+ if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
+ $sql[] = $s;
+
+ return $sql;
+ }
function AlterColumnSQL($tabname, $flds)
{
@@ -87,4 +133,4 @@ class ADODB2_sqlite extends ADODB_DataDict {
}
-?>
\ No newline at end of file
+?>
diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php
index 208853cfc..b87f12303 100644
--- a/tests/QueryTestCase.php
+++ b/tests/QueryTestCase.php
@@ -10,8 +10,16 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "Log_Status";
$this->tables[] = "Log_Entry";
- $this->dbh->query("DROP TABLE IF EXISTS test_items");
- $this->dbh->query("DROP TABLE IF EXISTS test_entries");
+ try {
+ $this->dbh->query("DROP TABLE test_items");
+ } catch(PDOException $e) {
+
+ }
+ try {
+ $this->dbh->query("DROP TABLE test_entries");
+ } catch(PDOException $e) {
+
+ }
parent::prepareTables();
}
public function testMultiComponentFetching2() {
@@ -1004,10 +1012,10 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(),0);
- $users = $query->query("FROM User-b WHERE User.Phonenumber.phonenumber REGEXP '[123]'");
+ $users = $query->query("FROM User-b WHERE User.Phonenumber.phonenumber LIKE '%123%'");
$this->assertEqual(trim($query->getQuery()),
- "SELECT entity.id AS User__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (phonenumber.phonenumber REGEXP '[123]') AND (entity.type = 0)");
- $this->assertEqual($users->count(),8);
+ "SELECT entity.id AS User__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (phonenumber.phonenumber LIKE '%123%') AND (entity.type = 0)");
+ $this->assertEqual($users->count(),5);
//$values = $query->query("SELECT COUNT(User.name) AS users, MAX(User.name) AS max FROM User");
diff --git a/tests/UnitTestCase.php b/tests/UnitTestCase.php
index 7b1a227f9..986bc6db2 100644
--- a/tests/UnitTestCase.php
+++ b/tests/UnitTestCase.php
@@ -63,8 +63,10 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER);
} else {
- $this->dbh = Doctrine_DB::getConnection();
- $this->session = $this->manager->openSession($this->dbh);
+ //$this->dbh = Doctrine_DB::getConnection();
+ $this->dbh = Doctrine_DB::getConn("sqlite::memory:");
+ //$this->dbh = new PDO("sqlite::memory:");
+ $this->session = $this->manager->openSession($this->dbh);
$this->listener = new Doctrine_EventListener_Debugger();
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
}
@@ -75,7 +77,12 @@ class Doctrine_UnitTestCase extends UnitTestCase {
}
public function prepareTables() {
foreach($this->tables as $name) {
- $this->dbh->query("DROP TABLE IF EXISTS ".strtolower($name));
+ $query = "DROP TABLE ".strtolower($name);
+ try {
+ $this->dbh->query($query);
+ } catch(PDOException $e) {
+
+ }
}
foreach($this->tables as $name) {