[ic] Array from [perl]

Mike Heins mikeh@minivend.com
Tue, 19 Dec 2000 18:53:57 -0500


Quoting Kaare Rasmussen (kar@webline.dk):
> > That I *know* is documented. [query ....] [/query] is what it is.
> 
> Sorry; can't see it! 
> 
> Been through all pages where I can find any reference to [query] and can't 
> find any reference to any array variable it will go through.
> 
> I've changed the subject to make it clearer that I'm no longer asking about a 
> database. I was hoping for something like 
> 
> [perl]
> ...
>  $Scratch->{ary} =  $db->query($q)
> [/perl]
> 
> [loop list="[scratch ary]"]
>  [loop-data fieldname] or 
>  [loop-pos 0]
> ... or the like. But [scratch ary] doesn't dereference to the array.

But that is what query is. I myself can't find the reference, so I am
answering here:

[query list=1 prefix=loop sql="select foo, bar from products"]
    [loop-data table field]
    [loop-pos 0]
    [loop-param foo]
    [loop-param bar]
    [loop-field price]
    [loop-price]
[/query]

It all works. The default prefix is actually "sql", but you can change
it to loop if you want. 8-)

All lists in Interchange are the same. Same accessors; they all return
arrays of arrays, and are accessed by the above tags and their friends.
So these are pretty much all the same:

    [loop
		more=1
		search="
		    fi=products
		    st=db
		    ra=yes
		    ml=10
		    rf=foo,bar
		"]
    [list]
	    [loop-param foo]
    [/list]
    [more-list]
	[more]
    [/more-list]
    [/loop]

The [list] [/list] surrounds the list so you can use [more-list] with
the more=1 parameter.

    [query
	prefix=loop
	list=1
	more=1
	ml=10
	sql="select foo, bar from products"]
    [list]
	    [loop-param foo]
    [/list]
    [more-list]
	[more]
    [/more-list]
    [/query]

Again, this accepts more=1, and you set the match limit with ml=10
as an argument.

    [search-region
	    prefix=loop
	    arg="
		    fi=products
		    st=db
		    ra=yes
		    ml=10
		    rf=foo,bar
	    "]
    [search-list]
	    [loop-param foo]
    [/search-list]
    [more-list]
	[more]
    [/more-list]
    [/search-region]

All will take a [more-list], a [no-match], [on-match], etc. They all
use the same routine for display. They all can change the prefix of the
accessor tags with prefix=foo.

The arguments to select the results and the default prefixes are different
due to history and for backward compatiblilty.

I think I need to do another tips and tricks...maybe I can write it over
the holidays. 8-)

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

Function in chaos, finish in style. -- Unknown