. */ Doctrine::autoload('Doctrine_Export'); /** * Doctrine_Export_Sqlite * * @package Doctrine * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.com * @since 1.0 * @version $Revision$ */ class Doctrine_Export_Sqlite extends Doctrine_Export { /** * Get the stucture of a field into an array * * @param string $table name of the table on which the index is to be created * @param string $name name of the index to be created * @param array $definition associative array that defines properties of the index to be created. * Currently, only one property named FIELDS is supported. This property * is also an associative with the names of the index fields as array * indexes. Each entry of this array is set to another type of associative * array that specifies properties of the index that are specific to * each field. * * Currently, only the sorting property is supported. It should be used * to define the sorting direction of the index. It may be set to either * ascending or descending. * * Not all DBMS support index sorting direction configuration. The DBMS * drivers of those that do not support it ignore this property. Use the * function support() to determine whether the DBMS driver can manage indexes. * Example * array( * 'fields' => array( * 'user_name' => array( * 'sorting' => 'ascending' * ), * 'last_login' => array() * ) * ) * @throws PDOException * @return void */ public function createIndex($table, $name, array $definition) { $table = $this->conn->quoteIdentifier($table, true); $name = $this->conn->getIndexName($name); $query = 'CREATE INDEX ' . $name . ' ON ' . $table; $fields = array(); foreach ($definition['fields'] as $fieldName => $field) { $fieldString = $fieldName; if (isset($field['sorting'])) { switch ($field['sorting']) { case 'ascending': $fieldString .= ' ASC'; break; case 'descending': $fieldString .= ' DESC'; break; } } $fields[] = $fieldString; } $query .= ' ('.implode(', ', $fields) . ')'; return $this->conn->exec($query); } }