[docs] Change in QueryTag made by Jonathan Clark

Wiki Watch docs@icdevgroup.org
Wed Jan 22 04:20:04 2003


You can visit the live page at this URL:
http://www.icdevgroup.org/i/doc/wiki/QueryTag.html

--- tmp/uKFcedHn:213.130.152.51.previous	Wed Jan 22 04:19:45 2003
+++ tmp/uKFcedHn:213.130.152.51.current	Wed Jan 22 04:19:45 2003
@@ -374,7 +374,32 @@
 
 to return references as it would if called within an ordinary
 [perl] tag. Note that it does not force list context if you call
-$Tag->query in scalar context.
+$Tag->query in scalar context. Here is another example of the use of the array references, from a UserTag:
+
+    my $sku = 'os28044';
+    my $sql = qq{select description, price from products where sku = '$sku'};
+    my $table = 'products';
+
+    my ($results, $col_name_hashref, $col_name_arrayref) = $Tag->query({
+            wantarray => 1,
+            sql => "$sql",
+            table => "$table"});
+
+    my $out;
+
+    # this will get the first field (description)..
+    $out = 'description: ' . $results->[0]->[0];
+
+    # and this the second field (price)..
+    $out .= '<br>price: ' . $results->[0]->[1];
+
+    # this will tell us the position in the $results array of the price field..
+    $out .= '<br>position of price field: ' . $col_name_hashref->{price};
+    return $out;
+
+If the [query] returns more than one row, the second row's description field would be:
+
+    $results->[1]->[0]
 
 Technical note - the ordinary [query ...] ... [/query] usage
 forces scalar context on the query call and suppresses the return