Quick & Dirty CodeGen

time to read 3 min | 552 words

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.