cvs: pear /MDB2_Schema/MDB2 Schema.php

From: Date: Sat, 08 Dec 2007 20:30:15 +0000
Subject: cvs: pear /MDB2_Schema/MDB2 Schema.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-49671@lists.php.net to get a copy of this message
ifeghali Sat Dec 8 20:30:15 2007 UTC Modified files: /pear/MDB2_Schema/MDB2 Schema.php Log: - drop usage of listDatabases() (Bug #12636) - updateDatabase() doesn't check anymore whether updating database exists http://cvs.php.net/viewvc.cgi/pear/MDB2_Schema/MDB2/Schema.php?r1=1.116&r2=1.117&diff_format=u Index: pear/MDB2_Schema/MDB2/Schema.php diff -u pear/MDB2_Schema/MDB2/Schema.php:1.116 pear/MDB2_Schema/MDB2/Schema.php:1.117 --- pear/MDB2_Schema/MDB2/Schema.php:1.116 Mon Aug 20 03:15:41 2007 +++ pear/MDB2_Schema/MDB2/Schema.php Sat Dec 8 20:30:15 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Schema.php,v 1.116 2007/08/20 03:15:41 ifeghali Exp $ +// $Id: Schema.php,v 1.117 2007/12/08 20:30:15 ifeghali Exp $ // require_once 'MDB2.php'; @@ -1236,51 +1236,45 @@ } $create = (isset($database_definition['create']) && $database_definition['create']); $overwrite = (isset($database_definition['overwrite']) && $database_definition['overwrite']); - if ($create) { - $errorcodes = array(MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_NOT_CAPABLE); - $this->db->expectError($errorcodes); - /** - * - * We need to clean up database name before any query to prevent - * database driver from using a inexistent database - * - */ - $this->db->setDatabase(""); - $databases = $this->db->manager->listDatabases(); + /** + * + * We need to clean up database name before any query to prevent + * database driver from using a inexistent database + * + */ + $this->db->setDatabase(''); + + // Lower / Upper case the db name if the portability deems so. + if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $func = $this->db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'; + $db_name = $func($database_definition['name']); + } - // Lower / Upper case the db name if the portability deems so. - if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { - $func = $this->db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'; - $db_name = $func($database_definition['name']); + if ($create) { + if ($overwrite) { + $this->db->expectError(MDB2_ERROR_CANNOT_DROP); + $result = $this->db->manager->dropDatabase($database_definition['name']); + $this->db->popExpect(); + if (PEAR::isError($result) && !MDB2::isError($result, MDB2_ERROR_CANNOT_DROP)) { + return $result; + } + $this->db->debug('Overwritting database: '.$database_definition['name'], __FUNCTION__); } + $this->db->expectError(MDB2_ERROR_ALREADY_EXISTS); + $result = $this->db->manager->createDatabase($database_definition['name']); $this->db->popExpect(); - if (PEAR::isError($databases)) { - if (!MDB2::isError($databases, $errorcodes)) { - return $databases; - } - } elseif (is_array($databases) && isset($db_name) && in_array($db_name, $databases)) { - if (!$overwrite) { + if (PEAR::isError($result)) { + if (MDB2::isError($result, MDB2_ERROR_ALREADY_EXISTS)) { $this->db->debug('Database already exists: ' . $database_definition['name'], __FUNCTION__); $create = false; } else { - $result = $this->db->manager->dropDatabase($database_definition['name']); - if (PEAR::isError($result)) { - return $result; - } - $this->db->debug('Overwritting database: '.$database_definition['name'], __FUNCTION__); - } - } - if ($create) { - $this->db->expectError(MDB2_ERROR_ALREADY_EXISTS); - $result = $this->db->manager->createDatabase($database_definition['name']); - $this->db->popExpect(); - if (PEAR::isError($result) && !MDB2::isError($result, MDB2_ERROR_ALREADY_EXISTS)) { return $result; } } } + $previous_database_name = $this->db->setDatabase($database_definition['name']); if (($support_transactions = $this->db->supports('transactions')) && PEAR::isError($result = $this->db->beginNestedTransaction()) @@ -2435,21 +2429,6 @@ } if ($previous_definition) { - $errorcodes = array(MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_NOT_CAPABLE); - $this->db->expectError($errorcodes); - $databases = $this->db->manager->listDatabases(); - $this->db->popExpect(); - if (PEAR::isError($databases)) { - if (!MDB2::isError($databases, $errorcodes)) { - return $databases; - } - } elseif (!is_array($databases) || - !in_array($current_definition['name'], $databases) - ) { - return $this->raiseError(MDB2_SCHEMA_ERROR, null, null, - 'database to update does not exist: '.$current_definition['name']); - } - $changes = $this->compareDefinitions($current_definition, $previous_definition); if (PEAR::isError($changes)) { return $changes;

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