yield_types
unit_types
units
+ unit_conversations
properties
prep_methods
categories
'prep_methods' => \&create_prep_methods_table,
'ingredient_prep_methods' => \&create_ingredient_prep_methods_table,
'ingredient_weights' => \&create_ingredient_weights_table,
+ 'unit_conversations' => \&create_unit_conversations_table,
);
my @import_tables = qw(
authors
yield_types
units
+ unit_conversations
categories
properties
prep_methods
'recipe_categories' => \&import_recipe_categories_table,
'yield_types' => \&import_yield_types_table,
'units' => \&import_units_table,
+ 'unit_conversations' => \&import_unit_conversations_table,
'ingredients' => \&import_ingredients_table,
'ingredient_groups' => \&import_ingredient_groups_table,
'ingredient_properties' => \&import_ingredient_properties_table,
#-------------------------------------------------------------
+=head2 create_unit_conversations_table( )
+
+=cut
+
+sub create_unit_conversations_table {
+
+ my $sql = <<END_SQL;
+CREATE TABLE `unit_conversations` (
+ `unit_conversation_id` int(10) unsigned NOT NULL auto_increment,
+ `unit_id_from` int(10) unsigned NOT NULL,
+ `unit_id_to` int(10) unsigned NOT NULL,
+ `ratio` float unsigned default NULL COMMENT 'Umwandlungsfaktor',
+ `date_created` datetime NOT NULL,
+ `date_changed` datetime NOT NULL,
+ PRIMARY KEY (`unit_conversation_id`),
+ KEY `unit_ids` (`unit_id_from`,`unit_id_to`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Umrechnungen zwischen den Einheiten'
+END_SQL
+
+ return undef unless $target_dbh->do($sql);
+ return 1;
+
+} ## end sub create_categories_table
+
+#-------------------------------------------------------------
+
+=head2 import_unit_conversations_table( )
+
+=cut
+
+sub import_unit_conversations_table {
+
+ my $sql = <<END_SQL;
+SELECT `unit1_id`, `unit2_id`, `ratio`
+ FROM `units_conversion`
+ ORDER BY `unit1_id`
+END_SQL
+
+ my ( $source_sth, $target_sth, $conv, $qparams );
+
+ unless ( $source_sth = $source_dbh->prepare($sql) ) {
+ return undef;
+ }
+
+ return undef unless $source_sth->execute();
+
+ $sql = <<END_SQL;
+INSERT INTO `unit_conversations` ( `unit_id_from`, `unit_id_to`, `ratio`, `date_created`, `date_changed` )
+ VALUES ( ?, ?, ?, now(), now() )
+END_SQL
+ $target_sth = $target_dbh->prepare($sql);
+ unless ($target_sth) {
+ $source_sth->finish();
+ return undef;
+ }
+
+ while ( $conv = $source_sth->fetchrow_hashref() ) {
+
+ next unless $map_unit_id{ $conv->{'unit1_id'} } and $map_unit_id{ $conv->{'unit2_id'} };
+
+ $qparams = [];
+ push @$qparams, $map_unit_id{ $conv->{'unit1_id'} };
+ push @$qparams, $map_unit_id{ $conv->{'unit2_id'} };
+ push @$qparams, $conv->{'ratio'};
+
+ unless ( $target_dbh->do( $sql, {}, @$qparams ) ) {
+ $source_sth->finish();
+ return undef;
+ }
+
+ } ## end while ( $cat = $source_sth->fetchrow_hashref(...
+
+ return 1;
+
+} ## end sub import_categories_table
+
+#-------------------------------------------------------------
+
=head2 create_categories_table( )
=cut