cvs: pear /MDB2/MDB2/Driver/Manager sqlite.php

From: Date: Thu, 13 Oct 2005 14:46:50 +0000
Subject: cvs: pear /MDB2/MDB2/Driver/Manager sqlite.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35499@lists.php.net to get a copy of this message
lsmith Thu Oct 13 10:46:50 2005 EDT Modified files: /pear/MDB2/MDB2/Driver/Manager sqlite.php Log: - primary key not supported in createIndex() http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/sqlite.php?r1=1.25&r2=1.26&ty=u Index: pear/MDB2/MDB2/Driver/Manager/sqlite.php diff -u pear/MDB2/MDB2/Driver/Manager/sqlite.php:1.25 pear/MDB2/MDB2/Driver/Manager/sqlite.php:1.26 --- pear/MDB2/MDB2/Driver/Manager/sqlite.php:1.25 Wed Oct 12 06:50:02 2005 +++ pear/MDB2/MDB2/Driver/Manager/sqlite.php Thu Oct 13 10:46:49 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.25 2005/10/12 10:50:02 lsmith Exp $ +// $Id: sqlite.php,v 1.26 2005/10/13 14:46:49 lsmith Exp $ // require_once 'MDB2/Driver/Manager/Common.php'; @@ -262,10 +262,35 @@ return $db; } - $query = 'CREATE '.(array_key_exists('unique', $definition) ? 'UNIQUE' : '')." INDEX $name ON $table ("; - $query.= implode(', ', array_keys($definition['fields'])); - $query.= ')'; + if (strtolower($name) == 'primary') { + return $db->raiseError('Index may not be named primary'); + } + + $query = 'CREATE'; + if (array_key_exists('primary', $definition) && $definition['primary']) { + return $db->raiseError('Primary Key creation must be done during table creation'); + } elseif (array_key_exists('unique', $definition) && $definition['unique']) { + $query.= ' UNIQUE'; + } + $query .= " INDEX $name ON $table ("; + $fields = array(); + foreach ($definition['fields'] as $field_name => $field) { + $field_string = $field_name; + if (array_key_exists('sorting', $field)) { + switch ($field['sorting']) { + case 'ascending': + $field_string.= ' ASC'; + break; + case 'descending': + $field_string.= ' DESC'; + break; + } + } + $fields[] = $field_string; + } + $query .= implode(', ', $fields) . ')'; return $db->query($query); + } // }}}

« previous php.pear.cvs (#35499) next »