| MetaStore documentation | view source | Contained in the MetaStore distribution. |
MetaStore::Cmetatags - class for collections of data, stored in database.
use MetaStore::Cmetatags;
my $props = new MetaStore::Cmetatags::
dbh => $dbh,
table => 'metatags',
field => 'mid';
Class for collections of data, stored in database.
usage:
_get_ids_by_attr({
__class=>'_metastore_user',
login=>'test'
})
=cut
sub _get_ids_by_attr { my $self = shift; my ( $attr, %opt ) = @_; my $dbh = $self->_dbh; my $table_name = $self->_table_name(); my $where = join " or ", map { '( tname in (' . $dbh->quote($_) . ') and tval LIKE (' . $dbh->quote( $attr->{$_} ) . ') )' } keys %$attr; my $count = scalar keys %$attr; my $sql = qq/ select mid from $table_name where $where group by mid HAVING ( count(*) = $count)/; if ( my $orderby = $opt{orderby} ) { $sql = qq/ select mid, tval from $table_name where tname like ('$orderby') and mid in ( $sql ) order by tval /; $sql .= ' DESC' if $opt{desc}; } if ( my $page = $opt{page} and my $onpage = $opt{onpage} ) { $sql .= " limit " . ( ( $page - 1 ) * $onpage ) . ",$onpage"; } my $qrt = $self->_query_dbh($sql); my %res = (); while ( my $rec = $qrt->fetchrow_hashref ) { $res{ $rec->{mid} }++; } $qrt->finish; return [ keys %res ]; } 1; __END__
MetaStore, Collection, README
Zahatski Aliaksandr, <zag@cpan.org>
Copyright (C) 2005-2006 by Zahatski Aliaksandr
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
| MetaStore documentation | view source | Contained in the MetaStore distribution. |