[ic] Array from database

Mike Heins mikeh@minivend.com
Tue, 19 Dec 2000 13:19:31 -0500

Quoting Mike Heins (mikeh@minivend.com):
> Quoting Kaare Rasmussen (kar@webline.dk):
> > I'd like to fill an array with the values of my order lines. After messing 
> > around for some time, I'm in doubt.
> > 
> > Seems to be best to do in perl. But all options seem a bit flawed, so which 
> > is best?
> > - $tag->data can only handle one row (??)
> > - %db may be better, but the key has to be named "code" (??)
> > - %sql gives you all the power, but is more complex.
> > - More?
> Why do you say that $Db{table} is not it?
> 	[perl tables=products]
> 		my $db = $Db{products} 
> 			or return "NO products?";
> 		my $q = "select foo, bar from products where buz = 'baz'";
> 		my $ary = $db->query($q)
> 			or die "query failed";

To follow up, I forgot to mention that this will only work when you
have a SQL table (and a SQL products table). That is why when you see
similar stuff in the demo it is like:

    [query arrayref=foo sql="select foo, bar from products where buz = 'baz'"]

    [perl tables=products]
	my $ary = $Tmp->{foo};

	# After that it is the same, except no name hash or array
	foreach $row (@$ary) { .... }

That is because you cannot call SQL::Statement without creating
objects at time of query parse. Safe doesn't like that.

Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH  45056
phone +1.513.523.7621 fax 7501 <heins@akopia.com>

If you like what you're gettin', keep doin' what you're doin'. -- Hector