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.

Print | posted on Sunday, April 15, 2007 9:11 AM

Feedback


Gravatar

# re: Quick & Dirty CodeGen 4/15/2007 11:33 AM 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.



Gravatar

# re: Quick & Dirty CodeGen 4/16/2007 10:57 PM 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.


Gravatar

# re: Quick & Dirty CodeGen 4/17/2007 12:11 PM 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.