ACME-QuoteDB
view release on metacpan or search on metacpan
lib/ACME/QuoteDB/DB/DBI.pm view on Meta::CPAN
#use criticism 'brutal'; # use critic with a ~/.perlcriticrc
use version; our $VERSION = qv('0.1.2');
use Readonly;
use File::Basename qw/dirname/;
use Carp qw/croak/;
use Cwd 'abs_path';
use File::Spec;
Readonly my $QUOTES_DATABASE => $ENV{ACME_QUOTEDB_PATH}
|| File::Spec->catfile(_untaint_db_path(),
q(quotedb), q(quotes.db)
);
# set this to use a remote database
# i.e. mysql
Readonly my $REMOTE => $ENV{ACME_QUOTEDB_REMOTE};
# be more specific (or more general) this is mysql
# and 'remote' can be localhost
lib/ACME/QuoteDB/DB/DBI.pm view on Meta::CPAN
RaiseError => 1,
mysql_enable_utf8 => 1,
}
)
|| croak "can not connect to: $database $!";
}
else {
ACME::QuoteDB::DB::DBI->connection(
'dbi:SQLite:dbname='.$QUOTES_DATABASE, '', '',
{
RaiseError => 1,
unicode => 1,
# func/pragma's may not work here,..(probably isnt' smart anyway)
#count_changes => 0,
#temp_store => 2,
#synchronous => 'OFF',
#busy_timeout => 3600000
}
)
|| croak "$QUOTES_DATABASE does not exist, or cant be created $!";
# how to enable this function?
#ACME::QuoteDB::DB::DBI->set_sql(func( 3600000, 'busy_timeout' );
}
sub get_current_db_path {
return $QUOTES_DATABASE;
}
sub _untaint_db_path {
my $sane_path = abs_path(dirname(__FILE__));
# appease taint mode, what a dir path looks like,... (probably not)
$sane_path =~ m{([a-zA-Z0-9-_\.:\/\\\s]+)}; #add '.', ':' for win32
return $1 || croak 'cannot untaint db path';
}
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
}
else {
create_db_tables_sqlite();
}
return $self;
}
# XXX we want the user to supply a pre created database.
# created as such 'CREATE DATABASE $dbn CHARACTER SET utf8 COLLATE utf8_general_ci'
# this get's into too many isseuwith privs and database creation
#Sat Aug 22 13:42:37 PDT 2009
# did this:
#mysql> CREATE DATABASE acme_quotedb CHARACTER SET utf8 COLLATE utf8_general_ci;
#mysql> grant usage on *.* to acme_user@localhost identified by 'acme';
#mysql> grant all privileges on acme_quotedb.* to acme_user@localhost ;
#sub create_db_mysql {
# my ($self) = @_;
#
# # hmmmm, what about priv's access, etc
# # maybe user need to supply a db, they have
# # access to, already created (just the db though)
# ## create our db
# #my $dbhc = DBI->connect('DBI:mysql:database=mysql;host='
# # .$self->{host}, $self->{user}, $self->{pass})
# # || croak "db cannot be accessed $! $DBI::errstr";
#
# #my $dbn = $self->{db};
# #my $db = qq(CREATE DATABASE $dbn CHARACTER SET utf8 COLLATE utf8_general_ci);
# # eval {
# # $dbhc->do($db) or croak $dbhc->errstr;
# # };
# # $@ and croak 'Cannot create database!';
# # $dbhc->disconnect; $dbhc = undef;
#
# my $drh = DBI->install_driver('mysql');
# my $rc = $drh->func("dropdb", $self->{db},
# [$self->{host}, $self->{user}, $self->{password}],
# 'admin'
( run in 0.620 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )