in reply to How to use DBIx::Class::Schema::Loader to create schema from an existing MySQL database?

G'day david123,

Welcome to the monastery.

The documentation for DBIx::Class::Schema::Loader has this regarding make_schema_at():

"Arguments: $schema_class_name, \%loader_options, \@connect_info"

So, you're missing the \%loader_options argument. This means that your \@connect_info (i.e. ['dbi::mysql::dbname=...]) is being read as that argument.

Line 165 of .../lib/DBIx/Class/Schema/Loader.pm (view the path given in the error message or see DBIx::Class::Schema::Loader Source) is:

my %args = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;

Which, given your arguments, evaluates to:

my %args = ['dbi::mysql::dbname=turboimmisoft', 'root', ''];

The error "Reference found where even-sized list expected" can be found in perldiag (Perl diagnostic messages) with a more detailed explanation.

-- Ken

  • Comment on Re: How to use DBIx::Class::Schema::Loader to create schema from an existing MySQL database?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: How to use DBIx::Class::Schema::Loader to create schema from an existing MySQL database?
by david123 (Initiate) on Aug 01, 2013 at 05:22 UTC
    Are the following my \%loader_options? { debug => 1, dump_directory => '.\lib', },

    I tried, but I got the following error message:

    DBIx::Class::Storage::DBI::_connect(): DBI Connection failed: DBI conn +ect('dbname="turboimmisoft"','root',...) failed: Unknown database '"t +urboimmisoft"' at C:/xampp/perl/site/lib/DBIx/Class/Storage/DBI.pm li +ne 1395.

    Can anyone write the right code for me please? I wasted an entire day on this. In MySQL, the database is made up a folder containing the tables. That folder is named turboimmisoft (same name as the database). There is no more folder in turboimmisoft.

    Some info:

    1. Path to the MySQL database:C:\xampp\mysql\data\turboimmisoft\

    2. Path to per.exe: C:\xampp\perl\bin\

    3. Connection info with DBI: my $driver = "mysql"; my $database = "turboimmisoft"; my $dsn = "DBI:$driver:database=$database"; my $userid = "root"; my $password = "";

      "I tried, but I got the following error message: ..."

      "I tried" doesn't tell us what you tried, so we're somewhat in the dark there; however, perhaps jumping directly to the error message will prove useful. What did you see when you looked at line 1395 of C:/xampp/perl/site/lib/DBIx/Class/Storage/DBI.pm? [Correct me if I'm wrong: you didn't look, did you?] In my copy of that code, I see:

      $dbh = DBI->connect(@info);

      Look familiar? Now look at the line just before that (i.e. 1394):

      require DBI;

      So, the connection is being made using DBI's connect() method.

      One key phrase that stands out:

      The $data_source value must begin with "dbi:driver_name:".

      Note that's dbi (in lowercase) and single colons are used!

      The next paragraph goes on to explain what happens if

      the driver_name part is empty (i.e., the $data_source prefix is "dbi::")

      I recommend you read more than just those snippets I've pointed to; however, that may be enough for you to resolve your problems.

      "I wasted an entire day on this."

      Or, alternatively, you could take the silver lining view:

      "I spent an entire day that I'll never forget. I learnt valuable lessons about troubleshooting and reading documentation that I'll never forget either."

      -- Ken