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

Bug #12950 writeInitialization method not work some times
Submitted: 2008-01-21 20:26 UTC
From: afz Assigned: ifeghali
Status: Closed Package: MDB2_Schema (version CVS)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


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 : 13 + 11 = ?

 
 [2008-01-21 20:26 UTC] afz (Ali Fazelzadeh)
Description: ------------ Hi, if load "writeInitialization" method after "updateDatabase" method in some databases like Interbase/Firebird the queris that provided in writeInitialization not excuted(without any error). for fix this problem, if we place exceute query in transaction, work fine.

Comments

 [2008-01-21 20:26 UTC] afz (Ali Fazelzadeh)
Index: Schema.php =================================================================== RCS file: /repository/pear/MDB2_Schema/MDB2/Schema.php,v retrieving revision 1.117 diff -u -r1.117 Schema.php --- Schema.php 8 Dec 2007 20:30:15 -0000 1.117 +++ Schema.php 21 Jan 2008 16:49:44 -0000 @@ -419,6 +419,7 @@ 'name' => $database, 'create' => true, 'overwrite' => false, + 'charset' => '', 'description' => '', 'comments' => '', 'tables' => array(), @@ -887,6 +888,7 @@ $table_name = $this->db->quoteIdentifier($table_name, true); $result = MDB2_OK; + $support_transactions = $this->db->supports('transactions'); foreach ($table['initialization'] as $instruction) { $query = ''; @@ -928,10 +930,18 @@ break; } if ($query) { + if ($support_transactions) { + $resTransaction = $this->db->beginTransaction(); + } + $result = $this->db->exec($query); if (PEAR::isError($result)) { return $result; } + + if ($support_transactions && !PEAR::isError($resTransaction)) { + $res = $this->db->commit(); + } } } return $result; @@ -1262,12 +1272,23 @@ $this->db->debug('Overwritting database: '.$database_definition['name'], __FUNCTION__); } - $this->db->expectError(MDB2_ERROR_ALREADY_EXISTS); - $result = $this->db->manager->createDatabase($database_definition['name']); + $errorcodes = array(MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_UNSUPPORTED); + $this->db->expectError($errorcodes); + $dbOptions = array(); + if (isset($database_definition['charset'])) { + $dbOptions['charset'] = $database_definition['charset']; + } + $result = $this->db->manager->createDatabase($database_definition['name'], $dbOptions); $this->db->popExpect(); - if (PEAR::isError($result)) { + if (PEAR::isError($result) && !MDB2::isError($result, MDB2_ERROR_UNSUPPORTED)) { if (MDB2::isError($result, MDB2_ERROR_ALREADY_EXISTS)) { $this->db->debug('Database already exists: ' . $database_definition['name'], __FUNCTION__); + if (!empty($dbOptions)) { + $result = $this->db->manager->alterDatabase($database_definition['name'], $dbOptions); + if (PEAR::isError($result)) { + return $result; + } + } $create = false; } else { return $result;
 [2008-01-21 20:27 UTC] afz (Ali Fazelzadeh)
in this patch also fix return error if database not support createDatabase/dropDatabase(like Interbase/Firebird).
 [2008-01-22 19:14 UTC] afz (Ali Fazelzadeh)
plz. use this patch it's better than last patch: Index: Schema.php =================================================================== RCS file: /repository/pear/MDB2_Schema/MDB2/Schema.php,v retrieving revision 1.117 diff -u -r1.117 Schema.php --- Schema.php 8 Dec 2007 20:30:15 -0000 1.117 +++ Schema.php 22 Jan 2008 18:51:31 -0000 @@ -419,6 +419,7 @@ 'name' => $database, 'create' => true, 'overwrite' => false, + 'charset' => '', 'description' => '', 'comments' => '', 'tables' => array(), @@ -887,6 +888,7 @@ $table_name = $this->db->quoteIdentifier($table_name, true); $result = MDB2_OK; + $support_transactions = $this->db->supports('transactions'); foreach ($table['initialization'] as $instruction) { $query = ''; @@ -928,10 +930,18 @@ break; } if ($query) { + if ($support_transactions && PEAR::isError($res = $this->db->beginNestedTransaction())) { + return $res; + } + $result = $this->db->exec($query); if (PEAR::isError($result)) { return $result; } + + if ($support_transactions && PEAR::isError($res = $this->db->completeNestedTransaction())) { + return $res; + } } } return $result; @@ -1262,12 +1272,23 @@ $this->db->debug('Overwritting database: '.$database_definition['name'], __FUNCTION__); } - $this->db->expectError(MDB2_ERROR_ALREADY_EXISTS); - $result = $this->db->manager->createDatabase($database_definition['name']); + $errorcodes = array(MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_UNSUPPORTED); + $this->db->expectError($errorcodes); + $dbOptions = array(); + if (isset($database_definition['charset'])) { + $dbOptions['charset'] = $database_definition['charset']; + } + $result = $this->db->manager->createDatabase($database_definition['name'], $dbOptions); $this->db->popExpect(); - if (PEAR::isError($result)) { + if (PEAR::isError($result) && !MDB2::isError($result, MDB2_ERROR_UNSUPPORTED)) { if (MDB2::isError($result, MDB2_ERROR_ALREADY_EXISTS)) { $this->db->debug('Database already exists: ' . $database_definition['name'], __FUNCTION__); + if (!empty($dbOptions)) { + $result = $this->db->manager->alterDatabase($database_definition['name'], $dbOptions); + if (PEAR::isError($result)) { + return $result; + } + } $create = false; } else { return $result; @@ -1324,11 +1345,13 @@ $this->db->setDatabase($previous_database_name); if (PEAR::isError($result) && $create - && PEAR::isError($result2 = $this->db->manager->dropDatabase($database_definition['name'])) - ) { - return $this->raiseError(MDB2_SCHEMA_ERROR, null, null, - 'Could not drop the created database after unsuccessful creation attempt ('. - $result2->getMessage().' ('.$result2->getUserinfo().'))'); + && PEAR::isError($result2 = $this->db->manager->dropDatabase($database_definition['name']))) + { + if (!MDB2::isError($result2, MDB2_ERROR_UNSUPPORTED)) { + return $this->raiseError(MDB2_SCHEMA_ERROR, null, null, + 'Could not drop the created database after unsuccessful creation attempt ('. + $result2->getMessage().' ('.$result2->getUserinfo().'))'); + } } return $result;
 [2008-01-22 19:32 UTC] ifeghali (Igor Feghali)
ok as soon as possible. regards, iGor.
 [2008-01-29 10:20 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.