Options

how to get to individual script from differences object

yzguyyzguy Posts: 23 Bronze 2
How do I get to the script for each of the objects in each db from a Differences object?

I found a round about way to get to the stored procedures, looking up each one by name through the data base object

_differences[100].ObjectIn1.Database.StoredProcedures["dbo", "sp_name"].Text

above is assuming the 100 index is an sp with the name "sp_name", but really the index I use there does not matter, because it is just getting to the db, it is really looking it up by name. I assume there is a way to get to the scipt object directly from the differences instance. Something like:

_differences[100].ObjectIn1.ScriptText

or if there is not a more direct way of getting the script text, how do I get the complete create table script (I could live with the round about method for getting SP scripts, but don't see any way to get the complete table scripts)? something like this?

_differences[0].ObjectIn1.Database.Tables["dbo", "test"].??

Comments

  • Options
    You're probably looking for the ScriptObject method? There's one on anything that inherits from ScriptableDatabaseObject, which should be everything you're looking at there.

    You can also create a Work object and use the Work.ScriptObject method.
    Software Developer
    Redgate Software
  • Options
    yzguyyzguy Posts: 23 Bronze 2
    I found this:

    Work work = new Work();

    // Retrieve the script for a particular table
    Regions regions = work.ScriptObject(_differences[0].ObjectIn1.Database.Tables["dbo", "acct"], o);
    string tmp = regions.ToString();

    but the question still remains, is there a more direct method from the differences object to get the indvidual scripts?
  • Options
    yzguyyzguy Posts: 23 Bronze 2
    I found the script objects in Work, but not anywhere else usefull. I was trying to find the scripts directly without having to pass in the names, or some other reference. I thought they might be in the differences object that I get back after doing a compare. I can loop through the differences object and see individual differences and find out things like the typ of object, name, if they were the same, different or only existed in one or the other db, but I don't see a way to directly access the script from there. Only to take the name from there and then go to the db object using the name, to get the script. This is not a big deal, I just figured if it was in the differences object I'd use that one (I figured that would be faster)
  • Options
    You can get the database object from the ObjectIn1 / ObjectIn2 properties of the Difference object, but you'll have to cast it to the right object type (or just casting it to ScriptableDatabaseObject may work) in order to access the ScriptObject method, as it isn't in the IDatabaseObject interface.

    You should also be able to use the ScriptObject method in Work directly on the ObjectIn1 / ObjectIn2 objects rather than having to go through the Database property.
    Software Developer
    Redgate Software
  • Options
    yzguyyzguy Posts: 23 Bronze 2
    yeah, that worked (the objectin1 and 2)
    Thanks
Sign In or Register to comment.