]> git.donarmstrong.com Git - infobot.git/commitdiff
- clean up where stuff.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Thu, 28 Nov 2002 12:20:03 +0000 (12:20 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Thu, 28 Nov 2002 12:20:03 +0000 (12:20 +0000)
- added sqlSelectColArray() - not used yet.
- sqlSelectColHash now supports $other.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@715 c11ca15a-4712-0410-83d8-924469b57eb5

blootbot/src/dbi.pl

index 893d80aba79d9bb0c8869b5f30fb64342edcd815..cd2bd353cede37fb915ceb1c4c6302ea17344b31 100644 (file)
@@ -88,9 +88,11 @@ sub sqlSelectMany {
        return;
     }
 
-    my $where = ($where_href) ? &hashref2where($where_href) : "";
-    $query .= " WHERE $where"  if ($where);
-    $query .= "$other"         if $other;
+    if ($where_href) {
+       my $where = &hashref2where($where_href);
+       $query .= " WHERE $where" if ($where);
+    }
+    $query .= " $other"                if $other;
 
     if (!($sth = $dbh->prepare($query))) {
        &ERROR("sqlSelectMany: prepare: $DBI::errstr");
@@ -130,13 +132,33 @@ sub sqlSelect {
 }
 
 #####
-#  Usage: &sqlSelectColHash($table, $select, [$where_href], [$type]);
+#  Usage: &sqlSelectColArray($table, $select, [$where_href], [$other]);
+# Return: array.
+sub sqlSelectColArray {
+    my $sth    = &sqlSelectMany(@_);
+    my @retval;
+
+    if (!defined $sth) {
+       &WARN("sqlSelect failed.");
+       return;
+    }
+
+    while (my @row = $sth->fetchrow_array) {
+       push(@retval, $row[0]);
+    }
+    $sth->finish;
+
+    return @retval;
+}
+
+#####
+#  Usage: &sqlSelectColHash($table, $select, [$where_href], [$other], [$type]);
 # Return: type = 1: $retval{ col2 }{ col1 } = 1;
 # Return: no  type: $retval{ col1 } = col2;
 #   Note: does not support $other, yet.
 sub sqlSelectColHash {
-    my ($table, $select, $where_href, $type) = @_;
-    my $sth    = &sqlSelectMany($table, $select, $where_href);
+    my ($table, $select, $where_href, $other, $type) = @_;
+    my $sth    = &sqlSelectMany($table, $select, $where_href, $other);
     if (!defined $sth) {
        &WARN("sqlSelectColhash failed.");
        return;
@@ -212,15 +234,14 @@ sub sqlSet {
        return;
     }
 
-    my $k = (keys %{ $where_href })[0];
+    # any column can be NULL... so just get them all.
+    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);
 
     if (1 or defined $result) {
        &sqlUpdate($table, $data_href, $where_href);
     } else {
-       &DEBUG("doing insert...");
-
        # hack.
        my %hash = %{ $where_href };
        # add data_href values...
@@ -379,7 +400,6 @@ sub sqlRawReturn {
        return 0;
     }
 
-
     while (my @row = $sth->fetchrow_array) {
        push(@retval, $row[0]);
     }