Fixed: Sqlite compatibility issues
This commit is contained in:
parent
7b37235fcc
commit
69e3a7112e
@ -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)) {
|
||||
|
@ -131,7 +131,6 @@ class Doctrine_DBStatement extends PDOStatement {
|
||||
*/
|
||||
public function execute(array $params = null) {
|
||||
$time = microtime();
|
||||
|
||||
$result = parent::execute($params);
|
||||
|
||||
$exectime = (microtime() - $time);
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
class Doctrine_DataDict {
|
||||
|
||||
private $dbh;
|
||||
|
||||
public function __construct(PDO $dbh) {
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
require_once($manager->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;
|
||||
}
|
||||
}
|
||||
|
@ -111,12 +111,12 @@ class Doctrine_Lib {
|
||||
*/
|
||||
public static function getTableAsString(Doctrine_Table $table) {
|
||||
$r[] = "<pre>";
|
||||
$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[] = "</pre>";
|
||||
return implode("\n",$r)."<br>";
|
||||
|
@ -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." = ?";
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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).")";
|
||||
|
@ -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 {
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
@ -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");
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user