From 18e422274d7623ea9964ad811e97e7b1dc08ea04 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 10 Aug 2007 20:05:17 +0000 Subject: [PATCH] =?utf8?q?properties-Tabelle=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@22 191103c4-1d37-0410-b3e5-d8c2315c0aac --- lib/CookBook/Db.pm | 1 + lib/CookBook/Db/Properties.pm | 58 +++++++++++++++++++++++++ sbin/initial_import.pl | 81 +++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 lib/CookBook/Db/Properties.pm diff --git a/lib/CookBook/Db.pm b/lib/CookBook/Db.pm index e5f5eeb..a8f4708 100644 --- a/lib/CookBook/Db.pm +++ b/lib/CookBook/Db.pm @@ -28,6 +28,7 @@ __PACKAGE__->load_classes( Categories Ingredients IngredientGroups + Properties RecipeAuthors RecipeCategories RecipeIngredients diff --git a/lib/CookBook/Db/Properties.pm b/lib/CookBook/Db/Properties.pm new file mode 100644 index 0000000..0a98a40 --- /dev/null +++ b/lib/CookBook/Db/Properties.pm @@ -0,0 +1,58 @@ +package CookBook::Db::Properties; + +# $Id$ +# $URL$ + +=head1 NAME + +CookBook::Db::Properties + +=head1 DESCRIPTION + +Module for abstract database access to the table 'properties' + +=cut + +#--------------------------------------------------------------------------- + +use strict; +use warnings; + +use CookBook::Common; +use base qw/DBIx::Class/; + +__PACKAGE__->load_components( + qw/ + PK::Auto + Core + / +); + +__PACKAGE__->table('properties'); + +__PACKAGE__->add_columns( + "property_id" => { + 'data_type' => "INT", + 'default_value' => undef, + 'is_nullable' => 0, + 'size' => 10, + 'is_auto_increment' => 1, + 'extras' => { 'unsigned' => 1 }, + }, + "property_name" => { 'data_type' => "VARCHAR", 'default_value' => "", 'is_nullable' => 0, 'size' => 100 }, + "units" => { 'data_type' => "VARCHAR", 'default_value' => undef, 'is_nullable' => 1, 'size' => 30 }, + "date_created" => { 'data_type' => "DATETIME", 'default_value' => "", 'is_nullable' => 0, 'size' => 19 }, + "date_changed" => { 'data_type' => "DATETIME", 'default_value' => "", 'is_nullable' => 0, 'size' => 19 }, +); + +__PACKAGE__->set_primary_key("property_id"); +__PACKAGE__->add_unique_constraint( "property_name", ["property_name"] ); + +#---------------------------------------------------------------------------------------- + +1; + +#---------------------------------------------------------------------------------------- + +__END__ + diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl index 06db69b..2988500 100755 --- a/sbin/initial_import.pl +++ b/sbin/initial_import.pl @@ -36,6 +36,7 @@ my @target_tables = qw( yield_types unit_types units + properties categories ingredients ingredient_groups @@ -60,6 +61,7 @@ my %create_method = ( 'units' => \&create_units_table, 'categories' => \&create_categories_table, 'recipe_categories' => \&create_recipe_categories_table, + 'properties' => \&create_properties_table, ); my @import_tables = qw( @@ -67,6 +69,7 @@ my @import_tables = qw( yield_types units categories + properties ingredients ingredient_groups recipes @@ -86,6 +89,7 @@ my %import_method = ( 'recipes' => \&import_recipes_table, 'recipe_authors' => \&import_recipe_authors_table, 'recipe_ingredients' => \&import_recipe_ingredients_table, + 'properties' => \&import_properties_table, ); my $admin_data = { @@ -785,6 +789,83 @@ END_SQL #------------------------------------------------------------- +=head2 create_properties_table( ) + +=cut + +sub create_properties_table { + + my $sql = <do($sql); + return 1; + +} ## end sub create_recipe_authors_table + +#------------------------------------------------------------- + +=head2 import_categories_table( ) + +=cut + +sub import_properties_table { + + my $sql = <prepare($sql) ) { + return undef; + } + + return undef unless $source_sth->execute(); + + $sql = <prepare($sql); + unless ($target_sth) { + $source_sth->finish(); + return undef; + } + + while ( $prop = $source_sth->fetchrow_hashref() ) { + + next unless $prop->{'name'}; + + $qparams = []; + push @$qparams, $prop->{'id'}; + push @$qparams, $prop->{'name'}; + push @$qparams, $prop->{'units'}; + + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } + + } ## end while ( $ingr = $source_sth->fetchrow_hashref... + + return 1; + +} ## end sub import_ingredients_table + +#------------------------------------------------------------- + =head2 create_session_table( ) =cut -- 2.39.5