← Back to team overview

maria-developers team mailing list archive

Re: CREATE OR REPLACE DATABASE algorithm

 

Hi Sriram,


On 05/22/2014 09:00 AM, sriram patil wrote:
Hi Alexander and all,

Following are the steps that I am following for implementing "CREATE OR
REPLACE" for DATABASE

"..." signifies, there exists one or more lines of code in that block of
the function.

mysql_create_db(...)
   ...
   ...
   if(db exists) {
     if(create_or_replace) {
       if(DROP_ACL access not granted) {
         // Error 1
         DBUG_RETURN(-1)
       }

       if(mysql_rm_db(...) unsuccessful) {
         // Error 2
         DBUG_RETURN(-1)
       }

       Reset m_status from diagnostics cause it is changed by mysql_rm_db.
       Proceed with normal create db.
     }
     else if(if not exists) {
       ...
     }
     else
       ...
   }
   ...
   ...
}

Is the above algorithm correct?

Yes, it looks fine.

Also, I am not yet sure which errors
should be displayed at both the places "Error 1" and "Error 2".

In case of "Error 1" it should return the same error that
"DROP DATABASE" would return:

ERROR 1044 (42000): Access denied for user 'foo'@'localhost' to database 'd1'

In think in case of "Error 2" you don't need to print any errors.
mysql_rm_db() should take care of printing a proper error.


I have written and tested the above code. It is working fine. Testing
involves running all the existing test cases and executing "CREATE OR
REPLACE DATABASE" command on the console manually. "IF NOT EXISTS" gives
error if used with "CREATE OR REPLACE".

Any other test cases I need to consider?

We'll need to add tests covering the new features into
mysql-test/t/*.test files.

Can you please send the current patch?
I'll help you with adding tests for "DATABASE",
so you can use the same idea for the other objects later.

Thanks.


Thanks,
Sriram


Follow ups

References