--- /dev/null
+
+-- $Id$
+-- $URL$
+
+
+CREATE OR REPLACE VIEW v_buchliste AS
+SELECT `buch_id`,
+ `title`,
+ `title_original`,
+ `untertitel`,
+ `verlag`,
+ `isbn`,
+ `buch_nr`,
+ `ausgabejahr`,
+ `druckjahr`,
+ `seiten`,
+ `preis`,
+ `waehrungs_kuerzel`,
+ `waehrung`,
+ `ort`,
+ `bindungsart`,
+ GROUP_CONCAT( DISTINCT `autor_id` SEPARATOR ', ' ) AS `autor_ids`,
+ GROUP_CONCAT( DISTINCT `autor_name` ORDER BY `autor_ord_num` SEPARATOR ', ' ) AS `autoren`,
+ GROUP_CONCAT( DISTINCT `kategorie_id` SEPARATOR ', ' ) AS `kategorie_ids`,
+ GROUP_CONCAT( DISTINCT `kategorie` ORDER BY `kategorie` SEPARATOR ', ' ) AS `kategorien`,
+ GROUP_CONCAT( DISTINCT `serien_id` SEPARATOR ', ' ) AS `serien_ids`,
+ GROUP_CONCAT( DISTINCT `serie` ORDER BY `serie` SEPARATOR ', ' ) AS `serien`
+ FROM ( SELECT b.`id` AS `buch_id`,
+ b.`title` AS `title`,
+ b.`title_original` AS `title_original`,
+ b.`untertitel` AS `untertitel`,
+ b.`isbn` AS `isbn`,
+ b.`buch_nr` AS `buch_nr`,
+ b.`ausgabejahr` AS `ausgabejahr`,
+ b.`druckjahr` AS `druckjahr`,
+ b.`seiten` AS `seiten`,
+ b.`preis` AS `preis`,
+ w.`waehrungs_kuerzel` AS `waehrungs_kuerzel`,
+ w.`waehrungs_name` AS `waehrung`,
+ CONCAT( '`', a.`nachname`,
+ IF( ISNULL(a.`vorname`), '', ' ' ), IFNULL( a.`vorname`, '' ),
+ IF( ISNULL(a.`mittelname`), '', ' ' ), IFNULL( a.`mittelname`, '' ),
+ IF( ISNULL(a.`name_suffix`), '', ' ' ), IFNULL( a.`name_suffix`, '' ),
+ '`'
+ ) AS `autor_name`,
+ ab.`ord_num` AS `autor_ord_num`,
+ CONCAT( '`', a.`id`, '`' ) AS `autor_id`,
+ a.`titel` AS `autor_titel`,
+ a.`vorname` AS `autor_vorname`,
+ a.`mittelname` AS `autor_mittelname`,
+ a.`nachname` AS `autor_nachname`,
+ a.`name_suffix` AS `autor_name_suffix`,
+ v.`name_short` AS `verlag`,
+ o.`name` AS `ort`,
+ CONCAT( '`', k.`id`, '`' ) AS `kategorie_id`,
+ CONCAT( '`', k.`kategorie_name`, '`' ) AS `kategorie`,
+ CONCAT( '`', s.`id`, '`' ) AS `serien_id`,
+ CONCAT( '`', s.`serien_name`, '`' ) AS `serie`,
+ bi.`art_name` AS `bindungsart`
+ FROM autor2buch AS ab
+ LEFT JOIN `autoren` a ON ab.`autor_id` = a.`id`
+ RIGHT JOIN `buecher` b ON ab.`buch_id` = b.`id`
+ LEFT JOIN `bindungsarten` bi ON b.`bindungsart_id` = bi.`id`
+ LEFT JOIN `verlage` v ON b.`verlags_id` = v.`id`
+ LEFT JOIN `orte` o ON b.`orts_id` = o.`id`
+ LEFT JOIN `waehrungen` w ON b.`waehrungs_id` = w.`id`
+ LEFT JOIN `buch2kategorie` bk ON b.`id` = bk.`buch_id`
+ LEFT JOIN `kategorien` k ON k.`id` = bk.`kategorie_id`
+ LEFT JOIN `buch2serie` bs ON b.`id` = bs.`buch_id`
+ LEFT JOIN `serien` s ON s.`id` = bs.`serien_id`
+ ) AS `a`
+GROUP BY `buch_id`;
+
+-- vim: noai : ts=4 fenc=utf-8 filetype=sql expandtab :
+
$storage->sql_maker->quote_char( [qw/` `/] );
$storage->sql_maker->name_sep('.');
+ my $SQL = "SET NAMES 'utf8'";
+ warn $SQL . ";\n" if $storage->debug();
+
+ $storage->dbh_do(
+ sub {
+ my ( $storage_a, $dbh ) = @_;
+ $dbh->do($SQL);
+ }
+ );
+
$c->session->{'last_run'} = localtime();
# Letzten und aktuellen Pfad behalten
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yMIjCo2VODRuy9VqS1AeQA
# You can replace this text with custom content, and it will be preserved on regeneration
+#--------------------------------------------------------------------------
+
+sub connect {
+
+ my $schema = DBIx::Class::Schema::connect(@_);
+
+ return undef unless $schema;
+
+ $schema->storage->sql_maker->quote_char( [qw/` `/] );
+ $schema->storage->sql_maker->name_sep('.');
+
+ my $SQL = "SET NAMES 'utf-8'";
+ warn $SQL . ";\n" if $schema->storage->debug();
+ warn $SQL . ";\n";
+
+ $schema->storage->dbh_do(
+ sub {
+ my ( $storage, $dbh ) = @_;
+ $dbh->do($SQL);
+ }
+ );
+
+ return $schema;
+
+}
+
+#--------------------------------------------------------------------------
+
1;
__END__
--- /dev/null
+package FrBr::Books::Db::BuchListe;
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class';
+
+__PACKAGE__->load_components("Core");
+
+__PACKAGE__->table("NONE");
+
+__PACKAGE__->add_columns(
+ "id",
+ "title",
+ "title_original",
+ "untertitel",
+ "verlag",
+ "isbn",
+ "buch_nr",
+ "ausgabejahr",
+ "druckjahr",
+ "seiten",
+ "preis",
+ "waehrungs_kuerzel",
+ "waehrung",
+ "ort",
+ "bindungsart",
+ "autor_ids",
+ "autoren",
+ "kategorie_ids",
+ "kategorien",
+ "serien_ids",
+ "serien",
+);
+
+__PACKAGE__->result_source_instance()->name( \<<SQL );
+( SELECT `id`,
+ `title`,
+ `title_original`,
+ `untertitel`,
+ `verlag`,
+ `isbn`,
+ `buch_nr`,
+ `ausgabejahr`,
+ `druckjahr`,
+ `seiten`,
+ `preis`,
+ `waehrungs_kuerzel`,
+ `waehrung`,
+ `ort`,
+ `bindungsart`,
+ GROUP_CONCAT( DISTINCT `autor_id` SEPARATOR ', ' ) AS `autor_ids`,
+ GROUP_CONCAT( DISTINCT `autor_name` ORDER BY `autor_ord_num` SEPARATOR ', ' ) AS `autoren`,
+ GROUP_CONCAT( DISTINCT `kategorie_id` SEPARATOR ', ' ) AS `kategorie_ids`,
+ GROUP_CONCAT( DISTINCT `kategorie` ORDER BY `kategorie` SEPARATOR ', ' ) AS `kategorien`,
+ GROUP_CONCAT( DISTINCT `serien_id` SEPARATOR ', ' ) AS `serien_ids`,
+ GROUP_CONCAT( DISTINCT `serie` ORDER BY `serie` SEPARATOR ', ' ) AS `serien`
+ FROM ( SELECT b.`id` AS `id`,
+ b.`title` AS `title`,
+ b.`title_original` AS `title_original`,
+ b.`untertitel` AS `untertitel`,
+ b.`isbn` AS `isbn`,
+ b.`buch_nr` AS `buch_nr`,
+ b.`ausgabejahr` AS `ausgabejahr`,
+ b.`druckjahr` AS `druckjahr`,
+ b.`seiten` AS `seiten`,
+ b.`preis` AS `preis`,
+ w.`waehrungs_kuerzel` AS `waehrungs_kuerzel`,
+ w.`waehrungs_name` AS `waehrung`,
+ CONCAT( '`', a.`nachname`,
+ IF( ISNULL(a.`vorname`), '', ' ' ), IFNULL( a.`vorname`, '' ),
+ IF( ISNULL(a.`mittelname`), '', ' ' ), IFNULL( a.`mittelname`, '' ),
+ IF( ISNULL(a.`name_suffix`), '', ' ' ), IFNULL( a.`name_suffix`, '' ),
+ '`'
+ ) AS `autor_name`,
+ ab.`ord_num` AS `autor_ord_num`,
+ CONCAT( '`', a.`id`, '`' ) AS `autor_id`,
+ a.`titel` AS `autor_titel`,
+ a.`vorname` AS `autor_vorname`,
+ a.`mittelname` AS `autor_mittelname`,
+ a.`nachname` AS `autor_nachname`,
+ a.`name_suffix` AS `autor_name_suffix`,
+ v.`name_short` AS `verlag`,
+ o.`name` AS `ort`,
+ CONCAT( '`', k.`id`, '`' ) AS `kategorie_id`,
+ CONCAT( '`', k.`kategorie_name`, '`' ) AS `kategorie`,
+ CONCAT( '`', s.`id`, '`' ) AS `serien_id`,
+ CONCAT( '`', s.`serien_name`, '`' ) AS `serie`,
+ bi.`art_name` AS `bindungsart`
+ FROM autor2buch AS ab
+ LEFT JOIN `autoren` a ON ab.`autor_id` = a.`id`
+ RIGHT JOIN `buecher` b ON ab.`buch_id` = b.`id`
+ LEFT JOIN `bindungsarten` bi ON b.`bindungsart_id` = bi.`id`
+ LEFT JOIN `verlage` v ON b.`verlags_id` = v.`id`
+ LEFT JOIN `orte` o ON b.`orts_id` = o.`id`
+ LEFT JOIN `waehrungen` w ON b.`waehrungs_id` = w.`id`
+ LEFT JOIN `buch2kategorie` bk ON b.`id` = bk.`buch_id`
+ LEFT JOIN `kategorien` k ON k.`id` = bk.`kategorie_id`
+ LEFT JOIN `buch2serie` bs ON b.`id` = bs.`buch_id`
+ LEFT JOIN `serien` s ON s.`id` = bs.`serien_id`
+ ) AS `a`
+ GROUP BY `id`
+)
+SQL
+
+1;
+
+__END__
+
+# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :
__PACKAGE__->has_many( 'buch_serie' => 'FrBr::Books::Db::Buch2serie', { 'foreign.buch_id' => 'self.id' } );
__PACKAGE__->many_to_many( 'serien' => 'buch_serie', 'serie' );
+=pod
+
# Make a new ResultSource based on the buecher class
my $source = __PACKAGE__->result_source_instance();
my $list_source = $source->new( $source );
-$list_source->source_name( 'BuecherListe' );
+$list_source->source_name( 'BuchListe' );
# Hand in your query as a scalar reference
# It will be added as a sub-select after FROM,
# so pay attention to the surrounding brackets!
$list_source->name( \<<SQL );
-( SELECT `buch_id`,
+( SELECT `id`,
`title`,
`title_original`,
`untertitel`,
GROUP_CONCAT( DISTINCT `kategorie` ORDER BY `kategorie` SEPARATOR ', ' ) AS `kategorien`,
GROUP_CONCAT( DISTINCT `serien_id` SEPARATOR ', ' ) AS `serien_ids`,
GROUP_CONCAT( DISTINCT `serie` ORDER BY `serie` SEPARATOR ', ' ) AS `serien`
- FROM ( SELECT b.`id` AS `buch_id`,
+ FROM ( SELECT b.`id` AS `id`,
b.`title` AS `title`,
b.`title_original` AS `title_original`,
b.`untertitel` AS `untertitel`,
LEFT JOIN `buch2serie` bs ON b.`id` = bs.`buch_id`
LEFT JOIN `serien` s ON s.`id` = bs.`serien_id`
) AS `a`
- GROUP BY `buch_id`
+ GROUP BY `id`
)
SQL
# Finally, register your new ResultSource with your Schema
-FrBr::Books::Db->register_source( 'BuecherListe' => $list_source );
+FrBr::Books::Db->register_source( 'BuchListe' => $list_source );
+=cut
1;
# $URL$
use strict;
+use warnings;
use base 'Catalyst::Model::DBIC::Schema';
__PACKAGE__->config(
],
);
-sub setup {
-
- my $c = shift;
- my $K = ( caller(0) )[3] . "(): ";
- $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
- warn $K . "aufgerufen.\n";
-
- $c->NEXT::setup(@_);
-
- return $c;
-}
+#sub setup {
+#
+# my $c = shift;
+# my $K = ( caller(0) )[3] . "(): ";
+# $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+# warn $K . "aufgerufen.\n";
+#
+# $c->NEXT::setup(@_);
+#
+# return $c;
+#}
=head1 NAME
'untertitel',
'isbn',
];
- for my $ref ( $c->model('Schema::Autor2buch')->search( $search_params, $other_params )->all() ) {
+ $c->log->debug( get_output_string( $K, "Suchparameter: ", $search_params ) ) if $c->stash->{'debug_level'} >= 2;
+ $c->log->debug( get_output_string( $K, "Andere Parameter: ", $other_params ) ) if $c->stash->{'debug_level'} >= 2;
+ my $uhu = $c->model('Schema');
+ #$c->log->debug( get_output_string( $K, "Datenquelle: ", $uhu ) ) if $c->stash->{'debug_level'} >= 2;
+ #for my $ref ( $c->model('Schema::Autor2buch')->search( $search_params, $other_params )->all() ) {
+ for my $ref ( $c->model('Schema')->resultset('Autor2buch')->search( $search_params, $other_params )->all() ) {
my $buch = {};
my $order = undef;
if ( $params->{'buch_id'} ) {
- $b_search_params->{'me.buch_id'} = $params->{'buch_id'};
+ $b_search_params->{'me.id'} = $params->{'buch_id'};
}
else {
$order = collect_sort_criteria($c)
# Anzahl der Buecher insgesamt (ohne paginierung) ermitteln
my $other_params = {};
$other_params->{'order_by'} = $order;
- $other_params->{'select'} = [ 'me.buch_id' ];
- $other_params->{'as'} = [ 'buch_id' ];
+ $other_params->{'select'} = [ 'me.id' ];
+ $other_params->{'as'} = [ 'id' ];
- $anzahl_buecher = $c->model('Schema::BuecherListe')->count( $b_search_params, $other_params );
+ $anzahl_buecher = $c->model('Schema::BuchListe')->count( $b_search_params, $other_params );
$c->log->debug( get_output_string( $K, "Anzahl gefundene Buecher: ", $anzahl_buecher ) ) if $c->stash->{'debug_level'} >= 2;
$other_params->{'rows'} = $c->stash->{'list_length'} || 20;
my $book_ids = [];
- for my $book ( $c->model('Schema::BuecherListe')->search( $b_search_params, $other_params )->all() ) {
- push @$book_ids, $book->get_column('buch_id');
+ for my $book ( $c->model('Schema::BuchListe')->search( $b_search_params, $other_params )->all() ) {
+ push @$book_ids, $book->get_column('id');
}
return ( wantarray ? ( $book_ids, 0 ) : $book_ids ) unless scalar( @$book_ids );