how to get to individual script from differences object

Automate and integrate using the SQL comparison API

Moderator: Chris Auckland

how to get to individual script from differences object

Postby yzguy » Tue Feb 09, 2010 2:13 am

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"].??
yzguy
 
Posts: 18
Joined: Tue Feb 09, 2010 2:05 am

Postby Michelle Taylor » Tue Feb 09, 2010 12:20 pm

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.
Michelle Taylor
 
Posts: 529
Joined: Mon Oct 30, 2006 12:45 pm
Location: Red Gate Software

Postby yzguy » Tue Feb 09, 2010 11:20 pm

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?
yzguy
 
Posts: 18
Joined: Tue Feb 09, 2010 2:05 am

Postby yzguy » Tue Feb 09, 2010 11:23 pm

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)
yzguy
 
Posts: 18
Joined: Tue Feb 09, 2010 2:05 am

Postby Michelle Taylor » Wed Feb 10, 2010 1:26 pm

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.
Michelle Taylor
 
Posts: 529
Joined: Mon Oct 30, 2006 12:45 pm
Location: Red Gate Software

Postby yzguy » Sat Feb 13, 2010 12:15 am

yeah, that worked (the objectin1 and 2)
Thanks
yzguy
 
Posts: 18
Joined: Tue Feb 09, 2010 2:05 am


Return to SQL Comparison SDK Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests