wojtyk has asked for the wisdom of the Perl Monks concerning the following question:
The error produced is:#!/usr/local/bin/perl use strict; use DBI; my $db_file = 'database.db'; package MyDbase::DBI; use base 'Class::DBI'; sub connect { DBI->connect("dbi:SQLite:dbname=$db_file","",""); } if (!-e $db_file) { my $db = &connect; $db->do(q{ CREATE TABLE user ( handle STRING PRIMARY KEY, password STRING, session INTEGER )}); $db->do(q{ CREATE TABLE session ( id STRING PRIMARY KEY, timestamp INTEGER )}); } package MyDbase::Session; use base 'MyDbase::DBI'; MyDbase::Session->table('session'); MyDbase::Session->columns(All => qw/id timestamp/); MyDbase::DBI->set_db('Main',"dbi:SQLite:dbname=$db_file","",""); package MyDbase::User; use base 'MyDbase::DBI'; MyDbase::User->table('user'); MyDbase::User->columns(All => qw/handle password session/); MyDbase::User->has_a(session => 'MyDbase::Session'); MyDbase::DBI->set_db('Main',"dbi:SQLite:dbname=$db_file","",""); package main; MyDbase::DBI->connect; my $session_id = 'aaa'; my $user_rec = { 'handle' => 'a', 'password' => crypt('a','a'), }; # is this a requirement or can both records be created at once? #my $session_rec = MyDbase::Session->insert({ my $session_rec = { 'id' => $session_id, 'timestamp' => time, }; #}); $user_rec->{'session'} = $session_rec; MyDbase::User->insert($user_rec);
This error goes away if I used the commented out code (using a MyDbase::Session object instead of a hash).Can't deflate session: HASH(0x84ee954) is not a MyDbase::Session at /u +sr/local/lib/perl5/site_perl/5.8.5/Class/DBI/Relationship/HasA.pm lin +e 86
My question is how to do this insert with a single database access.
Thanks in advance :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inserting a relation into a database with Class::DBI
by FunkyMonk (Bishop) on May 29, 2007 at 08:56 UTC | |
by wojtyk (Friar) on May 29, 2007 at 16:39 UTC | |
by agianni (Hermit) on May 29, 2007 at 17:54 UTC | |
|
Re: Inserting a relation into a database with Class::DBI
by andreas1234567 (Vicar) on May 29, 2007 at 19:37 UTC | |
by wojtyk (Friar) on May 29, 2007 at 20:35 UTC |