my $es = read_language()->{'FILELOCKREGEN'}; $es =~ s/\%sec/7/g;
log_error("dbint.pl", "sql_lock", "Request for lock by $subroutine on GLOBAL failed... [$selectquery1->[0]->{processid},$processid] (GLOBAL LOCK exists)");
error_message("Database Connect Error", "Could not connect to database <B>$database</B>.<p>Error message is: <FONT COLOR=#800080>$DBI::errstr</FONT>. Argument is $arg.", 0, 1) if $arg != 2;
return (undef, $DBI::errstr);
}
}
###
### db_sql_query
###
### General function to take a hash and convert it into a SQL query
###
sub db_sql_query {
my ($hash3, $database3, $qtype, $where3, $dbh, $noerr) = @_;
$dbh = database_dbh() if ! defined $dbh;
my @nh = defined $hash3 ? (ref $hash3 eq "HASH" ? ($hash3) : @{ $hash3 }) : ();
my @wh = defined $where3 ? (ref $where3 eq "HASH" ? ($where3) : @{ $where3 }) : ();
my $hash0 = $nh[0];
my $where0 = $wh[0];
my @ar = keys(%{ $hash0 });
my @d = split(/,/, $database3);
my @r = ();
foreach my $database (@d) {
my $sql_str = "";
if ($qtype =~ m|^insert$|i || $qtype =~ m|^replace$|i) {
my $i = $qtype =~ m|^insert$|i ? "INSERT" : "REPLACE";
$sql_str = "$i INTO $PARAMS->{db_prefix}$database (";
$sql_str .= join(",", @ar);
$sql_str .= ") VALUES ";
$sql_str .= _db_sql_query_questionmarks(\@ar);
} elsif ($qtype =~ m|^update$|i) {
$sql_str = "UPDATE $PARAMS->{db_prefix}$database SET ";
foreach my $a (@ar) {
$sql_str .= "$a=?,";
}
$sql_str =~ s/,$//;
$sql_str .= _db_sql_query_where($where0);
} elsif ($qtype =~ m|^delete$|i) {
$sql_str = "DELETE FROM $PARAMS->{db_prefix}$database";
$sql_str .= _db_sql_query_where($where0);
} elsif ($qtype =~ m|^select$|i) {
$sql_str = "SELECT * FROM $PARAMS->{db_prefix}$database";
$sql_str .= _db_sql_query_where($where0);
}
$sql_str =~ s/\s+$//;
$sql_str .= ";";
if (scalar(@wh) == 0) {
push @wh, {} until scalar(@wh) >= scalar(@nh);
}
if (defined $dbh) {
my $statement = $sql_str;
my $sth = undef;
unless ($sth = $dbh->prepare($statement)) {
log_error("dbint.pl", "db_sql_query", "Could not prepare statement [$statement]... " . $dbh->errstr());