Red Gate forums :: View topic - how to get to individual script from differences object
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Comparison SDK Previous Versions
SQL Comparison SDK Previous Versions forum

how to get to individual script from differences object

Search in SQL Comparison SDK Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
yzguy



Joined: 09 Feb 2010
Posts: 18

PostPosted: Tue Feb 09, 2010 2:13 am    Post subject: how to get to individual script from differences object Reply with quote

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"].??
Back to top
View user's profile Send private message
Michelle Taylor



Joined: 30 Oct 2006
Posts: 525
Location: Red Gate Software

PostPosted: Tue Feb 09, 2010 12:20 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
yzguy



Joined: 09 Feb 2010
Posts: 18

PostPosted: Tue Feb 09, 2010 11:20 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
yzguy



Joined: 09 Feb 2010
Posts: 18

PostPosted: Tue Feb 09, 2010 11:23 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
Michelle Taylor



Joined: 30 Oct 2006
Posts: 525
Location: Red Gate Software

PostPosted: Wed Feb 10, 2010 1:26 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
yzguy



Joined: 09 Feb 2010
Posts: 18

PostPosted: Sat Feb 13, 2010 12:15 am    Post subject: Reply with quote

yeah, that worked (the objectin1 and 2)
Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group