Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

April 18, 2006

Producing a CSV file from a database table

Back in November, 2002 I wrote a little utility module to dump the entire contents of an Oracle table to a CSV file.

Over the past month or so I've needed it again so I dusted that code off and made some enhancements. First I added support for MySQL and SQLite. As if that wasn't enough I then added an optional where clause parameter, so that you can dump some of the rows in the table. Then I added another optional parameter, this time a column list allowing you to only specify a subset of the columns in the table.

Then I just got carried away and introduced another function which accepts a valid SQL statement and dumps its results to a CSV file.

You can view the code here - or download it from here -

Posted by Andy Todd at April 18, 2006 06:14 PM