From 3cc53150f61a681537d85a3982b7e56bbb721098 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 13 Apr 2003 21:17:39 +0000 Subject: [PATCH] buildHashRef can now generate complex keys. --- lib/WebGUI/SQL.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index 780c8ab42..cc3073c5c 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -148,7 +148,7 @@ Builds a hash of data from a series of rows. =item sql -An SQL query. The query must select only two columns of data, the first being the key for the hash, the second being the value. +An SQL query. The query must select at least two columns of data, the first being the key for the hash, the second being the value. If the query selects more than two columns, then the last column will be the value and the remaining columns will be joined together by an underscore "_" to form a complex key. =item dbh @@ -163,7 +163,9 @@ sub buildHash { tie %hash, "Tie::IxHash"; $sth = WebGUI::SQL->read($_[1],$_[2]); while (@data = $sth->array) { - $hash{$data[0]} = $data[1]; + my $value = pop @data; + my $key = join("_",@data); + $hash{$key} = $value; } $sth->finish; return %hash; @@ -180,7 +182,7 @@ Builds a hash reference of data from a series of rows. =item sql -An SQL query. The query must select only two columns of data, the first being the key for the hash, the second being the value. +An SQL query. The query must select at least two columns of data, the first being the key for the hash, the second being the value. If the query selects more than two columns, then the last column will be the value and the remaining columns will be joined together by an underscore "_" to form a complex key. =item dbh