An Introduction to Class::DBI - Bonus Material 43

Class::DBI Gotchas

Create and NOT NULL columns

  • When you call Person->create(), the object is created and inserted into the database in a single step

  • You might be tempted to do the following:

        my $person = Person->create();
        $person->name('Kevin Bacon');
  • But if the columns 'name', 'birthyear' and 'vacuity' are declared with NOT NULL, your database will throw an error.

  • Instead, you should fill in all the attributes:

        my $person = Person->create({
            name             => 'Kevin Bacon',
            birthyear        => 1958,
            degrees_of_kevin => 0,


YAPC::Canada << Previous | Index | Next >>
Copyright © 2003 Michael Graham