[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
RE: Retrieving database field names.
****** message to minivend-users from "Yossi Cohen" <YOSSI@prodigy.net> ******
Hi Mike, Frank, All,
I was overwhelmed to receive two possible responses. Frank's suggestion was
probably great except that I didn't understand much about the trapping issue
plus I opted for a generic solution. So I took Mike's contribution to
include UserTag dbinfo in minivend.cfg. At first, I was quite helpless, as
it didn't work for me. But then (quite surprisingly) I found there's a small
bug in the code:
if($opt->{storage}) {
my $string = $db;
$string =~ s/.*::(\w+).*/; <=== I believe it should have been
$string =~ s/.*::(\w+).*//;
return $1;
}
So I added the extra slash, and fixed the initial problem with not being
able to parse that UserTag.
Then I went on to try it:
<TABLE Border=0>
<TR><TH>code</TH><TH>[dbinfo table=products columns=1
joiner="</TH><TH>"]</TH></TR>
[tag each products]
<TR><TD>[loop-code]</TD>
[loop with="-a" arg="[dbinfo table=products columns=1 joiner=' ']"]
<TD>[loop-field [loop-code-a]]</TD> <!-- Persumably getting back
[loop-field title], etc..-->
[/loop]
</TR>
[/tag]
</TABLE>
The purpose of the above code was to display the products database in a
table form without the necessity to know up front the field names.
Unfortunately, only the table header was successfully printed. Any attempt
to display the contents of the other database fields failed.
I simply could not get the [loop-field [loop-code-a]] to be interpolated at
all.
Please advise.
Sincerely,
Yossi
-----Original Message-----
From: owner-minivend-users@minivend.com
[mailto:owner-minivend-users@minivend.com]On Behalf Of
mikeh@minivend.com
Sent: Tuesday, February 23, 1999 3:47 AM
To: minivend-users@minivend.com
Subject: Re: Retrieving database field names.
****** message to minivend-users from mikeh@minivend.com ******
Quoting Yossi Cohen (yossi@prodigy.net):
>
> Hi everybody,
>
> Just wondered whether any one bumped into trying to retrieve database
field
> names using minivend tags. I am trying to display the products table in a
> web form for administration purposes and where the columns heading would
be
> the field names.
>
> As usual I will be very glad to even get No as an answer. ;-)
>
In response to the suggestion from the list (sorry, I couldn't find who
made it), we are going to add a UserTag repository with editable entries
at Minivend.com -- we have already started work on it. Here will be one
of my contributions:
# Return some info about a database
# Goes in minivend.cfg, not catalog.cfg
#
# This REQUIRES MiniVend 3.12beta4 or higher!
#
# IMPORTANT NOTE: columns don't include key column!!!!
#
# Examples:
#
# <PRE>
# columns: [dbinfo table=products columns=1 joiner="|"]
# file: [dbinfo table=products attribute=file]
# dir: [dbinfo table=products attribute=dir]
# INDEX: [dbinfo table=products attrib=INDEX]
# CONTINUE: [dbinfo table=products attrib=CONTINUE]
# path to db: [dbinfo db=products attr=dir]/[dbinfo db=products attr=file]
# exists category: [dbinfo db=products column_exists=category]
# exists nevairbe: [dbinfo db=products column_exists=nevairbe No="Nope."]
# exists 00-0011: [dbinfo
# db=products
# record_exists="00-0011"
# YES="Yup."
# No="Nope."]
# exists 00-0000: [dbinfo
# db=products
# record_exists="00-0000"
# yes="Yup."
# no="Nope."]
#
# </PRE>
#
UserTag dbinfo Order table
UserTag dbinfo addAttr
UserTag dbinfo attrAlias base table
UserTag dbinfo attrAlias db table
UserTag dbinfo Routine <<EOR
sub {
my ($table, $opt) = @_;
sub _die {
$Vend::Session->{failure} .= shift;
return;
}
my $db_obj = $Vend::Cfg->{Database}{$table}
|| return _die("Table '$table' does not exist\n");
# attributes are: (case matters)
#
# CONTINUE dir EXCEL file INDEX MEMORY type
#
if($opt->{attribute} or $opt->{attribute} = $opt->{attrib} ||
$opt->{attr}) {
return $db_obj->{$opt->{attribute}};
}
# SQL only....
# COLUMN_DEF, NUMERIC, NAME
#
if($opt->{attribute_ref}) {
return Vend::Util::uneval($db_obj->{$opt->{attribute_ref}});
}
my $db = Vend::Data::database_exists_ref($table)
|| return _die("Table '$table' does not exist\n");
$db = $db->ref();
if($opt->{storage}) {
my $string = $db;
$string =~ s/.*::(\w+).*/;
return $1;
}
# doesn't include first column!
return join (($opt->{joiner} || "\n"), $db->columns())
if($opt->{columns});
if($opt->{column_exists}) {
return defined $db->test_column($opt->{column_exists})
? ($opt->{yes} || 1)
: ($opt->{no} || '');
}
if($opt->{record_exists}) {
return $db->record_exists($opt->{record_exists})
? ($opt->{yes} || 1)
: ($opt->{no} || '');
}
return;
}
EOR
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
Fast, reliable, cheap. 131 Willow Lane, Floor 2 | || _ \
Pick two and we'll talk. Oxford, OH 45056 | || |_) |
-- unknown <mikeh@minivend.com> |___| _ <
513.523.7621 FAX 7501 |_| \_\
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to
Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list