Moose Identity Round Up. Part the First



  • Its identity round-up day here in the Moose-Pen

    I decided to add in another test;


    { caption => 'have identity option but do not use',
    key => 'elements',
    elements => [
    { name => 'id',
    identity =>{'DBI::db'=>{'ORACLE' => {
    name => 'NEXTVAL',
    view => 'products_seq'}
    }}
    },
    { name => 'first_name', },
    { name => 'last_name', },
    ],
    create => {
    container => {
    last_name => 'Bloggings',
    first_name => 'Bill',
    },
    sql =>
    "INSERT INTO Products ( first_name, last_name ) VALUES( ?, ? )",
    params => [ 'Bill', 'Bloggings' ]
    },
    },

    A simple enough test all I want to ensure is when I have a $dbh that does not match the one currently being used. I do get a pass when I run the above;


    ok 15 - have identity option but do not use create SQL correct
    ok 16 - have identity option but do not use create params correct

    but I am getting this rather annoying waring;

    Use of uninitialized value in string ne at D:\GitHub\database-accessor-driver-dbi\lib/Database/Accessor/Driver/DBI.pm line 786.

    coming from this line;

    if ($self->identity_index() ne undef ){

    the problem, though it is not much of one, is that I can't just do this;

    if ($self->identity_index())

    as if my 'index' element happens to be the first one I would get '0' here and my code will fail in that case as if (0) would be false.

    I have to do a little trick here to get this to work; First I have to take out the default value from the attribute


    has identity_index => (
    is => 'ro',
    isa => 'Int|Undef',
    -- default => undef,
    );

    and next I have to change that if a little to

    -- if ($self->identity_index()){
    ++ if ($self->identity_index() >=0){

    and now that warning is gone;

    So that is the postette for today.

    IMG_5435a.jpg



    http://blogs.perl.org/users/byterock/2018/09/moose-identity-round-up-part-the-first.html

Log in to reply
 

© Lightnetics 2019