cvs: pear /MDB2/MDB2/Driver/Manager mysql.php mysqli.php

From: Date: Fri, 14 Oct 2005 16:33:36 +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-35537@lists.php.net to get a copy of this message
lsmith Fri Oct 14 12:33:36 2005 EDT Modified files: /pear/MDB2/MDB2/Driver/Manager mysql.php mysqli.php Log: - use getConnection() - split index and contraint handling

http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/mysql.php?r1=1.40&r2=1.41&ty=u Index: pear/MDB2/MDB2/Driver/Manager/mysql.php diff -u pear/MDB2/MDB2/Driver/Manager/mysql.php:1.40 pear/MDB2/MDB2/Driver/Manager/mysql.php:1.41 --- pear/MDB2/MDB2/Driver/Manager/mysql.php:1.40 Fri Oct 14 05:40:28 2005 +++ pear/MDB2/MDB2/Driver/Manager/mysql.php Fri Oct 14 12:33:36 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.40 2005/10/14 09:40:28 lsmith Exp $ +// $Id: mysql.php,v 1.41 2005/10/14 16:33:36 lsmith Exp $ // require_once 'MDB2/Driver/Manager/Common.php'; @@ -99,8 +99,12 @@ return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, $table_type.' is not a supported table type'); } + $connection = $db->getConnection(); + if (PEAR::isError($connection)) { + return $connection; + } if (isset($this->verified_table_types[$table_type]) - && $this->verified_table_types[$table_type] == $db->connection + && $this->verified_table_types[$table_type] == $connection ) { return MDB2_OK; } @@ -114,7 +118,7 @@ if (is_array($has)) { $not_supported = true; if ($has[1] == 'YES') { - $this->verified_table_types[$table_type] = $db->connection; + $this->verified_table_types[$table_type] = $connection; return MDB2_OK; } } @@ -526,47 +530,98 @@ } // }}} - // {{{ createIndex() + // {{{ dropIndex() /** - * get the stucture of a field into an array + * drop existing index * - * @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. + * @param string $table name of table that should be used in method + * @param string $name name of the index to be dropped + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function dropIndex($table, $name) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + return $db->query("DROP INDEX $name ON $table"); + } + + // }}} + // {{{ listTableIndexes() + + /** + * list all indexes in a table + * + * @param string $table name of table that should be used in method + * @return mixed data array on success, a MDB2 error on failure + * @access public + */ + function listTableIndexes($table) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + $key_name = 'Key_name'; + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + if ($db->options['field_case'] == CASE_LOWER) { + $key_name = strtolower($key_name); + } else { + $key_name = strtoupper($key_name); + } + } + + $query = "SHOW INDEX FROM $table"; + $indexes_all = $db->queryCol($query, 'text', $key_name); + if (PEAR::isError($indexes_all)) { + return $indexes_all; + } + + $result = array_unique($indexes_all); + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result); + } + return $result; + } + + // }}} + // {{{ createConstraint() + + /** + * create a constraint on a table + * + * @param string $table name of the table on which the constraint is to be created + * @param string $name name of the constraint to be created + * @param array $definition associative array that defines properties of the constraint 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 + * is also an associative with the names of the constraint fields as array + * constraints. Each entry of this array is set to another type of associative + * array that specifies properties of the constraint 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' - * ), + * 'user_name' => array(), * 'last_login' => array() * ) * ) * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ - function createIndex($table, $name, $definition) + function createConstraint($table, $name, $definition) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } + $type = ''; if (array_key_exists('primary', $definition) && $definition['primary']) { if (strtolower($name) != 'primary') { return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, @@ -574,10 +629,6 @@ } $type = 'PRIMARY'; $name = 'KEY'; - } elseif (array_key_exists('unique', $definition) && $definition['unique']) { - $type = 'UNIQUE'; - } else { - $type = 'INDEX'; } $query = "ALTER TABLE $table ADD $type $name ("; @@ -588,17 +639,17 @@ } // }}} - // {{{ dropIndex() + // {{{ dropConstraint() /** - * drop existing index + * drop existing constraint * * @param string $table name of table that should be used in method - * @param string $name name of the index to be dropped + * @param string $name name of the constraint to be dropped * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ - function dropIndex($table, $name) + function dropConstraint($table, $name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -614,16 +665,16 @@ } // }}} - // {{{ listTableIndexes() + // {{{ listTableConstraints() /** - * list all indexes in a table + * list all sonstraints in a table * * @param string $table name of table that should be used in method * @return mixed data array on success, a MDB2 error on failure * @access public */ - function listTableIndexes($table) + function listTableConstraints($table) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -756,9 +807,6 @@ $result[] = $sqn; } } - if (PEAR::isError($result)) { - return $result; - } if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result); } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/mysqli.php?r1=1.27&r2=1.28&ty=u Index: pear/MDB2/MDB2/Driver/Manager/mysqli.php diff -u pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.27 pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.28 --- pear/MDB2/MDB2/Driver/Manager/mysqli.php:1.27 Fri Oct 14 05:40:29 2005 +++ pear/MDB2/MDB2/Driver/Manager/mysqli.php Fri Oct 14 12:33:36 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.27 2005/10/14 09:40:29 lsmith Exp $ +// $Id: mysqli.php,v 1.28 2005/10/14 16:33:36 lsmith Exp $ // require_once 'MDB2/Driver/Manager/Common.php'; @@ -99,8 +99,12 @@ return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, $table_type.' is not a supported table type'); } + $connection = $db->getConnection(); + if (PEAR::isError($connection)) { + return $connection; + } if (isset($this->verified_table_types[$table_type]) - && $this->verified_table_types[$table_type] == $db->connection + && $this->verified_table_types[$table_type] == $connection ) { return MDB2_OK; } @@ -114,7 +118,7 @@ if (is_array($has)) { $not_supported = true; if ($has[1] == 'YES') { - $this->verified_table_types[$table_type] = $db->connection; + $this->verified_table_types[$table_type] = $connection; return MDB2_OK; } } @@ -526,47 +530,98 @@ } // }}} - // {{{ createIndex() + // {{{ dropIndex() + + /** + * drop existing index + * + * @param string $table name of table that should be used in method + * @param string $name name of the index to be dropped + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function dropIndex($table, $name) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + return $db->query("DROP INDEX $name ON $table"); + } + + // }}} + // {{{ listTableIndexes() + + /** + * list all indexes in a table + * + * @param string $table name of table that should be used in method + * @return mixed data array on success, a MDB2 error on failure + * @access public + */ + function listTableIndexes($table) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + $key_name = 'Key_name'; + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + if ($db->options['field_case'] == CASE_LOWER) { + $key_name = strtolower($key_name); + } else { + $key_name = strtoupper($key_name); + } + } + + $query = "SHOW INDEX FROM $table"; + $indexes_all = $db->queryCol($query, 'text', $key_name); + if (PEAR::isError($indexes_all)) { + return $indexes_all; + } + + $result = array_unique($indexes_all); + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result); + } + return $result; + } + + // }}} + // {{{ createConstraint() /** - * get the stucture of a field into an array + * create a constraint on a table * - * @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. + * @param string $table name of the table on which the constraint is to be created + * @param string $name name of the constraint to be created + * @param array $definition associative array that defines properties of the constraint 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 + * is also an associative with the names of the constraint fields as array + * constraints. Each entry of this array is set to another type of associative + * array that specifies properties of the constraint 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' - * ), + * 'user_name' => array(), * 'last_login' => array() * ) * ) * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ - function createIndex($table, $name, $definition) + function createConstraint($table, $name, $definition) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } + $type = ''; if (array_key_exists('primary', $definition) && $definition['primary']) { if (strtolower($name) != 'primary') { return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, @@ -574,10 +629,6 @@ } $type = 'PRIMARY'; $name = 'KEY'; - } elseif (array_key_exists('unique', $definition) && $definition['unique']) { - $type = 'UNIQUE'; - } else { - $type = 'INDEX'; } $query = "ALTER TABLE $table ADD $type $name ("; @@ -588,17 +639,17 @@ } // }}} - // {{{ dropIndex() + // {{{ dropConstraint() /** - * drop existing index + * drop existing constraint * * @param string $table name of table that should be used in method - * @param string $name name of the index to be dropped + * @param string $name name of the constraint to be dropped * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ - function dropIndex($table, $name) + function dropConstraint($table, $name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -614,16 +665,16 @@ } // }}} - // {{{ listTableIndexes() + // {{{ listTableConstraints() /** - * list all indexes in a table + * list all sonstraints in a table * * @param string $table name of table that should be used in method * @return mixed data array on success, a MDB2 error on failure * @access public */ - function listTableIndexes($table) + function listTableConstraints($table) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) {
« previous php.pear.cvs (#35537) next »