[Dbix-class] Detecting connection errors

Will Crawford billcrawford1970 at gmail.com
Thu Oct 15 10:13:34 GMT 2015


This is because you are using sqlite. You could be intending to call
->deploy() rather than trying to select data. Sqlite will create the
file for you (complete with typo) in this case. But as you haven't
created any tables in the alternately-spelt database file, you'll get
an exception.

On 14 October 2015 at 20:14, Alberto Luaces <aluaces at udc.es> wrote:
> Alberto Luaces <aluaces at udc.es> writes:
>
>>> Sencondly, DBIx::Class only hits the database when it absolutely has
>>>to,
>>> e.g. to fetch restults.  This includes the initial connection.  However,
>>> you can force it to connect early by calling
>>>
>>>    $schema->storage->ensure_connected;
>>>
>>> Which will throw an exception if it fails to connect.
>>
>> Yes, it sounds sensible for an ORM to be lazy, but I did not imagine
>> that it could even involve connections.  Thanks a lot for the pointer.
>
> Oops, I spoke too soon.  ensure_connected is not throwing.  Here is the
> code for reference:
>
>  1 use lib './lib';
>  2 use DAAO;
>  3
>  4 my $r = DAAO->connect("dbi:SQLite:non-existent.db");
>  5 $r->storage->ensure_connected;
>  6
>  7 my $resultset = $r->resultset('Alumno')->search;
>  8
>  9 my $person = $resultset->next;       # Iterator
> 10
> 11 print $person->asistencia;
>
> It does not crash until line 9, when the iterator is used.
>
> --
> Alberto
>
>
> _______________________________________________
> 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



More information about the DBIx-Class mailing list