def _get_transform(server1, server2, object1, object2, options): """Get the transformation SQL statements This method generates the SQL statements to transform the destination object based on direction of the compare. server1[in] first server connection server2[in] second server connection object1 the first object in the compare in the form: (db.name) object2 the second object in the compare in the form: (db.name) options[in] a dictionary containing the options for the operation: (quiet, etc.) Returns tuple - (bool - same db name?, list of transformation statements) """ from mysql.utilities.common.database import Database from mysql.utilities.common.sql_transform import SQLTransformer obj_type = None direction = options.get("changes-for", "server1") # If there is no dot, we do not have the format 'db_name.obj_name' for # object1 and therefore must treat it as a database name. if object1.find(".") == -1: obj_type = "DATABASE" # We are working with databases so db and name need to be set # to the database name to tell the get_object_definition() method # to retrieve the database information. db1 = object1 db2 = object2 name1 = object1 name2 = object2 else: try: db1, name1 = object1.split(".") db2, name2 = object2.split(".") except: raise UtilError("Invalid object name arguments for _get_transform" "(): %s, %s." % (object1, object2)) db_1 = Database(server1, db1, options) db_2 = Database(server2, db2, options) if obj_type is None: obj_type = db_1.get_object_type(name1) transform_str = [] obj1 = db_1.get_object_definition(db1, name1, obj_type) obj2 = db_2.get_object_definition(db2, name2, obj_type) # Get the transformation based on direction. transform_str = [] same_db_name = True xform = SQLTransformer(db_1, db_2, obj1[0], obj2[0], obj_type, options.get("verbosity", 0)) differences = xform.transform_definition() if differences is not None and len(differences) > 0: transform_str.extend(differences) return transform_str
def _get_transform(server1, server2, object1, object2, options, object_type): """Get the transformation SQL statements This method generates the SQL statements to transform the destination object based on direction of the compare. server1[in] first server connection server2[in] second server connection object1 the first object in the compare in the form: (db.name) object2 the second object in the compare in the form: (db.name) options[in] a dictionary containing the options for the operation: (quiet, etc.) object_type[in] type of the objects to be compared (e.g., TABLE, PROCEDURE, etc.). Returns tuple - (bool - same db name?, list of transformation statements) """ try: m_obj1 = re.match(REGEXP_QUALIFIED_OBJ_NAME, object1) db1, name1 = m_obj1.groups() m_obj2 = re.match(REGEXP_QUALIFIED_OBJ_NAME, object2) db2, name2 = m_obj2.groups() except: raise UtilError("Invalid object name arguments for _get_transform" "(): %s, %s." % (object1, object2)) # If the second part of the object qualified name is None, then the format # is not 'db_name.obj_name' for object1 and therefore must treat it as a # database name. (supports backticks and the use of '.' (dots) in names.) if not name1 or object_type == 'DATABASE': # We are working with databases so db and name need to be set # to the database name to tell the get_object_definition() method # to retrieve the database information. name1 = db1 name2 = db2 db_1 = Database(server1, db1, options) db_2 = Database(server2, db2, options) obj1 = db_1.get_object_definition(db1, name1, object_type) obj2 = db_2.get_object_definition(db2, name2, object_type) # Get the transformation based on direction. transform_str = [] xform = SQLTransformer(db_1, db_2, obj1[0], obj2[0], object_type, options.get('verbosity', 0)) differences = xform.transform_definition() if differences and len(differences) > 0: transform_str.extend(differences) return transform_str
def _get_transform(server1, server2, object1, object2, options): """Get the transformation SQL statements This method generates the SQL statements to transform the destination object based on direction of the compare. server1[in] first server connection server2[in] second server connection object1 the first object in the compare in the form: (db.name) object2 the second object in the compare in the form: (db.name) options[in] a dictionary containing the options for the operation: (quiet, etc.) Returns tuple - (bool - same db name?, list of transformation statements) """ from mysql.utilities.common.database import Database from mysql.utilities.common.sql_transform import SQLTransformer obj_type = None direction = options.get("changes-for", "server1") # If there is no dot, we do not have the format 'db_name.obj_name' for # object1 and therefore must treat it as a database name. if object1.find('.') == -1: obj_type = "DATABASE" # We are working with databases so db and name need to be set # to the database name to tell the get_object_definition() method # to retrieve the database information. db1 = object1 db2 = object2 name1 = object1 name2 = object2 else: try: db1, name1 = object1.split('.') db2, name2 = object2.split('.') except: raise UtilError("Invalid object name arguments for _get_transform" "(): %s, %s." % (object1, object2)) db_1 = Database(server1, db1, options) db_2 = Database(server2, db2, options) if obj_type is None: obj_type = db_1.get_object_type(name1) transform_str = [] obj1 = db_1.get_object_definition(db1, name1, obj_type) obj2 = db_2.get_object_definition(db2, name2, obj_type) # Get the transformation based on direction. transform_str = [] same_db_name = True xform = SQLTransformer(db_1, db_2, obj1[0], obj2[0], obj_type, options.get('verbosity', 0)) differences = xform.transform_definition() if differences is not None and len(differences) > 0: transform_str.extend(differences) return transform_str