1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Doctrine_DataDict_Sqlite driver

This commit is contained in:
zYne 2006-09-25 21:08:02 +00:00
parent 70ebe0d9af
commit cec372dfe1
6 changed files with 137 additions and 99 deletions

View File

@ -94,10 +94,18 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/**
* returns the database handler of which this connection uses
*
* @return object PDO the database handler
* @return PDO the database handler
*/
public function getDBH() {
return $this->dbh;
}
/**
* returns a datadict object
*
* @return Doctrine_DataDict
*/
public function getDataDict() {
}
/**
* returns the regular expression operator

View File

@ -28,7 +28,7 @@
*/
class Doctrine_DataDict {
private $dbh;
protected $dbh;
public function __construct(PDO $dbh) {
$file = Doctrine::getPath().DIRECTORY_SEPARATOR."Doctrine".DIRECTORY_SEPARATOR."adodb-hack".DIRECTORY_SEPARATOR."adodb.inc.php";

View File

@ -27,7 +27,7 @@
* @version $Id$
*/
class Doctrine_DataDict_Sqlite {
class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
/**
* lists all databases
*
@ -79,6 +79,22 @@ class Doctrine_DataDict_Sqlite {
*/
public function listTableColumns($table) {
$sql = "PRAGMA table_info($table)";
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$description = array();
$columns = array();
foreach ($result as $key => $val) {
$description = array(
'name' => $val['name'],
'type' => $val['type'],
'notnull' => (bool) $val['notnull'],
'default' => $val['dflt_value'],
'primary' => (bool) $val['pk'],
);
$columns[$val['name']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
@ -90,13 +106,17 @@ class Doctrine_DataDict_Sqlite {
}
/**
* lists table constraints
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT name FROM sqlite_master WHERE type='table' "
. "UNION ALL SELECT name FROM sqlite_temp_master "
. "WHERE type='table' ORDER BY name";
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
/**
* lists table triggers

View File

@ -33,102 +33,43 @@
* class Doctrine_Schema_Column
* Holds information on a database table field
*/
class Doctrine_Schema_Column extends Doctrine_Schema_Object
implements IteratorAggregate
{
/** Aggregations: */
/** Compositions: */
var $m_Vector = array();
/*** Attributes: ***/
class Doctrine_Schema_Column extends Doctrine_Schema_Object implements IteratorAggregate {
/**
* Column name
* @access public
* column definitions
* @var array $definition
*/
public $name;
/**
* Column type e.g. varchar, char, int etc.
* @access public
*/
public $type;
/**
* Field max length
* @access public
*/
public $length;
/**
* Is an autoincrement column
* @access public
*/
public $autoincrement;
/**
* Default field value
* @access public
*/
public $default;
/**
* Is not null
* @access public
*/
public $notNull;
/**
* Column comment
* @access public
*/
public $description;
/**
* Column level check constraint
* @access public
*/
public $check;
/**
* Character encoding e.g. ISO-8859-1 or UTF-8 etc.
* @access public
*/
public $charset;
/**
*
* @return
* @access public
*/
public function __toString( ) {
} // end of member function __toString
/**
*
* @return
* @access public
*/
public function __clone( ) {
} // end of member function __clone
/**
*
* @return bool
* @access public
*/
public function isValid( ) {
} // end of member function isValid
private $definition = array('name' => '',
'type' => '',
'unique' => false,
'primary' => false,
'notnull' => false,
'default' => null,
);
public function __construct(array $definition) {
foreach($this->definition as $key => $val) {
if(isset($definition[$key]))
$this->definition[$key] = $definition[$key];
}
}
public function getName() {
return $this->definition['name'];
}
public function getType() {
return $this->definition['type'];
}
public function isUnique() {
return $this->definition['unique'];
}
public function isPrimaryKey() {
return $this->definition['primary'];
}
public function defaultValue() {
return $this->definition['default'];
}
public function isNotNull() {
return $this->definition['notnull'];
}
} // end of Doctrine_Schema_Column

View File

@ -360,6 +360,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
return $rows;
}
/**
* fetchAll
*/
public function fetchAssoc($statement, $params = array()) {
if( ! $params)
$this->query($statement);
}
/**
* lastInsertId
*

View File

@ -0,0 +1,62 @@
<?php
class Doctrine_DataDict_Sqlite_TestCase extends Doctrine_UnitTestCase {
private $dict;
private $columns;
public function prepareData() { }
public function prepareTables() {
$this->dbh->query("CREATE TABLE test (col_null NULL,
col_int INTEGER NOT NULL,
col_real REAL,
col_text TEXT DEFAULT 'default' NOT NULL,
col_blob BLOB)");
$this->dict = new Doctrine_DataDict_Sqlite($this->dbh);
$this->columns = $this->dict->listTableColumns('test');
}
public function testListTables() {
$result = $this->dict->listTables();
}
public function testIntegerType() {
$this->assertEqual($this->columns['col_int']->isUnique(), false);
$this->assertEqual($this->columns['col_int']->isNotNull(), true);
$this->assertEqual($this->columns['col_int']->defaultValue(), null);
$this->assertEqual($this->columns['col_int']->isPrimaryKey(), false);
$this->assertEqual($this->columns['col_int']->getType(), 'INTEGER');
$this->assertEqual($this->columns['col_int']->getName(), 'col_int');
}
public function testNullType() {
$this->assertEqual($this->columns['col_null']->isUnique(), false);
$this->assertEqual($this->columns['col_null']->isNotNull(), false);
$this->assertEqual($this->columns['col_null']->defaultValue(), null);
$this->assertEqual($this->columns['col_null']->isPrimaryKey(), false);
$this->assertEqual($this->columns['col_null']->getType(), 'numeric');
$this->assertEqual($this->columns['col_null']->getName(), 'col_null');
}
public function testTextType() {
$this->assertEqual($this->columns['col_text']->isUnique(), false);
$this->assertEqual($this->columns['col_text']->isNotNull(), true);
$this->assertEqual($this->columns['col_text']->defaultValue(), 'default');
$this->assertEqual($this->columns['col_text']->isPrimaryKey(), false);
$this->assertEqual($this->columns['col_text']->getType(), 'TEXT');
$this->assertEqual($this->columns['col_text']->getName(), 'col_text');
}
public function testBlobType() {
$this->assertEqual($this->columns['col_blob']->isUnique(), false);
$this->assertEqual($this->columns['col_blob']->isNotNull(), false);
$this->assertEqual($this->columns['col_blob']->defaultValue(), null);
$this->assertEqual($this->columns['col_blob']->isPrimaryKey(), false);
$this->assertEqual($this->columns['col_blob']->getType(), 'BLOB');
$this->assertEqual($this->columns['col_blob']->getName(), 'col_blob');
}
public function testRealType() {
$this->assertEqual($this->columns['col_real']->isUnique(), false);
$this->assertEqual($this->columns['col_real']->isNotNull(), false);
$this->assertEqual($this->columns['col_real']->defaultValue(), null);
$this->assertEqual($this->columns['col_real']->isPrimaryKey(), false);
$this->assertEqual($this->columns['col_real']->getType(), 'REAL');
$this->assertEqual($this->columns['col_real']->getName(), 'col_real');
}
}
?>