Dear Monk Programmers

In a previous question (Is it worth migrating from MySQL to MariaDB?) I was asking if it is a good move to switch from MySQL to MariaDB. And the consensus was Yes. However. I forgot to mention one crucial part of my settings: that I am relying heavily on DBIx::Class which has no loader for MariaDB. The "solutions" are 2:

  1. Install DBD::mysql and use the DSN : connect("DBI:mysql:...", ...) (also see Re: MariaDB : read credentials from file fails (via dsn option mariadb_read_default_file)) - this is a dead end for me because DBD::mysql fails to install, I need to investigate how to install DBD::mysql on my particular system. I can say that this route worked on another system where said module did install OK.
  2. Use a DSN with DBI:MariaDB. DBIx::Class will complain that it does not know this DB driver. Install DBIx::Class::Storage::DBI::MariaDB and add __PACKAGE__->ensure_class_loaded('DBIx::Class::Storage::DBI::MariaDB');

    in the custom-code part of the Schema.pm auto-generated file (by DBIx). This sounds straightforward and DBIx converts my SQL to packages OK. The only problem (so far) is that the generated files do not contain a set_primary_key() for those tables which my SQL code explicitly declares one column to be the PK. Instead it has a:

    __PACKAGE__->add_unique_constraint( "PRIMARY", ["id"] );

    This should work but it doesn't! Because further on, DBIx::Class complains with:

    Error: {UNKNOWN}: DBIx::Class::ResultSource::_pri_cols_or_die(): Oper +ation requires a primary key to be declared on 'MyApp::Schema::XYZ' v +ia set_primary_key ...

    My hack was to add a __PACKAGE__->set_primary_key("id"); in the custom-code part of the auto-generated schema file for each table that needs it.

    Fine! This creates the schema files and finally connects to DB. BUT my tests fail with surreal output. The culprit, I found out hours later, is that none of my tables' PK is ... auto_increment'ed (as it was stated in my SQL code) !!!!!!!!!

    Currently, this directive is set in said file, like so:

    # when I am using DBI:mysql ... __PACKAGE__->add_columns( "id", { "is_auto_increment" => "1", "data_type" => "mediumint", ... } ); __PACKAGE__->set_primary_key("id");

    The auto_increment directive is currently missing from my DBIx::Class auto-generated files. From a diagonal look in the documentation I did not see how to modify these directives for each column in the custom-code part of the auto-generated files. I did try to re-issue a __PACKAGE__->add_columns(...) in the custom-code part hoping that it will modify it but I did not see any change.

To summarise, I am looking for a solution in using DBD::MariaDB (and not DBD::mysql) with DBIx::Class with primary keys declared explicitly and also to be auto-incremented if that is what my SQL states.

I have filed an issue with DBIx::Class::Storage::DBI::MariaDB at https://github.com/Siemplexus/DBIx-Class-Storage-DBI-MariaDB/issues/4 and plan to do the same with DBIx::Class.

bw, bliako


In reply to DBD::MariaDB + DBIx::Class = woes by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.