Doctrine 1.2.4
Doctrine_Import_Sqlite Class Reference

Inherits Doctrine_Import.

Public Member Functions

 databaseExists ($database)
 
 functionExists ($function)
 
 getConnection ()
 
 getModuleName ()
 
 importSchema ($directory, array $connections=array(), array $options=array())
 
 listDatabases ()
 
 listFunctions ()
 
 listSequences ($database=null)
 
 listTableColumns ($table)
 
 listTableConstraints ($table)
 
 listTableIndexes ($table)
 
 listTableRelations ($table)
 
 listTables ($database=null)
 
 listTableTriggers ($table)
 
 listTableViews ($table)
 
 listTriggers ($database=null)
 
 listUsers ()
 
 listViews ($database=null)
 
 sequenceExists ($sequence, $database=null)
 
 tableColumnExists ($column, $table)
 
 tableConstraintExists ($constraint, $table)
 
 tableExists ($table, $database=null)
 
 tableIndexExists ($index, $table)
 
 tableTriggerExists ($trigger, $table)
 
 tableViewExists ($view, $table)
 
 triggerExists ($trigger, $database=null)
 
 userExists ($user)
 
 viewExists ($view, $database=null)
 

Detailed Description

Definition at line 32 of file Sqlite.php.

Member Function Documentation

Doctrine_Import::databaseExists (   $database)
inherited

checks if a database exists

Parameters
string$database
Returns
boolean

Definition at line 220 of file Import.php.

{
return in_array($database, $this->listDatabases());
}
Doctrine_Import::functionExists (   $function)
inherited

checks if a function exists

Parameters
string$function
Returns
boolean

Definition at line 231 of file Import.php.

{
return in_array($function, $this->listFunctions());
}
Doctrine_Connection_Module::getConnection ( )
inherited

getConnection returns the connection object this module uses

Returns
Doctrine_Connection

Definition at line 68 of file Module.php.

{
return $this->conn;
}
Doctrine_Connection_Module::getModuleName ( )
inherited

getModuleName returns the name of this module

Returns
string the name of this module

Definition at line 79 of file Module.php.

{
return $this->moduleName;
}
Doctrine_Import::importSchema (   $directory,
array  $connections = array(),
array  $options = array() 
)
inherited

importSchema

method for importing existing schema to Doctrine_Record classes

Parameters
string$directory
array$connectionsArray of connection names to generate models for
Returns
array the names of the imported classes

Definition at line 364 of file Import.php.

{
$classes = array();
foreach ($manager as $name => $connection) {
// Limit the databases to the ones specified by $connections.
// Check only happens if array is not empty
if ( ! empty($connections) && ! in_array($name, $connections)) {
continue;
}
$builder = new Doctrine_Import_Builder();
$builder->setTargetPath($directory);
$builder->setOptions($options);
$definitions = array();
foreach ($connection->import->listTables() as $table) {
$definition = array();
$definition['tableName'] = $table;
$definition['className'] = Doctrine_Inflector::classify(Doctrine_Inflector::tableize($table));
$definition['columns'] = $connection->import->listTableColumns($table);
$definition['connection'] = $connection->getName();
$definition['connectionClassName'] = $definition['className'];
try {
$definition['relations'] = array();
$relations = $connection->import->listTableRelations($table);
$relClasses = array();
foreach ($relations as $relation) {
$table = $relation['table'];
if (in_array($class, $relClasses)) {
$alias = $class . '_' . (count($relClasses) + 1);
} else {
$alias = $class;
}
$relClasses[] = $class;
$definition['relations'][$alias] = array(
'alias' => $alias,
'class' => $class,
'local' => $relation['local'],
'foreign' => $relation['foreign']
);
}
} catch (Exception $e) {}
$definitions[strtolower($definition['className'])] = $definition;
$classes[] = $definition['className'];
}
// Build opposite end of relationships
foreach ($definitions as $definition) {
$className = $definition['className'];
$relClasses = array();
foreach ($definition['relations'] as $alias => $relation) {
if (in_array($relation['class'], $relClasses) || isset($definitions[$relation['class']]['relations'][$className])) {
$alias = $className . '_' . (count($relClasses) + 1);
} else {
$alias = $className;
}
$relClasses[] = $relation['class'];
$definitions[strtolower($relation['class'])]['relations'][$alias] = array(
'alias' => $alias,
'class' => $className,
'local' => $relation['foreign'],
'foreign' => $relation['local']
);
}
}
// Build records
foreach ($definitions as $definition) {
$builder->buildRecord($definition);
}
}
return $classes;
}
Doctrine_Import_Sqlite::listDatabases ( )

