On Tue, Nov 18, 2008 at 10:03 AM, luke saunders <[EMAIL PROTECTED]> wrote: > On Mon, Nov 17, 2008 at 11:23 PM, John Goulah <[EMAIL PROTECTED]> wrote: >> So far I've been using sqlt-diff to diff two files: >> file1.sql=MySQL file2.sql=MySQL >> >> >> but what I really need is to be able to diff a file against the actual >> database and produce a diff. >> >> >> I see there is a parser called DBI-MySQL, but I'm not sure how to >> invoke it. My thought would be to use a DSN string, but then how >> would one supply a username/password? >> >> >> If someone can clear this up I would be glad to patch the help output >> to give some better examples on how this may work. >> > > Hi John, > > I have done some work which involved creating a diff directly against > the database. > > Essentially I create one SQLT object like so: > > my $db_tr = SQL::Translator->new({ > add_drop_table => 1, > parser => 'DBI', > parser_args => { dbh => $dbh } > }); >
Thanks Luke, I'm essentially going with that approach but I'm having a bit of weirdness. I create a DBI parser like that and also a file based parser. When I run them through schema_diff I get basically a create for every table as my output, which seems to me that one of the parsers is empty. I've tracked that down to my DBI parser. I created the dbh something like: my $dbh = DBI->connect($dsn, 'user', 'pass', {'RaiseError' => 1}); and I know that works fine because I was able to select some rows. Then I created the object like you said: my $db_tr = SQL::Translator->new({ add_drop_table => 1, parser => 'DBI', parser_args => { dbh => $dbh } }); $db_tr->producer('MySQL'); # do I need this? I can dump out the object, and the schema object, but it just barfs on the get_tables call warn Dumper($db_tr); warn Dumper($db_tr->schema); warn Dumper($db_tr->schema->get_tables); and the output: $VAR1 = bless( { 'parser_args' => { 'dbh' => bless( {}, 'DBI::db' ) }, 'quote_field_names' => 1, '_ID' => 'SQL::Translator', 'parser' => sub { "DUMMY" }, 'quote_table_names' => 1, 'parser_type' => 'SQL::Translator::Parser::DBI', 'add_drop_table' => 1, '_DEBUG' => 1, 'producer' => sub { "DUMMY" }, 'debug' => 1, '_ERROR' => '', 'producer_type' => 'SQL::Translator::Producer::MySQL' }, 'SQL::Translator' ); $VAR1 = bless( { 'translator' => bless( { 'parser_args' => { 'dbh' => bless( {}, 'DBI::db' ) }, 'quote_field_names' => 1, '_ID' => 'SQL::Translator', 'parser' => sub { "DUMMY" }, 'schema' => $VAR1, 'quote_table_names' => 1, 'parser_type' => 'SQL::Translator::Parser::DBI', 'add_drop_table' => 1, '_DEBUG' => 1, 'producer' => sub { "DUMMY" }, 'debug' => 1, '_ERROR' => '', 'producer_type' => 'SQL::Translator::Producer::MySQL' }, 'SQL::Translator' ), '_ID' => 'SQL::Translator::Schema', '_DEBUG' => 0, '_ERROR' => '' }, 'SQL::Translator::Schema' ); Warning: something's wrong at db_diff.pl line 38. ### $db_tr->schema->get_tables Also, I tried adding that other bit of code you had, the only other thing I could think of that I was missing. This bit: foreach my $tr ($db_tr, $file_tr) { my $data = $tr->data; $tr->parser->($tr, $$data); } And very strangely that gives me: Undefined subroutine &SQL::Translator::Parser::DBI::MySQL::parse called at /home/jgoulah/wdir/sqlfairy_trunk/sqlfairy/lib//SQL/Translator/Parser/DBI.pm line 179 I'm a bit stuck, if anyone has a clue. Thanks for all the ideas so far! John ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ -- sqlfairy-developers mailing list sqlfairy-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlfairy-developers