Commit 69e3a711 authored by doctrine's avatar doctrine

Fixed: Sqlite compatibility issues

parent 7b37235f
...@@ -273,8 +273,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -273,8 +273,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$query .= " WHERE ".implode(" AND ",$where); $query .= " WHERE ".implode(" AND ",$where);
} }
$params = array_merge($params, array_values($this->table->getInheritanceMap()));
$coll = $this->table->execute($query, $params, $limit, $offset); $coll = $this->table->execute($query, $params, $limit, $offset);
if( ! isset($offset)) { if( ! isset($offset)) {
......
...@@ -131,7 +131,6 @@ class Doctrine_DBStatement extends PDOStatement { ...@@ -131,7 +131,6 @@ class Doctrine_DBStatement extends PDOStatement {
*/ */
public function execute(array $params = null) { public function execute(array $params = null) {
$time = microtime(); $time = microtime();
$result = parent::execute($params); $result = parent::execute($params);
$exectime = (microtime() - $time); $exectime = (microtime() - $time);
......
<?php <?php
class Doctrine_DataDict { class Doctrine_DataDict {
private $dbh; private $dbh;
public function __construct(PDO $dbh) { public function __construct(PDO $dbh) {
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
require_once($manager->getRoot()."/adodb-hack/adodb.inc.php"); require_once($manager->getRoot()."/adodb-hack/adodb.inc.php");
...@@ -8,13 +10,23 @@ class Doctrine_DataDict { ...@@ -8,13 +10,23 @@ class Doctrine_DataDict {
$this->dbh = $dbh; $this->dbh = $dbh;
$this->dict = NewDataDictionary($dbh); $this->dict = NewDataDictionary($dbh);
} }
/**
* metaColumns
*
* @param Doctrine_Table $table
* @return array
*/
public function metaColumns(Doctrine_Table $table) { public function metaColumns(Doctrine_Table $table) {
return $this->dict->metaColumns($table->getTableName()); return $this->dict->metaColumns($table->getTableName());
} }
/**
* createTable
public function createTable($tablename, $columns) { *
* @param string $tablename
* @param array $columns
* @return boolean
*/
public function createTable($tablename, array $columns) {
foreach($columns as $name => $args) { foreach($columns as $name => $args) {
$r[] = $name." ".$this->getADOType($args[0],$args[1])." ".str_replace("|"," ",$args[2]); $r[] = $name." ".$this->getADOType($args[0],$args[1])." ".str_replace("|"," ",$args[2]);
} }
...@@ -28,8 +40,6 @@ class Doctrine_DataDict { ...@@ -28,8 +40,6 @@ class Doctrine_DataDict {
try { try {
$this->dbh->query($sql); $this->dbh->query($sql);
} catch(PDOException $e) { } catch(PDOException $e) {
if($this->dbh->getAttribute(PDO::ATTR_DRIVER_NAME) == "sqlite")
throw $e;
$return = false; $return = false;
} }
} }
......
...@@ -111,12 +111,12 @@ class Doctrine_Lib { ...@@ -111,12 +111,12 @@ class Doctrine_Lib {
*/ */
public static function getTableAsString(Doctrine_Table $table) { public static function getTableAsString(Doctrine_Table $table) {
$r[] = "<pre>"; $r[] = "<pre>";
$r[] = "Component : ".$this->getComponentName(); $r[] = "Component : ".$table->getComponentName();
$r[] = "Table : ".$this->getTableName(); $r[] = "Table : ".$table->getTableName();
$r[] = "Repository : ".$this->getRepository()->count()." objects"; $r[] = "Repository : ".$table->getRepository()->count()." objects";
if($table->getCache() instanceof Doctrine_Cache_File) { if($table->getCache() instanceof Doctrine_Cache_File) {
$r[] = "Cache : ".$this->getCache()->count()." objects"; $r[] = "Cache : ".$table->getCache()->count()." objects";
$r[] = "Cache hits : ".array_sum($this->getCache()->getStats())." hits"; $r[] = "Cache hits : ".array_sum($table->getCache()->getStats())." hits";
} }
$r[] = "</pre>"; $r[] = "</pre>";
return implode("\n",$r)."<br>"; return implode("\n",$r)."<br>";
......
...@@ -417,7 +417,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -417,7 +417,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$id = array_values($id); $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->data = $this->table->getSession()->execute($query,$id)->fetch(PDO::FETCH_ASSOC);
$this->modified = array(); $this->modified = array();
...@@ -809,7 +809,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -809,7 +809,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
foreach($r["delete"] as $record) { foreach($r["delete"] as $record) {
$query = "DELETE FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." = ?" $query = "DELETE FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." = ?"
." && ".$fk->getLocal()." = ?"; ." AND ".$fk->getLocal()." = ?";
$this->table->getSession()->execute($query, array($record->getID(),$this->getID())); $this->table->getSession()->execute($query, array($record->getID(),$this->getID()));
} }
foreach($r["add"] as $record) { foreach($r["add"] as $record) {
...@@ -1037,6 +1037,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1037,6 +1037,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void * @return void
*/ */
final public function loadReference($name) { final public function loadReference($name) {
$fk = $this->table->getForeignKey($name); $fk = $this->table->getForeignKey($name);
$table = $fk->getTable(); $table = $fk->getTable();
...@@ -1123,7 +1124,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1123,7 +1124,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->originals[$name] = clone $coll; $this->originals[$name] = clone $coll;
} elseif($fk instanceof Doctrine_Association) { } elseif($fk instanceof Doctrine_Association) {
$asf = $fk->getAssociationFactory(); $asf = $fk->getAssociationFactory();
$query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local." = ?"; $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local." = ?";
......
...@@ -45,6 +45,10 @@ class Doctrine_Relation { ...@@ -45,6 +45,10 @@ class Doctrine_Relation {
* @var integer $type bind type * @var integer $type bind type
*/ */
private $type; private $type;
/**
* @var string $alias relation alias
*/
private $alias;
/** /**
* @param Doctrine_Table $table * @param Doctrine_Table $table
...@@ -59,6 +63,12 @@ class Doctrine_Relation { ...@@ -59,6 +63,12 @@ class Doctrine_Relation {
$this->foreign = $foreign; $this->foreign = $foreign;
$this->type = $type; $this->type = $type;
} }
/**
* @return string the relation alias
*/
public function getAlias() {
return $this->alias;
}
/** /**
* @return integer the relation type, either 0 or 1 * @return integer the relation type, either 0 or 1
*/ */
......
...@@ -798,7 +798,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab ...@@ -798,7 +798,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$params = array_merge($params, $id); $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 = $this->dbh->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
......
...@@ -870,17 +870,25 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -870,17 +870,25 @@ class Doctrine_Table extends Doctrine_Configurable {
} }
/** /**
* getDefinitionOf * getDefinitionOf
*
* @return mixed array on success, false on failure
*/ */
public function getDefinitionOf($column) { public function getDefinitionOf($column) {
if(isset($this->columns[$column])) if(isset($this->columns[$column]))
return $this->columns[$column]; return $this->columns[$column];
return false;
} }
/** /**
* getTypeOf * getTypeOf
*
* @return mixed string on success, false on failure
*/ */
public function getTypeOf($column) { public function getTypeOf($column) {
if(isset($this->columns[$column])) if(isset($this->columns[$column]))
return $this->columns[$column][0]; return $this->columns[$column][0];
return false;
} }
/** /**
* setData * setData
......
...@@ -957,6 +957,7 @@ class ADODB_DataDict { ...@@ -957,6 +957,7 @@ class ADODB_DataDict {
} }
$s = "CREATE TABLE $tabname (\n"; $s = "CREATE TABLE $tabname (\n";
$s .= implode(",\n", $lines); $s .= implode(",\n", $lines);
if (sizeof($pkey)>0) { if (sizeof($pkey)>0) {
$s .= ",\n PRIMARY KEY ("; $s .= ",\n PRIMARY KEY (";
$s .= implode(", ",$pkey).")"; $s .= implode(", ",$pkey).")";
......
...@@ -24,31 +24,77 @@ class ADODB2_sqlite extends ADODB_DataDict { ...@@ -24,31 +24,77 @@ class ADODB2_sqlite extends ADODB_DataDict {
function ActualType($meta) function ActualType($meta)
{ {
switch($meta) { switch($meta) {
case 'C': return 'VARCHAR'; case 'C': return 'TEXT';
case 'XL': case 'XL':
case 'X': return 'VARCHAR(250)'; case 'X': return 'TEXT';
case 'C2': return 'VARCHAR'; case 'C2': return 'TEXT';
case 'X2': return 'VARCHAR(250)'; case 'X2': return 'TEXT';
case 'B': return 'VARCHAR'; case 'B': return 'BLOB';
case 'D': return 'DATE'; case 'D': return 'DATE';
case 'T': return 'DATE'; case 'T': return 'DATE';
case 'L': return 'DECIMAL(1)'; case 'L': return 'REAL';
case 'I': return 'DECIMAL(10)'; case 'I': return 'INTEGER';
case 'I1': return 'DECIMAL(3)'; case 'I1': return 'INTEGER';
case 'I2': return 'DECIMAL(5)'; case 'I2': return 'INTEGER';
case 'I4': return 'DECIMAL(10)'; case 'I4': return 'INTEGER';
case 'I8': return 'DECIMAL(20)'; case 'I8': return 'INTEGER';
case 'F': return 'DECIMAL(32,8)'; case 'F': return 'REAL';
case 'N': return 'DECIMAL'; case 'N': return 'DECIMAL';
default: default:
return $meta; 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) function AlterColumnSQL($tabname, $flds)
{ {
...@@ -87,4 +133,4 @@ class ADODB2_sqlite extends ADODB_DataDict { ...@@ -87,4 +133,4 @@ class ADODB2_sqlite extends ADODB_DataDict {
} }
?> ?>
\ No newline at end of file
...@@ -10,8 +10,16 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -10,8 +10,16 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "Log_Status"; $this->tables[] = "Log_Status";
$this->tables[] = "Log_Entry"; $this->tables[] = "Log_Entry";
$this->dbh->query("DROP TABLE IF EXISTS test_items"); try {
$this->dbh->query("DROP TABLE IF EXISTS test_entries"); $this->dbh->query("DROP TABLE test_items");
} catch(PDOException $e) {
}
try {
$this->dbh->query("DROP TABLE test_entries");
} catch(PDOException $e) {
}
parent::prepareTables(); parent::prepareTables();
} }
public function testMultiComponentFetching2() { public function testMultiComponentFetching2() {
...@@ -1004,10 +1012,10 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -1004,10 +1012,10 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(),0); $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()), $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)"); "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(),8); $this->assertEqual($users->count(),5);
//$values = $query->query("SELECT COUNT(User.name) AS users, MAX(User.name) AS max FROM User"); //$values = $query->query("SELECT COUNT(User.name) AS users, MAX(User.name) AS max FROM User");
......
...@@ -63,8 +63,10 @@ class Doctrine_UnitTestCase extends UnitTestCase { ...@@ -63,8 +63,10 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER); $this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER);
} else { } else {
$this->dbh = Doctrine_DB::getConnection(); //$this->dbh = Doctrine_DB::getConnection();
$this->session = $this->manager->openSession($this->dbh); $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->listener = new Doctrine_EventListener_Debugger();
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener); $this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
} }
...@@ -75,7 +77,12 @@ class Doctrine_UnitTestCase extends UnitTestCase { ...@@ -75,7 +77,12 @@ class Doctrine_UnitTestCase extends UnitTestCase {
} }
public function prepareTables() { public function prepareTables() {
foreach($this->tables as $name) { 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) { foreach($this->tables as $name) {
......
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