$self->{dbh} = $self->{dbh}->clone;
}
if ( $ping_count >= 10 and not $self->{dbh}->ping ) {
- &ERROR("Tried real hard but was unable to reconnect");
+ &ERROR('Tried real hard but was unable to reconnect');
return undef;
}
$_[0] = $self->{dbh};
# SQLHost should be unset for SQLite
if ( exists $param{'SQLHost'} and $param{'SQLHost'} ) {
- # PostgreSQL requires ";" and keyword 'host'. See perldoc Pg -- troubled
+ # PostgreSQL requires ';' and keyword 'host'. See perldoc Pg -- troubled
if ( $type eq 'Pg' ) {
$dsn .= ";host=$param{SQLHost}";
}
my $sth;
if ( !defined $select or $select =~ /^\s*$/ ) {
- &WARN("sqlSelectMany: select == NULL.");
+ &WARN('sqlSelectMany: select == NULL.');
return;
}
if ( !defined $table or $table =~ /^\s*$/ ) {
- &WARN("sqlSelectMany: table == NULL.");
+ &WARN('sqlSelectMany: table == NULL.');
return;
}
sub sqlSelect {
my $sth = &sqlSelectMany(@_);
if ( !defined $sth ) {
- &WARN("sqlSelect failed.");
+ &WARN('sqlSelect failed.');
return;
}
my @retval = $sth->fetchrow_array;
my @retval;
if ( !defined $sth ) {
- &WARN("sqlSelect failed.");
+ &WARN('sqlSelect failed.');
return;
}
my ( $table, $select, $where_href, $other, $type ) = @_;
my $sth = &sqlSelectMany( $table, $select, $where_href, $other );
if ( !defined $sth ) {
- &WARN("sqlSelectColhash failed.");
+ &WARN('sqlSelectColhash failed.');
return;
}
my %retval;
if ( defined $type and $type == 2 ) {
- &DEBUG("sqlSelectColHash: type 2!");
+ &DEBUG('sqlSelectColHash: type 2!');
while ( my @row = $sth->fetchrow_array ) {
$retval{ $row[0] } = join( ':', $row[ 1 .. $#row ] );
}
- &DEBUG( "sqlSelectColHash: count => " . scalar( keys %retval ) );
+ &DEBUG( 'sqlSelectColHash: count => ' . scalar( keys %retval ) );
}
elsif ( defined $type and $type == 1 ) {
sub sqlSelectRowHash {
my $sth = &sqlSelectMany(@_);
if ( !defined $sth ) {
- &WARN("sqlSelectRowHash failed.");
+ &WARN('sqlSelectRowHash failed.');
return;
}
my $retval = $sth->fetchrow_hashref();
my ( $table, $where_href, $data_href ) = @_;
if ( !defined $table or $table =~ /^\s*$/ ) {
- &WARN("sqlSet: table == NULL.");
+ &WARN('sqlSet: table == NULL.');
return;
}
if ( !defined $data_href or ref($data_href) ne 'HASH' ) {
- &WARN("sqlSet: data_href == NULL.");
+ &WARN('sqlSet: data_href == NULL.');
return;
}
my $k = join( ',', keys %{$where_href} );
my $result = &sqlSelect( $table, $k, $where_href );
- # &DEBUG("result is not defined :(") if (!defined $result);
+ # &DEBUG('result is not defined :(') if (!defined $result);
# this was hardwired to use sqlUpdate. sqlite does not do inserts on sqlUpdate.
if ( defined $result ) {
my ( $table, $data_href, $where_href ) = @_;
if ( !defined $data_href or ref($data_href) ne 'HASH' ) {
- &WARN("sqlSet: data_href == NULL.");
+ &WARN('sqlSet: data_href == NULL.');
return 0;
}
# note: ^^^ doesnt actually do anything lol. Need code to s/1/DELAYED/ below -- troubled
if ( !defined $data_href or ref($data_href) ne 'HASH' ) {
- &WARN("sqlInsert: data_href == NULL.");
+ &WARN('sqlInsert: data_href == NULL.');
return;
}
my @v = @{$v_aref};
if ( !@k or !@v ) {
- &WARN("sqlInsert: keys or vals is NULL.");
+ &WARN('sqlInsert: keys or vals is NULL.');
return;
}
&sqlRaw(
"Insert($table)",
sprintf(
- "INSERT %s INTO %s (%s) VALUES (%s)",
+ 'INSERT %s INTO %s (%s) VALUES (%s)',
( $other || '' ),
$table,
join( ',', @k ),
my ( $table, $data_href, $pkey ) = @_;
if ( !defined $data_href or ref($data_href) ne 'HASH' ) {
- &WARN("sqlReplace: data_href == NULL.");
+ &WARN('sqlReplace: data_href == NULL.');
return;
}
my @v = @{$v_aref};
if ( !@k or !@v ) {
- &WARN("sqlReplace: keys or vals is NULL.");
+ &WARN('sqlReplace: keys or vals is NULL.');
return;
}
# PGSql syntax: UPDATE table SET key = 'value', key2 = 'value2' WHERE key = 'value'
# &sqlRaw("Replace($table)", sprintf(
- # "INSERT INTO %s (%s) VALUES (%s)",
+ # 'INSERT INTO %s (%s) VALUES (%s)',
# $table, join(',',@k), join(',',@v)
# ));
&WARN(
"DEBUG: ($pkey = ) "
. sprintf(
- "REPLACE INTO %s (%s) VALUES (%s)",
+ 'REPLACE INTO %s (%s) VALUES (%s)',
$table,
join( ',', @k ),
join( ',', @v )
&sqlRaw(
"Replace($table)",
sprintf(
- "REPLACE INTO %s (%s) VALUES (%s)",
+ 'REPLACE INTO %s (%s) VALUES (%s)',
$table,
join( ',', @k ),
join( ',', @v )
my ( $table, $where_href ) = @_;
if ( !defined $where_href or ref($where_href) ne 'HASH' ) {
- &WARN("sqlDelete: where_href == NULL.");
+ &WARN('sqlDelete: where_href == NULL.');
return;
}
my $sth;
if ( !defined $query or $query =~ /^\s*$/ ) {
- &WARN("sqlRaw: query == NULL.");
+ &WARN('sqlRaw: query == NULL.');
return 0;
}
my $sth;
if ( !defined $query or $query =~ /^\s*$/ ) {
- &WARN("sqlRawReturn: query == NULL.");
+ &WARN('sqlRawReturn: query == NULL.');
return 0;
}
my ($href) = @_;
if ( !defined $href ) {
- &WARN("hashref2where: href == NULL.");
+ &WARN('hashref2where: href == NULL.');
return;
}
}
}
- return join( ' AND ', map { $_ . "=" . $hash{$_} } keys %hash );
+ return join( ' AND ', map { $_ . '=' . $hash{$_} } keys %hash );
}
sub hashref2update {
my ($href) = @_;
if ( ref($href) ne 'HASH' ) {
- &WARN("hashref2update: href is not HASH ref.");
+ &WARN('hashref2update: href is not HASH ref.');
return;
}
$hash{$k} = $v;
}
- return join( ', ', map { $_ . "=" . $hash{$_} } sort keys %hash );
+ return join( ', ', map { $_ . '=' . $hash{$_} } sort keys %hash );
}
sub hashref2array {
my ($href) = @_;
if ( ref($href) ne 'HASH' ) {
- &WARN("hashref2update: href is not HASH ref.");
+ &WARN('hashref2update: href is not HASH ref.');
return;
}
my $query = "SELECT $select FROM $table LIMIT 1 OFFSET $rand";
if ( $param{DBType} =~ /^mysql$/i ) {
- # WARN: only newer MySQL supports "LIMIT limit OFFSET offset"
+ # WARN: only newer MySQL supports 'LIMIT limit OFFSET offset'
$query = "SELECT $select FROM $table LIMIT $rand,1";
}
my $sth = $dbh->prepare($query);
$str = $1;
}
else {
- $str .= "%" if ( $str =~ s/^\^// );
- $str = "%" . $str if ( $str =~ s/\$$// );
- $str = "%" . $str . "%" if ( $str eq $origStr ); # el-cheapo fix.
+ $str .= '%' if ( $str =~ s/^\^// );
+ $str = '%' . $str if ( $str =~ s/\$$// );
+ $str = '%' . $str . '%' if ( $str eq $origStr ); # el-cheapo fix.
}
$str =~ s/\_/\\_/g;
sub sqlCreateTable {
my ( $table, $dbtype ) = @_;
- my (@path) = ( $bot_data_dir, ".", "..", "../.." );
+ my (@path) = ( $bot_data_dir, '.', '..', '../..' );
my $found = 0;
my $data;
$dbtype = lc $dbtype;
my %db;
if ( $param{DBType} =~ /^mysql$/i ) {
- my $sql = "SHOW DATABASES";
+ my $sql = 'SHOW DATABASES';
foreach ( &sqlRawReturn($sql) ) {
$database_exists++ if ( $_ eq $param{'DBName'} );
}
if ( $#tables == -1 ) {
@tables = $dbh->tables;
}
- &status( "Tables: " . join( ',', @tables ) );
+ &status( 'Tables: ' . join( ',', @tables ) );
@db{@tables} = (1) x @tables;
}
# $sql_showDB = SQL to select the DB list
# $sql_showTBL = SQL to select all tables for the current connection
- my $sql_showDB = "SELECT datname FROM pg_database";
+ my $sql_showDB = 'SELECT datname FROM pg_database';
my $sql_showTBL = "SELECT tablename FROM pg_tables \
WHERE schemaname = 'public'";
unless ($database_exists) {
&status("Creating PostgreSQL database $param{'DBName'}");
- &status("(actually, not really, please read the INSTALL file)");
+ &status('(actually, not really, please read the INSTALL file)');
}
# retrieve a list of db's from the server. This code is from mysql above, please check -- troubled
if ( $#tables == -1 ) {
@tables = $dbh->tables;
}
- &status( "Tables: " . join( ',', @tables ) );
+ &status( 'Tables: ' . join( ',', @tables ) );
@db{@tables} = (1) x @tables;
}