Ayende @ Rahien

Unnatural acts on source code

Quick & Dirty CodeGen

I needed to get some code that would map an XML file to a database table. Not being particularily fond of doing it by hand, I whipped out this statement:

select  '

      if node.SelectSingleNode("' + column_name + '/text()") is not null:

            row["' + column_name + '"] = node.SelectSingleNode("' + column_name + '/text()").Value

      else:

            row["' + column_name + '"] = DBNull.Value'

from    information_schema.columns

where   table_name = 'Content'

I am doing about 60% of my code gen with SQL and Regex, I think.

Comments

Tobin Harris
04/15/2007 08:33 AM by
Tobin Harris

This is cool. I use SQL for all sorts of code gen too. It's also great for generating batch scripts, or generating SQL/DDL/DML.

Moran
04/16/2007 07:57 PM by
Moran

I use it to create Active Record class, including everything...

And using the new XML features I can create a fully functional admin console GUI for web apps with a simple F5.

I've been told that I'm taking it too far, though I'm glad that I'm not alone on this.

Mischa Kroon
04/17/2007 09:11 AM by
Mischa Kroon

I use a custom .Net app based on:

http://secretgeek.net/wscg.asp

For doing my lightweight code gen.

I extended it a bit to save snippets of code.

And that works wonders for me :)

Comments have been closed on this topic.