MiniVend Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

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


Search for: Match: Format: Sort by: