MySQL-RunSQL

 view release on metacpan or  search on metacpan

lib/MySQL/RunSQL.pm  view on Meta::CPAN

package MySQL::RunSQL;

=head1 NAME

MySQL::RunSQL	- Run SQL queries against a MySQL database and return the
results to STDOUT or XLSX file.

=cut

use v5.10;
use warnings;
use Modern::Perl;
use DBI;
use Params::Validate;
use Excel::Writer::XLSX;
use Env						qw/HOME/;
use vars					qw($VERSION @ISA);

require Exporter;

@ISA = qw/Exporter/;
$VERSION = '1.2';


=head1 SYNOPSIS

	use MySQL::RunSQL;
	
	my $runsql = MySQL::RunSQL->new(
		group_name => <mysql_group>, #[blockname] to look under in my.cnf file
		database => <database>, # Database to run query against
		my_cnf => <my_cnf_file>, # File the contains user/pass information
		host	=> <mysql_server> # MySQL server to connect to
		);
		
	my $sqlfile = 	"/tmp/employees.sql";
	
	$runsql->runsql("SELECT col1 as 'Col 1', col2 as 'Col 2'...");
	$runsql->runsql_fromfile($sqlfile);
	
	my $xlsx = $runsql_report("SELECT col1 as 'Col 1', col2 as 'Col 2'...");
	my $xlsx = $runsql_report_fromfile($sqlfile);
	
	

=head1 DESCRIPTION

	MySQL::RunSQL provides a simple object oriented interface to
	DBD::mysql for running a queries against a MySQL database. Data
	is returned to STDOUT as a comma delimited list or is written
	out to an XLSX file.
	
=head1 EXAMPLE

	#!/usr/bin/perl
	
	use strict;
	use MySQL::RunSQL;
	use Env qw/HOME/;
	
	my $db = "test";
	my $cnf = "$HOME/.my.cnf";
	my $group = "test";
	my $host = "localhost";
	
	# Create our MySQL::RunSQL Object
	my $rs = MySQL::RunSQL->new(
		database =>	$db,
		my_cnf	=>	$cnf,
		group_name => $group,
		host =>	$host
	);



( run in 1.728 second using v1.01-cache-2.11-cpan-39bf76dae61 )