if (&IsParam("useStrict")) { use strict; }
#####
-# Usage: &setFactInfo($faqtoid, $type, $what, ?, ?);
+# Usage: &setFactInfo($faqtoid, $type, $primval, $key, $val);
sub setFactInfo {
- &dbSet("factoids", "factoid_key", $_[0], $_[1], $_[2]);
+ &dbSet("factoids",
+ { factoid_key => $_[0] },
+ { $_[1] => $_[2] }
+ );
}
#####
### lets get on with business.
# set the last refresh time. fixes multiple spawn bug.
- &::dbSet("freshmeat", "projectname_short", "_", "latest_version", time());
+ &::dbSet("freshmeat",
+ { "projectname_short" => "_" },
+ { "latest_version" => time() }
+ );
&::dbRaw("LOCK", "LOCK TABLES freshmeat WRITE");
@cols = &::dbGetColInfo("freshmeat");
s/·//g;
}
- if ($str =~ s/\&(\S+);//g) {
+ if (0 and $str =~ s/\&(\S+?);//g) {
&::DEBUG("fm: sarred $1 to ''.");
}
$attempt++;
### TODO: OPTIMIZE THIS.
- &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
- &dbSet("rootwarn", "nick", lc($nick), "time", time());
- &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
- &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
+ if (1) { # old
+ &dbSet("rootwarn", { nick => lc($nick) }, { attempt => $attempt });
+ &dbSet("rootwarn", { nick => lc($nick) }, { time => time() });
+ &dbSet("rootwarn", { nick => lc($nick) }, { host => $user."\@".$host });
+ &dbSet("rootwarn", { nick => lc($nick) }, { channel => $chan });
+ } else { # new. replace.
+ &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
+ &dbSet("rootwarn", "nick", lc($nick), "time", time());
+ &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
+ &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
+ }
return;
}
$karma--;
}
- &dbSet("stats", "nick",$term, "type","karma");
-# &dbSet("stats", "nick",$term, "type","karma");
+ &dbSet("stats",
+ { nick => $term, type => "karma" },
+ { counter => $karma }
+ );
return;
}
my $sth;
if (!($sth = $dbh->prepare($query))) {
- &ERROR("Get: $DBI::errstr");
+ &ERROR("Get: prepare: $DBI::errstr");
return;
}
&SQLDebug($query);
if (!$sth->execute) {
- &ERROR("Get => '$query'");
-# &ERROR("Get => $DBI::errstr");
+ &ERROR("Get: execute: '$query'");
$sth->finish;
return 0;
}
my $sth = $dbh->prepare($query);
&SQLDebug($query);
if (!$sth->execute) {
- &ERROR("GetCol => '$query'");
- &ERROR("GetCol => $DBI::errstr");
+ &ERROR("GetCol: execute: '$query'");
+# &ERROR("GetCol => $DBI::errstr");
$sth->finish;
return;
}
}
#####
-# Usage: &dbSet($table, $primkey, $primval, $key, $val);
+# Usage: &dbSet($table, $primhash_ref, $hash_ref);
sub dbSet {
- my ($table, $primkey, $primval, $key, $val) = @_;
- my $query;
+ my ($table, $phref, $href) = @_;
+ my $where = join(' AND ', map {
+ $_."=".&dbQuote($phref->{$_})
+ } keys %{$phref}
+ );
+
+ my $result = &dbGet($table, join(',', keys %{$phref}), $where);
+
+ my(@keys,@vals);
+ foreach (keys %{$href}) {
+ push(@keys, $_);
+ push(@vals, &dbQuote($href->{$_}) );
+ }
- my $result = &dbGet($table, $primkey, "$primkey='$primval'");
+ if (!@keys or !@vals) {
+ &WARN("dbset: keys or vals is NULL.");
+ return;
+ }
+
+ my $query;
if (defined $result) {
- $query = "UPDATE $table SET $key=".&dbQuote($val).
- " WHERE $primkey=".&dbQuote($primval);
+ my @keyval;
+ for(my$i=0; $i<scalar @keys; $i++) {
+ push(@keyval, $keys[$i]."=".$vals[$i] );
+ }
+
+ $query = "UPDATE $table SET ".
+ join(' AND ', @keyval).
+ " WHERE ".$where;
} else {
- $query = "INSERT INTO $table ($primkey,$key) VALUES (".
- &dbQuote($primval).",".&dbQuote($val).")";
+ foreach (keys %{$phref}) {
+ push(@keys, $_);
+ push(@vals, &dbQuote($phref->{$_}) );
+ }
+
+ $query = sprintf("INSERT INTO $table (%s) VALUES (%s)",
+ join(',',@keys), join(',',@vals) );
}
&dbRaw("Set", $query);
} elsif ($param{'DBType'} =~ /^dbm$/i) {
&status(" using Berkeley DBM 1.85/2.0 support.");
- require "$bot_src_dir/db_dbm.pl";
+ &ERROR("dbm support is broken... you want it, you fix it!");
+ &shutdown();
+ exit 1;
+
+# require "$bot_src_dir/db_dbm.pl";
} else {
&status("DB support DISABLED.");