use strict; use DBI; my $query_string = "SELECT * FROM perfmon WHERE Date_and_Time BETWEEN '7034' AND '7037'"; my $csv_file_name = "perfdata.csv"; my $csv_dbh; my $stmt_handle; $@ = ""; eval{ $csv_dbh = DBI->connect( "DBI:CSV:f_dir=.", { PrintError => 1, RaiseError => 1, AutoCommit => 0 } ); print "\n$csv_file_name\n"; $csv_dbh -> {csv_tables} -> {perfmon} = { file => $csv_file_name, }; print "\n$query_string\n"; $stmt_handle = $csv_dbh -> prepare(" $query_string "); $stmt_handle -> execute(); while ( my @row = $stmt_handle->fetchrow_array() ) { my $rowstr = join(";", @row); print $rowstr,"\n"; } $stmt_handle -> finish(); $csv_dbh -> disconnect(); }; $@ and die "\n\nSQL database error: $@\n"; __END__ #Contents of the CSV file. Level,Date_and_Time,Source,Event_ID,Task_Category,Status 'Information',26/01/2010 20:05:51,'Service Control Manager',7036,None,'The Multimedia Class Scheduler service entered the running state.' 'Information',26/01/2010 20:05:41,'Service Control Manager',7036,None,'The WMI Performance Adapter service entered the stopped state.' 'Information',27/01/2010 20:02:36,'Service Control Manager',7036,None,'The Application Experience service entered the running state.' 'Information',27/01/2010 20:02:35,'Service Control Manager',7036,None,'The WMI Performance Adapter service entered the running state.' 'Information',28/01/2010 20:01:25,'Service Control Manager',7036,None,'The Application Information service entered the running state.' #command line used: perl perflogquery.pl #Output perfdata.csv SELECT * FROM perfmon WHERE Date_and_Time BETWEEN '7034' AND '7037' DBD::CSV::st execute failed: Not an ARRAY reference at C:/Perl/site/lib/SQL/Statement/Operation.pm line 438, line 2. [for Statement " SELECT * FROM perfmon WHERE Date_and_Time BETWEEN '7034' AND '7037' "] at perflogquery.pl line 42. DBD::CSV::st fetchrow_array failed: Attempt to fetch row without a preceeding execute () call or from a non-SELECT statement [for Statement " SELECT * FROM perfmon WHERE Date_and_Time BETWEEN '7034' AND '7037' "] at perflogquery.pl line 48.