lists all databases

Returns
array

Definition at line 39 of file Sqlite.php.

{
}
Doctrine_Import_Sqlite::listFunctions ( )

lists all availible database functions

Returns
array

Definition at line 49 of file Sqlite.php.

{
}
Doctrine_Import_Sqlite::listSequences (   $database = null)

lists all database sequences

Parameters
string | null$database
Returns
array

Definition at line 71 of file Sqlite.php.

{
$query = "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
$tableNames = $this->conn->fetchColumn($query);
$result = array();
foreach ($tableNames as $tableName) {
if ($sqn = $this->conn->fixSequenceName($tableName, true)) {
$result[] = $sqn;
}
}
if ($this->conn->getAttribute(Doctrine_Core::ATTR_FIELD_CASE) && ($this->conn->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_FIX_CASE)) {
$result = array_map(($this->conn->getAttribute(Doctrine_Core::ATTR_FIELD_CASE) == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
Doctrine_Import_Sqlite::listTableColumns (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 130 of file Sqlite.php.

{
$sql = 'PRAGMA table_info(' . $table . ')';
$result = $this->conn->fetchAll($sql);
$description = array();
$columns = array();
foreach ($result as $key => $val) {
$val = array_change_key_case($val, CASE_LOWER);
$decl = $this->conn->dataDict->getPortableDeclaration($val);
$description = array(
'name' => $val['name'],
'ntype' => $val['type'],
'type' => $decl['type'][0],
'alltypes' => $decl['type'],
'notnull' => (bool) $val['notnull'],
'default' => $val['dflt_value'],
'primary' => (bool) $val['pk'],
'length' => null,
'scale' => null,
'precision' => null,
'unsigned' => null,
'autoincrement' => (bool) ($val['pk'] == 1 && $decl['type'][0] == 'integer'),
);
$columns[$val['name']] = $description;
}
return $columns;
}
Doctrine_Import_Sqlite::listTableConstraints (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 94 of file Sqlite.php.

{
$table = $this->conn->quote($table, 'text');
$query = "SELECT sql FROM sqlite_master WHERE type='index' AND ";
if ($this->conn->getAttribute(Doctrine_Core::ATTR_FIELD_CASE) && ($this->conn->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_FIX_CASE)) {
$query .= 'LOWER(tbl_name) = ' . strtolower($table);
} else {
$query .= 'tbl_name = ' . $table;
}
$query .= ' AND sql NOT NULL ORDER BY name';
$indexes = $this->conn->fetchColumn($query);
$result = array();
foreach ($indexes as $sql) {
if (preg_match("/^create unique index ([^ ]+) on /i", $sql, $tmp)) {
$index = $this->conn->formatter->fixIndexName($tmp[1]);
if ( ! empty($index)) {
$result[$index] = true;
}
}
}
if ($this->conn->getAttribute(Doctrine_Core::ATTR_FIELD_CASE) && ($this->conn->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_FIX_CASE)) {
$result = array_change_key_case($result, $this->conn->getAttribute(Doctrine_Core::ATTR_FIELD_CASE));
}
return array_keys($result);
}
Doctrine_Import_Sqlite::listTableIndexes (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 166 of file Sqlite.php.

{
$sql = 'PRAGMA index_list(' . $table . ')';
return $this->conn->fetchColumn($sql);
}
Doctrine_Import::listTableRelations (   $table)
inherited

lists table relations

Expects an array of this format to be returned with all the relationships in it where the key is the name of the foreign table, and the value is an array containing the local and foreign column name

Array ( [groups] => Array ( [local] => group_id [foreign] => id ) )

Parameters
string$tabledatabase table name
Returns
array

Definition at line 125 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import_Sqlite::listTables (   $database = null)

lists tables

Parameters
string | null$database
Returns
array

Definition at line 177 of file Sqlite.php.

{
$sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND name != 'sqlite_sequence' "
. "UNION ALL SELECT name FROM sqlite_temp_master "
. "WHERE type = 'table' ORDER BY name";
return $this->conn->fetchColumn($sql);
}
Doctrine_Import_Sqlite::listTableTriggers (   $table)

lists table triggers

Parameters
string$tabledatabase table name
Returns
array

Definition at line 192 of file Sqlite.php.

{
}
Doctrine_Import_Sqlite::listTableViews (   $table)

lists table views

Parameters
string$tabledatabase table name
Returns
array

Definition at line 203 of file Sqlite.php.

{
$query = "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL";
$views = $db->fetchAll($query);
$result = array();
foreach ($views as $row) {
if (preg_match("/^create view .* \bfrom\b\s+\b{$table}\b /i", $row['sql'])) {
if ( ! empty($row['name'])) {
$result[$row['name']] = true;
}
}
}
return $result;
}
Doctrine_Import_Sqlite::listTriggers (   $database = null)

lists all database triggers

Parameters
string | null$database
Returns
array

Definition at line 60 of file Sqlite.php.

{
}
Doctrine_Import_Sqlite::listUsers ( )

lists database users

Returns
array

Definition at line 224 of file Sqlite.php.

{
}
Doctrine_Import_Sqlite::listViews (   $database = null)

lists database views

Parameters
string | null$database
Returns
array

Definition at line 235 of file Sqlite.php.

{
$query = "SELECT name FROM sqlite_master WHERE type='view' AND sql NOT NULL";
return $this->conn->fetchColumn($query);
}
Doctrine_Import::sequenceExists (   $sequence,
  $database = null 
)
inherited

checks if a sequence exists

Parameters
string$sequence
string | null$database
Returns
boolean

Definition at line 255 of file Import.php.

{
return in_array($sequence, $this->listSequences($database));
}
Doctrine_Import::tableColumnExists (   $column,
  $table 
)
inherited

checks if a table column exists

Parameters
string$column
string$tabledatabase table name
Returns
boolean

Definition at line 279 of file Import.php.

{
return in_array($column, $this->listTableColumns($table));
}
Doctrine_Import::tableConstraintExists (   $constraint,
  $table 
)
inherited

checks if a table constraint exists

Parameters
string$constraint
string$tabledatabase table name
Returns
boolean

Definition at line 267 of file Import.php.

{
return in_array($constraint, $this->listTableConstraints($table));
}
Doctrine_Import::tableExists (   $table,
  $database = null 
)
inherited

checks if a table exists

Parameters
string$table
string | null$database
Returns
boolean

Definition at line 303 of file Import.php.

{
return in_array($table, $this->listTables($database));
}
Doctrine_Import::tableIndexExists (   $index,
  $table 
)
inherited

checks if a table index exists

Parameters
string$index
string$tabledatabase table name
Returns
boolean

Definition at line 291 of file Import.php.

{
return in_array($index, $this->listTableIndexes($table));
}
Doctrine_Import::tableTriggerExists (   $trigger,
  $table 
)
inherited

checks if a table trigger exists

Parameters
string$trigger
string$tabledatabase table name
Returns
boolean

Definition at line 315 of file Import.php.

{
return in_array($trigger, $this->listTableTriggers($table));
}
Doctrine_Import::tableViewExists (   $view,
  $table 
)
inherited

checks if a table view exists

Parameters
string$view
string$tabledatabase table name
Returns
boolean

Definition at line 327 of file Import.php.

{
return in_array($view, $this->listTableViews($table));
}
Doctrine_Import::triggerExists (   $trigger,
  $database = null 
)
inherited

checks if a trigger exists

Parameters
string$trigger
string | null$database
Returns
boolean

Definition at line 243 of file Import.php.

{
return in_array($trigger, $this->listTriggers($database));
}
Doctrine_Import::userExists (   $user)
inherited

checks if a user exists

Parameters
string$user
Returns
boolean

Definition at line 338 of file Import.php.

{
return in_array($user, $this->listUsers());
}
Doctrine_Import::viewExists (   $view,
  $database = null 
)
inherited

checks if a view exists

Parameters
string$view
string | null$database
Returns
boolean

Definition at line 350 of file Import.php.

{
return in_array($view, $this->listViews($database));
}

The documentation for this class was generated from the following file: