Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.8.6

Request #12636 MDB2_Schema without need "SHOW Database privilege"!
Submitted: 2007-12-07 08:56 UTC
From: afz Assigned: ifeghali
Status: Closed Package: MDB2_Schema (version CVS)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 46 + 33 = ?

 
 [2007-12-07 08:56 UTC] afz (Ali Fazelzade)
Description: ------------ in create and update databses MDB2_Schema need use listDatabases function that require more permission to execute. this patch fix this problem.

Comments

 [2007-12-07 09:04 UTC] afz (Ali Fazelzade)
i can't upload patch file!!!! Index: Schema.php =================================================================== RCS file: /repository/pear/MDB2_Schema/MDB2/Schema.php,v retrieving revision 1.116 diff -u -r1.116 Schema.php --- Schema.php 20 Aug 2007 03:15:41 -0000 1.116 +++ Schema.php 8 Dec 2007 08:47:39 -0000 @@ -1236,51 +1236,43 @@ } $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(); - - // 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']); - } - - $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) { - $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__); - } + + $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(""); + + // 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']); + } + + $this->db->popExpect(); + + if ($overwrite) { + $result = $this->db->manager->dropDatabase($database_definition['name']); + if (PEAR::isError($result) && !MDB2::isError($result, MDB2_ERROR_CANNOT_DROP)) { + return $result; } - 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; - } + $this->db->debug('Overwritting database: '.$database_definition['name'], __FUNCTION__); + } + + $result = $this->db->manager->createDatabase($database_definition['name']); + if (PEAR::isError($result)) { + if (!MDB2::isError($result, MDB2_ERROR_ALREADY_EXISTS)) { + return $result; } + $this->db->debug('Database already exists: ' . $database_definition['name'], __FUNCTION__); + $create = false; } + $previous_database_name = $this->db->setDatabase($database_definition['name']); if (($support_transactions = $this->db->supports('transactions')) && PEAR::isError($result = $this->db->beginNestedTransaction()) @@ -2435,21 +2427,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;
 [2007-12-07 15:55 UTC] ifeghali (Igor Feghali)
Hello Ali, Thank you for your patch. I will review it and make some needed modifications. This should be done until tomorow. Stay tunned. regards, iGor.
 [2007-12-08 20:31 UTC] ifeghali (Igor Feghali)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.