Re: create and insert
[prev]
[thread]
[next]
[Date index for 2005/01/24]
I just finished my NAC::ScanInterface class and included it in my webpage=
:
package NAC::ScanInterface;
use strict;
use warnings;
use nactools;
use base 'NAC::DBI';
__PACKAGE__->table($dbtools::schemaname . '.scaninterface');
__PACKAGE__->columns(Primary =3D> qw/port/);
__PACKAGE__->columns(Essential =3D> qw/fk_device datetime name snmpid sn=
mpid_rtt type speed mtu ipaddr ipnetmask description/);
__PACKAGE__->columns(Others =3D> qw//);
__PACKAGE__->columns(TEMP =3D> qw/fk_line/);
__PACKAGE__->has_a(fk_device =3D> 'NAC::Device');
__PACKAGE__->has_a(fk_line =3D> 'NAC::Line');
__PACKAGE__->add_trigger(select =3D> \&trig_line);
sub trig_line {
my ($self) =3D @_;
if (not defined $self->line)
{
my $dbh =3D nactools::connectdbnacweb();
my @ary_description =3D split(/\s/, $self->description, 4);
# workaround for LAN interfaces which have no provider
if ($ary_description[0] =3D~ /^LAN/ )
{
# LAN interfaces have no provider=20
unshift (@ary_description, '');
# and no speed
splice (@ary_description, 3, 0, '');
}
# all others have no location=20
else
{
splice (@ary_description, 2, 0, '');
}
#$obj_line->name ($ary_description[1]);
#$obj_line->location ($ary_description[2]);
#$obj_line->speed ($ary_description[3]);
#$obj_line->description ($ary_description[4]);
#$obj_line->fk_provider (get_provider ($dbh, $ary_description[0]));
=20
$self->line(NAC::Line->sql_find_line->select_val($ary_description[1],=
$ary_description[2]));
}=20
} =20
Is the use of the TEMP column ok? I need it for NAC::Line object lookup.
The trigger seems to work fine...
Now I'll look in the process of creating NAC::Interface objects out of NA=
C::ScanInterface objects. As Perrin already wrote the NAC::ScanInterface =
objects don't have the same primary key as the NAC::Interface objects so =
I won't be able to use ->copy.
Thanks for the feedback!
-Alex
-----Urspr=FCngliche Nachricht-----
Von: Perrin Harkins [mailto:perrin@xxxx.xxx]=20
Gesendet: Sonntag, 23. Januar 2005 01:19
An: Peter Speltz
Cc: class dbi list
Betreff: Re: create and insert
Peter Speltz wrote:
> --- Perrin Harkins <perrin@xxxx.xxx> wrote:
>>You can add to an existing object and then update() it, but you have to=
=20
>>already have a primary key.
>>
>=20
>=20
> Is that what Alex is doing?
No, which is why it isn't working for him. He is making broken objects=20=
with no primary key, that CDBI should prevent.
> To me it seems he is getting data from
> scaninterface and making an Interface object out of it. He doesn't even=
have a
> Scaninterface CDBI class.=20
> ($obj_new_interface) =3D NAC::Interface->search_from_scan(..); # sql_fr=
om_scan
> retrieves data only from scaninterface table.=20
Right, and that would actually work if his scaninterface table had the=20=
same primary key, but it doesn't, so he ends without a primary key in=20
hos objects.
- Perrin
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*"*
Hinweis: Dieses E-mail kann vertrauliche und gesch=FCtzte Informationen e=
nthalten.
Sollten Sie nicht der beabsichtigte Empf=E4nger sein, verst=E4ndigen Sie =
bitte den Absender und l=F6schen Sie dieses E-mail dann sofort.
Notice: This e-mail contains information that is confidential and may be =
privileged.
If you are not the intended recipient, please notify the sender and then =
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*"*
|
(message missing)
|