# Wednesday, February 21, 2007
Rob Farley posted a very interesting codegen post on scripting objects this morning, and as a reforming codegen junky I just couldn't let it go without comment :-)

Firstly, I modified his query as so:

select quotename(si.name) as "@IndexName", quotename(ss.name) AS "@SchemaName", quotename(so.name) AS "@ObjectName",
    stuff((select ',' + quotename(sc.name)
            from sys.index_columns sic
            join sys.columns sc
                on sc.column_id = sic.column_id
            where so.object_id = sic.object_id
                and sic.index_id = si.index_id
                and sc.object_id = so.object_id
            order by sic.key_ordinal
            for xml path('')),1,1,'') as "@IndexColumns"
from sys.indexes si
join sys.objects so
    on so.object_id = si.object_id
join sys.schemas ss
    on ss.schema_id = so.schema_id
where so.type = 'U' and si.type = 1
for xml path('index'), root('indexes')


Things I'll point out:
  • Adding the extra for xml clause, this time specifying a better row element name than 'row' and also adding a document node
  • Once the outter for xml clause is in place, we can alias the columns using @ to have them come out as elements in the results
We can feed the results of that query straight into the following XSLT:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"
/>
   
    <xsl:template match='/'>
    <xsl:apply-templates select ='indexes/index'
/>
    </xsl:template>

  <xsl:template match='index' >
create index <xsl:value-of select='@IndexName'
/>
  on <xsl:value-of select='@SchemaName'
/>.<xsl:value-of select='@ObjectName'/> (<xsl:value-of select='@IndexColumns'/>)
  </xsl:template>
 
</xsl:stylesheet>

I'm not claiming this method is superior, just different, which I think is in keeping with the spirit of Rob's post :-)  and I have learned more about the improvements of the for xml clause in SQL Server 2005 in the process.

I'll leave final judgment on the utility of this approach as an exercise to the reader; my instinctive reaction is to include it as a build step to help you snapshot schema changes between check-ins, or as Rob suggests to take objects from one database and create slightly different objects in another database – there are no wrong answers and if you think of something interesting please leave a comment :-)

Grab the source files here: ScriptObjects.zip (.78 KB)
Wednesday, February 21, 2007 6:32:28 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [2]  | 
# Monday, February 19, 2007

In my commute this morning I was listening to my weekly dose of DotNetRocks - Show 214 with guest Billy Hollis and Billy mentioned something on Agile to illustrate a point, and it has stuck with me all day.

He was referring to a presentation he attended where an advocate said he was writing 2 or 3 lines of unit test code for each line of production code.  Billy's objection to this is hardly a challenge to intuition: Are we getting 4x the value for 4x the code?

One of my metrics for the unit tests that I write is that they don't hurt.  Some can be a couple of lines long, some can be heavily copied-n-paste'd.  Customizing a CodeRush template is time well spent.  There are no wrong answers, however you get them in there is really OK.

It makes sense:  You're writing a unit test.  The aim is to isolate a gizmo of your choosing in your code and exercise it.  The cumulative weight of the unit tests should really function as an expression of your intent for the gizmo.  I outlined what I think of the high importance of naming your tests in a prior post.

Monday, February 19, 2007 4:48:15 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, February 16, 2007

I love finding little nice features.  I just discovered the following combination in CodeRush:

alt-UP/alt-DOWN - Change visiblility (public/private/protected/friend) of property, variable or class that the cursor is inside

I've got to hang around late tonight for a conference call with London (on a Friday night no less!) but finding that has made my day.

We should all try to remember the importance of little units of joy in the software we make.

 

Friday, February 16, 2007 3:23:00 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [1]  | 
# Thursday, February 15, 2007
WCF is at SDNUG tonight...

...and also came across it here today:

Image courtesy Gary Costa Pereira

[?] After Blog Mint:  Juval Lowy was great at SDNUG last night.  Not a semi-colon in sight!  The presentation was mostly about architecture with the IDesign method.  Well worth it. 

Also, Justin, if you're reading this... sorry about spilling beer on you at the Paragon :-)

Thursday, February 15, 2007 8:32:45 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, February 07, 2007

with apologies and thanks to Sir Winston for giving me the courage to continue on with WiX :-)

The two links that make my WiX world turn are:

Wednesday, February 07, 2007 6:11:45 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, February 06, 2007

Some of the problems a modern cow developer has to face... (thanks Brian - keep posting the funnies)

My contribution:


WATERFALL:  18 months ago, one cow went into the milking shead.  The method was sound, but you don't need milk any more.

AGILE:  Only milk when necessary. 

EXTREME PROGRAMMING:  You have two cows.  They milk each other.

TEST-DRIVEN DEVELOPMENT:  Know the bucket before milking any cows.

OPEN SOURCE:  I have a cow, you and some other guy from Norway milk it on weekends or when ever you have some free time. 

CONTINUOUS INTEGRATION:  Your team of two cows checks-in to the milking sheads every day.  Everyone has access to the milk.  Everyone feels good.

SERVICE-ORIENTED ARCHITECTURE:  We agree a schema for a cow.  No one feels dependant on any breed of cow, but no one has actually seen a complete cow.

SCRUM:  There is a backlog of milk orders.  Cows decide how they are to be milked.  Every 30 days the cows, pigs and chickens agree on an amount of potentially shippable milk.  The pigs and chickens get to decide when no more milk is needed.

SaaS:  You don't own the cows.  You rent access to them and pay for it out of OpEx.  Owning cows is outside of core business - you just need some milk.

Tuesday, February 06, 2007 1:53:08 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, February 05, 2007

An easy one, but anyway... When building a target in NAnt that depends on a Web Service, the only change to your <vbc> or <csc> task is to make sure your sources include the Reference file that Visual Studio generated when you added/updated the Web Reference, as so:

<sources>
    <include name="MyProject\*.vb"/>
    <include name="MyProject\Web References\RemoteInterfaceWS\Reference.vb"/>
</sources>

I was also pleased to note that in cases where the wsdl imports a typed dataset (ie the remote Web Method takes or returns a typed dataset), Reference.[vb|cs] includes the dataset definition.  No need to add a step to execute xsd.exe!

Monday, February 05, 2007 4:11:53 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, February 02, 2007

Got Build?

(sprint pending ;)

Friday, February 02, 2007 8:22:44 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, February 01, 2007

I love a good coincidence :-)  Couple of interesting expirations...

  • One of my credit cards expired today.  Not your problem I know, just saying...
  • The first Office 2007 betas expired today too.  If this stands between you and a productive morning in Outlook, grab the Beta 2 Technical Refresh and you will be able to the 31st of March.

*with apologies for the Dark Side of the Moon reference, I'm still on a buzz from seeing Roger Waters at the SuperdomeAcer Arena last week...

Thursday, February 01, 2007 1:04:52 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Disclaimer  |  Comments [2]  |