I mentioned the incredible tedium of writing DB2 embedded-SQL programs in here a while ago, and of course I wasn't about to stand for that. I wanted to write a program to do the tedious stuff for me.
My first attempts met with abject failure: DBI and DBD::DB2 don't give you metadata unless the underlying DBMS supports the INFORMATION_SCHEMA views (which DB2 doesn't; and it wouldn't suffice for what I needed anyway), and the type information was the sine qua non of what I was trying to do.
Then I found a way to get metadata for arbitrary SQL using one of IBM's sample embedded-SQL/C programs. But as soon as I got that working, I knew there wasn't a chance I'd write something like the code generator in C. Just the thought of doing a ton of strstr
and strtok
calls almost made me break out in a rash. Really, life's too short.
A couple of days ago, somebody in a meeting said, "Oh, I figured you'd just dump the type data in a file", and the lightbulb went on. I used IPC::Open2 to feed the SQL file to the C program I'd cribbed from IBM, and read the results back. Presto! DB2 metadata in Perl!
I got the code generator working today and it spit out 95% of everything I needed. Put me ahead days, if not weeks.