DBSchema-Normalizer
view release on metacpan or search on metacpan
Normalizer.pm view on Meta::CPAN
BTW, this is the code used to produce the above SQL statements:
#!/usr/bin/perl -w
use strict;
use DBSchema::Normalizer;
my $norm = DBSchema::Normalizer->new ({
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
simulate => 1
});
$norm->do();
Normalizer.pm view on Meta::CPAN
This one-liner is equivalent to the following script:
#!/usr/bin/perl
no warnings; # Yeah. No warnings. I said it is equivalent,
# not recommended.
no strict; # Yup. No strict either.
use DBSchema::Normalizer;
$norm = DBSchema::Normalizer->new (
{
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
verbose => 1,
simulate => 1,
});
$norm->do();
It is definitely not as safe as the normal call. However, TMTOWTDI, and it's your call. I am using it, but I don't recommend it. Read my lips: I DON'T RECOMMEND IT.
=cut
sub snew { # shortcut new (parameters called by position)
my ($class, $host, $db, $src_table, $index_field,
$lookup_fields, $lookup_table, $dest_table,
$copy_indexes, $verbose, $simulate) = @_;
my $DSN= "DBI:mysql:$db;host=$host;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf";
return new ($class, {
DSN => $DSN,
src_table => $src_table,
index_field => $index_field,
lookup_fields => $lookup_fields,
lookup_table => $lookup_table,
dest_table => $dest_table,
copy_indexes => $copy_indexes,
verbose => $verbose,
simulate => $simulate,
%param_hash must contain at least the information to connect
successfully to a mysql database through the DBI. For example, the
following two calls are equivalent. The first one assumes that you have
a MySQL configuration file (.my.cnf) in your home directory. This syntax
is Unix specific. For other operating systems, please refer to the MySQL
manual.
# using a configuration file
my $norm = DBSchema::Normalizer->new ({
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
simulate => 1
});
# passing username and password explicitly
docs/Normalizer.html view on Meta::CPAN
<P>That's it. It seems a rather small contribution to your average workload, but if you ever have to deal with a project involving several large tables, with many fields, to be transformed into many normalized tables, I am sure you will appreciate th...
<P>BTW, this is the code used to produce the above SQL statements:</P>
<PRE>
#!/usr/bin/perl -w
use strict;</PRE>
<PRE>
use DBSchema::Normalizer;</PRE>
<PRE>
my $norm = DBSchema::Normalizer->new ({
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
simulate => 1
});</PRE>
<PRE>
$norm->do();</PRE>
docs/Normalizer.html view on Meta::CPAN
<PRE>
#!/usr/bin/perl
no warnings; # Yeah. No warnings. I said it is equivalent,
# not recommended.
no strict; # Yup. No strict either.
use DBSchema::Normalizer;
$norm = DBSchema::Normalizer->new (
{
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
verbose => 1,
simulate => 1,
});
$norm->do();</PRE>
docs/Normalizer.pod view on Meta::CPAN
BTW, this is the code used to produce the above SQL statements:
#!/usr/bin/perl -w
use strict;
use DBSchema::Normalizer;
my $norm = DBSchema::Normalizer->new ({
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
simulate => 1
});
$norm->do();
docs/Normalizer.pod view on Meta::CPAN
This one-liner is equivalent to the following script:
#!/usr/bin/perl
no warnings; # Yeah. No warnings. I said it is equivalent,
# not recommended.
no strict; # Yup. No strict either.
use DBSchema::Normalizer;
$norm = DBSchema::Normalizer->new (
{
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
verbose => 1,
simulate => 1,
});
$norm->do();
docs/Normalizer.txt view on Meta::CPAN
BTW, this is the code used to produce the above SQL statements:
#!/usr/bin/perl -w
use strict;
use DBSchema::Normalizer;
my $norm = DBSchema::Normalizer->new ({
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
simulate => 1
});
$norm->do();
docs/Normalizer.txt view on Meta::CPAN
This one-liner is equivalent to the following script:
#!/usr/bin/perl
no warnings; # Yeah. No warnings. I said it is equivalent,
# not recommended.
no strict; # Yup. No strict either.
use DBSchema::Normalizer;
$norm = DBSchema::Normalizer->new (
{
DSN => "DBI:mysql:music;host=localhost;"
. "mysql_read_default_file=$ENV{HOME}/.my.cnf",
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
copy_indexes => 1,
verbose => 1,
simulate => 1,
});
$norm->do();
examples/test_normalizer.pl view on Meta::CPAN
=cut
=pod
# calling the constructor with DSN parameters
#
my $norm = DBSchema::Normalizer->new (
{
DSN => "DBI:mysql:music;host=localhost" # change database and host if different
. ";mysql_read_default_file=$ENV{HOME}/.my.cnf", # see comments above
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
verbose => 2, # A LOT of information. Change to "1" to reduce it
copy_indexes => 1, # if "1", indexes are recreated into dest_table before data insertion
simulate => 1 # Does not perform anything on the database, but only print the SQL statements
});
=cut
# New constructor available in 0.08, passing a database handler
#
my $dbh = DBI->connect("DBI:mysql:music;host=localhost"
. ";mysql_read_default_file=$ENV{HOME}/.my.cnf", undef, undef, {RaiseError=>1});
my $norm = DBSchema::Normalizer->new (
{
dbh => $dbh,
src_table => "MP3",
index_field => "album_id",
lookup_fields => "artist,album,genre",
lookup_table => "tmp_albums",
dest_table => "songs",
verbose => 2, # A LOT of information. Change to "1" to reduce it
( run in 0.296 second using v1.01-cache-2.11-cpan-05444aca049 )