[Dbix-class] Handling Null values in search,find and upgrade

will trillich will.trillich at serensoft.com
Thu May 23 13:39:55 GMT 2013


$rs->search( { field =3D> undef } )

creates sql like so:

...where field is null...



on the other hand

$rs->search( { field =3D> { '!=3D' =3D> undef } } )

produces:

...where field is not null...




On Wed, May 22, 2013 at 4:03 PM, Ekki Plicht (DF4OR) <ekki at plicht.de> wrote:

> Hi.
> I am a little bit uncertain how DBIx::Class handles Null values in various
> circumstances.
>
> With the following table:
> "id",  { data_type =3D> "integer", is_auto_increment =3D> 1, is_nullable =
=3D> 0
> },
> "id_prod", { data_type =3D> "integer", is_foreign_key =3D> 1, is_nullable=
 =3D> 1
> },
> "lang", { data_type =3D> "varchar", is_nullable =3D> 1, size =3D> 2 },
> "size", { data_type =3D> "varchar", is_nullable =3D> 1, size =3D> 2 },
> "atext", { data_type =3D> "text", is_nullable =3D> 1 },
> __PACKAGE__->set_primary_key("id");
> __PACKAGE__->add_unique_constraint("text_UNIQUE", ["size", "id_prod",
> "lang"]);
>
> What is the difference between
> ->search( { size =3D> 'S',  lang =3D> 'de', }, { key =3D> 'text_UNIQUE' }=
);
> and
> ->search( { size =3D> 'S',  lang =3D> 'de', id_prod =3D> undef }, { key =
=3D>
> 'text_UNIQUE' });
>
> In the first case one constraint component (id_prod) is missing entirely,
> in the second case it's present but set to undef.
>
> Which of these two cases would be preferrable if the value of 'id_prod' is
> "Dont care"?
>
> What I did so far to find it out myself:
> Search CPAN docs high and low; google for appropriate search terms, check
> stackoverflow, all to no avail.
>
> What I could have done to help myself:
> Set up a database to simulate this. But I am at an early stage of
> development of a new DB and don't have no data yet. Sorry.
>
> TIA,
> Ekki
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



-- =

 Will Trillich :: 812.454.6431

=93Grading takes away all the fun from failing. And a huge part of education
is about failure.=94  -- Shimon Schocken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130523/ce3=
e7a19/attachment.htm


More information about the DBIx-Class mailing list