\& | Product | \&SK/b | \&Stock | \&@@ -120,6 +121,11 @@ .Ve .Vb 10 \&
\&+ [if file images/thumb/[item-field thumb]] \&+ \&+ [/if] \&+ | \&+\& \& [item-description] \& | .Ve .Sh "How do I do a random display of items?" .IX Subsection "How do I do a random display of items?" (Answered by Bill Carr) .PP If you are using mysql (and others probably), you should be able to add \*(L"\s-1ORDER\s0 \s-1BY\s0 \fIRAND()\fR\*(R" to your \s-1SQL\s0 query. For example: .PP .Vb 8 \& [query \& list=1 \& sql=|SELECT * FROM products ORDER BY RAND() LIMIT 3| \&] \&[list] \& [sql-param description]||
[loop-code] | \& [loop-alternate 3]
.Ve .Vb 12 \& if scratch compare: \& [benchmark start=1] \& .Ve .Vb 2 \& [benchmark] \&
.Ve .Vb 14 \& if scratch compare eq 1: \& [benchmark start=1] \& \& [benchmark] \&
.Ve
.Vb 1
\& [page @@MV_PAGE@@]Again
.Ve
.Vb 1
\& ---- end test ---
.Ve
.Ip "\(bu" 4
Use [PREFIX-calc] instead of [calc] or [perl]
.PP
You can execute the same code as [calc] with [PREFIX-calc], which has
two benefits:
.Ip "11." 4
.IX Item "11."
It doesn't require \s-1ITL\s0 parsing.
.Ip "12." 4
.IX Item "12."
It is executed during the loop instead of after it.
.PP
The [PREFIX-calc] object has complete access to all normal embedded
Perl objects like \f(CW$Values\fR, \f(CW$Carts\fR, \f(CW$Tag\fR, and such. If you want to make
a data table (i.e. \*(L"products\*(R" or \*(L"pricing\*(R") available for access
inside of it, just do:
.PP
.Vb 1
\& [perl tables="products pricing"] [/perl]
.Ve
prior to list start. Now you can do something like:
.PP
.Vb 7
\& [loop search="ra=yes"]
\& [loop-calc]
\& $desc = $Tag->data('products', 'description', '[loop-code]');
\& $link = $Tag->page('[loop-code]');
\& return "$link $desc ";
\& [/loop-calc]
\& [/loop]
.Ve
.Ip "\(bu" 4
\&\s-1ADVANCED:\s0 Precompile and execute with [PREFIX-sub] and [PREFIX-exec]
.PP
For repetitive routines, you can achieve a considerable savings in \s-1CPU\s0
by pre-compiling your embedded Perl code.
.PP
In the \*(L"Construct Something\*(R" demo, the \fIbar_link()\fR routine in
catalog_before.cfg is an example of compiling the subroutine once at
catalog configuration time.
.PP
You can also compile routines at the time of the list execution with
[item-sub routine] \s-1CODE\s0 [/item-sub]. This means only one Safe
evaluation is done \*(-- every time the [loop-exec routine] is called, it
is done fast as a call to the routine. This can be 10 times or more
faster than separate [calc] calls, or 5 times faster than separate
[PREFIX-calc] calls.
.Ip "" 4
Example:
.Sp
.Vb 1
\& [benchmark start=1]
.Ve
.PP
.Vb 1
\& [benchmark]
.Ve
.Vb 1
\&
.Ve
.Vb 11
\& [benchmark start=1]
\& loop-sub and loop-exec:
\&
.Ve
.Vb 1
\& [benchmark]
.Ve
.Ip "\(bu" 4
\&\s-1ADVANCED:\s0 Execute and save with [query ...], then use an embedded Perl
routine.
.PP
You can run [query arrayref=myref sql=\*(L"query\*(R"], which saves the
results of the search/query in a Perl reference. It is then available
in \f(CW$Tmp\fR->{myref}. (Of course, \*(L"myref\*(R" can be any arbitrary name.)
.PP
This is the fastest possible method to display a list.
.Ip "" 4
Observe:
.Sp
.Vb 1
\& --- begin test code ---
.Ve
.PP
.Vb 5
\& [benchmark start=1] Embedded Perl
\&
\& [/query]
.Ve
.Vb 15
\& [perl]
\& # Get the query results, has multiple fields
\& my $ary = $Tmp->{myref};
\& my $out = '';
\& foreach $line (@$ary) {
\& my ($sku, $price, $desc) = @$line;
\& if($sku eq $Scratch->{waiting_for}) {
\& $out .= "We were waiting for this one!!!!\en";
\& }
\& $out .= "sku: $sku price: $price description: $desc\en";
\& }
\& return $out;
\& [/perl]
\& -->
\& TIME: [benchmark]
.Ve
.Vb 11
\& [benchmark start=1] All loop
\&
.Ve
.Vb 1
\& TIME: [benchmark]
.Ve
.Vb 1
\& --- end test code ---
.Ve
.Ip "\(bu" 4
Other things that help:
.RS 4
.Ip "\(bu" 8
Avoid interpolate=1 when possible. A separate tag parser must be
spawned every time you do this. Many times people use this without
needing it.
.Ip "\(bu" 8
Avoid saving large values to Scratch, as these have to be written to
the users session. If you need them only for the current page, clear
at the end by using [tmp scratch_var] contents [/tmp], which is the
same as [seti scratch_var] contents [/seti] except clears the value
before the session is written. You can also use [scratchd scratch_var]
to return the contents and delete them from the session at the same
time.
.Ip "\(bu" 8
Use the [more-list] facility to break up your large searches. You can
use them in [query ....] and [loop ...] searches as well \*(-- see the
docs.
.RE
.RS 4
.RE
.SH "Using Interchange with Oracle"
.IX Header "Using Interchange with Oracle"
Question: should we be using the \s-1DBI\s0 ChopBlanks setting for Oracle or
is Interchange trimming trailing space from \s-1CHAR\s0 fields itself?
.PP
\&\s-1IC\s0 daemon user should have environment variables \s-1ORACLE_HOME\s0 and
possibly \s-1NLS_LANG\s0 set.
.PP
Mark Johnson (mark@endpoint.com) wrote this trigger on \s-1TABLE_NAME\s0 to
update the \s-1MOD_TIME\s0 column on insert or update. The user must have
been granted the \s-1RESOURCE\s0 role to create triggers. Here it is:
.PP
\&\s-1CREATE\s0 \s-1TRIGGER\s0 tr_modtime_for_TABLE_NAME \s-1BEFORE\s0 \s-1INSERT\s0 \s-1OR\s0 \s-1UPDATE\s0 \s-1ON\s0
\&\s-1TABLE_NAME\s0 \s-1FOR\s0 \s-1EACH\s0 \s-1ROW\s0 \s-1BEGIN\s0
.PP
new.MOD_TIME := \s-1SYSDATE\s0; \s-1END\s0; /
.SH "Using Interchange with PostgreSQL"
.IX Header "Using Interchange with PostgreSQL"
Make sure you have \s-1DBD:\s0:Pg installed and tested. Make sure
\&\s-1POSTGRES_INCLUDE\s0 and \s-1POSTGRES_LIB\s0 environment variables are set.
.SH "Using Interchange with MySQL"
.IX Header "Using Interchange with MySQL"
Permissions. test_ databases usually special.
.SH "Using Interchange with Apache"
.IX Header "Using Interchange with Apache"
Slightly modified article posted to the old minivend-users mail list.
Minivend-users is now interchange-users.
.PP
.Vb 4
\& Date: Thu, 7 Sep 2000 12:08:37 -0700
\&From: Bill Randle