cvs: pear /MDB2/MDB2/Driver/Manager mysql.php mysqli.php
| From: | Lukas Smith | Date: | Sat, 29 Oct 2005 11:26:25 +0000 |
| Subject: | cvs: pear /MDB2/MDB2/Driver/Manager mysql.php mysqli.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35947@lists.php.net to get a copy of this message | ||
lsmith Sat Oct 29 07:26:25 2005 EDT
Modified files:
/pear/MDB2/MDB2/Driver/Manager mysql.php mysqli.php
Log:
- support column length in create index (mysql only feature, but a nice touch, emulating it with
substring is not feasible though)
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/mysql.php?r1=1.50&r2=1.51&ty=u Index: pear/MDB2/MDB2/Driver/Manager/mysql.php diff -u pear/MDB2/MDB2/Driver/Manager/mysql.php:1.50 pear/MDB2/MDB2/Driver/Manager/mysql.php:1.51 --- pear/MDB2/MDB2/Driver/Manager/mysql.php:1.50 Fri Oct 21 18:48:22 2005 +++ pear/MDB2/MDB2/Driver/Manager/mysql.php Sat Oct 29 07:26:23 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.50 2005/10/21 22:48:22 dufuz Exp $ +// $Id: mysql.php,v 1.51 2005/10/29 11:26:23 lsmith Exp $ // require_once 'MDB2/Driver/Manager/Common.php'; @@ -227,23 +227,19 @@ return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, 'createTable: no valid table name specified'); } - if (empty($fields)) { return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, 'createTable: no fields specified for table "'.$name.'"'); } - $verify = $this->_verifyTableType($db->options['default_table_type']); if (PEAR::isError($verify)) { return $verify; } - $query_fields = $this->getFieldDeclarationList($fields); if (PEAR::isError($query_fields)) { return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, 'createTable: '.$this->getUserinfo()); } - $name = $db->quoteIdentifier($name); $query = "CREATE TABLE $name ($query_fields)".(strlen($db->options['default_table_type']) ? ' TYPE='.$db->options['default_table_type'] : ''); @@ -538,6 +534,69 @@ } // }}} + // {{{ createIndex() + + /** + * get the stucture of a field into an array + * + * @author Leoncx + * @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 supports() to determine whether the DBMS driver can manage indexes. + * + * Example + * array( + * 'fields' => array( + * 'user_name' => array( + * 'sorting' => 'ascending' + * 'length' => 10 + * ), + * 'last_login' => array() + * ) + * ) + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function createIndex($table, $name, $definition) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + $table = $db->quoteIdentifier($table); + $name = $db->quoteIdentifier($name); + $query = 'CREATE'; + if (array_key_exists('unique', $definition) && $definition['unique']) { + $query.= ' UNIQUE'; + } + $query .= " INDEX $name ON $table"; + $fields = array(); + foreach ($definition['fields'] as $field => $fieldinfo) { + if (array_key_exists('length', $fieldinfo)) { + $fields[] = $db->quoteIdentifier($field) . '(' . $fieldinfo['length'] . ')'; + } else { + $fields[] = $db->quoteIdentifier($field); + } + } + $query .= ' ('. implode(', ', $fields) . ')'; + return $db->query($query); + } + + // }}} // {{{ dropIndex() /** @@ -834,4 +893,4 @@ // }}} } -?> \ No newline at end of file +?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/mysqli.php?r1=1.36&r2=1.37&ty=u Index: pear/MDB2/MDB2/Driver/Manager/mysqli.php diff -u pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.36 pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.37 --- pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.36 Sun Oct 16 17:47:56 2005 +++ pear/MDB2/MDB2/Driver/Manager/mysqli.php Sat Oct 29 07:26:23 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.36 2005/10/16 21:47:56 lsmith Exp $ +// $Id: mysqli.php,v 1.37 2005/10/29 11:26:23 lsmith Exp $ // require_once 'MDB2/Driver/Manager/Common.php'; @@ -534,6 +534,69 @@ } // }}} + // {{{ createIndex() + + /** + * get the stucture of a field into an array + * + * @author Leoncx + * @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 supports() to determine whether the DBMS driver can manage indexes. + * + * Example + * array( + * 'fields' => array( + * 'user_name' => array( + * 'sorting' => 'ascending' + * 'length' => 10 + * ), + * 'last_login' => array() + * ) + * ) + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function createIndex($table, $name, $definition) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + $table = $db->quoteIdentifier($table); + $name = $db->quoteIdentifier($name); + $query = 'CREATE'; + if (array_key_exists('unique', $definition) && $definition['unique']) { + $query.= ' UNIQUE'; + } + $query .= " INDEX $name ON $table"; + $fields = array(); + foreach ($definition['fields'] as $field => $fieldinfo) { + if (array_key_exists('length', $fieldinfo)) { + $fields[] = $db->quoteIdentifier($field) . '(' . $fieldinfo['length'] . ')'; + } else { + $fields[] = $db->quoteIdentifier($field); + } + } + $query .= ' ('. implode(', ', $fields) . ')'; + return $db->query($query); + } + + // }}} // {{{ dropIndex() /** @@ -830,4 +893,4 @@ // }}} } -?> \ No newline at end of file +?>
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/mysql.php?r1=1.50&r2=1.51&ty=u Index: pear/MDB2/MDB2/Driver/Manager/mysql.php diff -u pear/MDB2/MDB2/Driver/Manager/mysql.php:1.50 pear/MDB2/MDB2/Driver/Manager/mysql.php:1.51 --- pear/MDB2/MDB2/Driver/Manager/mysql.php:1.50 Fri Oct 21 18:48:22 2005 +++ pear/MDB2/MDB2/Driver/Manager/mysql.php Sat Oct 29 07:26:23 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.50 2005/10/21 22:48:22 dufuz Exp $ +// $Id: mysql.php,v 1.51 2005/10/29 11:26:23 lsmith Exp $ // require_once 'MDB2/Driver/Manager/Common.php'; @@ -227,23 +227,19 @@ return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, 'createTable: no valid table name specified'); } - if (empty($fields)) { return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, 'createTable: no fields specified for table "'.$name.'"'); } - $verify = $this->_verifyTableType($db->options['default_table_type']); if (PEAR::isError($verify)) { return $verify; } - $query_fields = $this->getFieldDeclarationList($fields); if (PEAR::isError($query_fields)) { return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, 'createTable: '.$this->getUserinfo()); } - $name = $db->quoteIdentifier($name); $query = "CREATE TABLE $name ($query_fields)".(strlen($db->options['default_table_type']) ? ' TYPE='.$db->options['default_table_type'] : ''); @@ -538,6 +534,69 @@ } // }}} + // {{{ createIndex() + + /** + * get the stucture of a field into an array + * + * @author Leoncx + * @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 supports() to determine whether the DBMS driver can manage indexes. + * + * Example + * array( + * 'fields' => array( + * 'user_name' => array( + * 'sorting' => 'ascending' + * 'length' => 10 + * ), + * 'last_login' => array() + * ) + * ) + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function createIndex($table, $name, $definition) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + $table = $db->quoteIdentifier($table); + $name = $db->quoteIdentifier($name); + $query = 'CREATE'; + if (array_key_exists('unique', $definition) && $definition['unique']) { + $query.= ' UNIQUE'; + } + $query .= " INDEX $name ON $table"; + $fields = array(); + foreach ($definition['fields'] as $field => $fieldinfo) { + if (array_key_exists('length', $fieldinfo)) { + $fields[] = $db->quoteIdentifier($field) . '(' . $fieldinfo['length'] . ')'; + } else { + $fields[] = $db->quoteIdentifier($field); + } + } + $query .= ' ('. implode(', ', $fields) . ')'; + return $db->query($query); + } + + // }}} // {{{ dropIndex() /** @@ -834,4 +893,4 @@ // }}} } -?> \ No newline at end of file +?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/mysqli.php?r1=1.36&r2=1.37&ty=u Index: pear/MDB2/MDB2/Driver/Manager/mysqli.php diff -u pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.36 pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.37 --- pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.36 Sun Oct 16 17:47:56 2005 +++ pear/MDB2/MDB2/Driver/Manager/mysqli.php Sat Oct 29 07:26:23 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.36 2005/10/16 21:47:56 lsmith Exp $ +// $Id: mysqli.php,v 1.37 2005/10/29 11:26:23 lsmith Exp $ // require_once 'MDB2/Driver/Manager/Common.php'; @@ -534,6 +534,69 @@ } // }}} + // {{{ createIndex() + + /** + * get the stucture of a field into an array + * + * @author Leoncx + * @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 supports() to determine whether the DBMS driver can manage indexes. + * + * Example + * array( + * 'fields' => array( + * 'user_name' => array( + * 'sorting' => 'ascending' + * 'length' => 10 + * ), + * 'last_login' => array() + * ) + * ) + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function createIndex($table, $name, $definition) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + $table = $db->quoteIdentifier($table); + $name = $db->quoteIdentifier($name); + $query = 'CREATE'; + if (array_key_exists('unique', $definition) && $definition['unique']) { + $query.= ' UNIQUE'; + } + $query .= " INDEX $name ON $table"; + $fields = array(); + foreach ($definition['fields'] as $field => $fieldinfo) { + if (array_key_exists('length', $fieldinfo)) { + $fields[] = $db->quoteIdentifier($field) . '(' . $fieldinfo['length'] . ')'; + } else { + $fields[] = $db->quoteIdentifier($field); + } + } + $query .= ' ('. implode(', ', $fields) . ')'; + return $db->query($query); + } + + // }}} // {{{ dropIndex() /** @@ -830,4 +893,4 @@ // }}} } -?> \ No newline at end of file +?>