Re: create and insert

[prev] [thread] [next] [Date index for 2005/01/21]

From: Hartmaier Alexander
Subject: Re: create and insert
Date: 09:40 on 21 Jan 2005
Thanks for the answers!

It seems I haven't specified everything good enough.

This is my object:

package NAC::Interface;
use strict;
use warnings;
use nactools;
use base 'NAC::DBI';
__PACKAGE__->table($dbtools::schemaname . '.interface');
__PACKAGE__->sequence('seq_interface');
__PACKAGE__->columns(Primary   =3D> qw/id_interface/);
__PACKAGE__->columns(Essential =3D> qw/fk_device fk_line fk_monitor fk_di=
vision fk_servicetime port name snmpid snmpid_rtt type speed mtu ipaddr i=
pnetmask description/);
__PACKAGE__->columns(Others    =3D> qw/startofservice user_speed bandwidt=
h_override bandwidth_computed offerbw_nonob offerbw_ob bandwidth_comment =
xfervol_computed exclude_time compu
ted_date computed_from computed_to max_downtime/);
# needed for down/notreachable interfaces
__PACKAGE__->columns(TEMP      =3D> qw/datetime_last/);

__PACKAGE__->has_a(fk_device      =3D> 'NAC::Device');
__PACKAGE__->has_a(fk_line        =3D> 'NAC::Line');
__PACKAGE__->has_a(fk_division    =3D> 'NAC::Division');
__PACKAGE__->has_a(fk_servicetime =3D> 'NAC::Servicetime');

__PACKAGE__->set_sql('down', 'SELECT * FROM nacadm.view_down_interfaces')=
;
__PACKAGE__->set_sql('notreach', 'SELECT * FROM nacadm.view_notreach_inte=
rfaces');
__PACKAGE__->set_sql('mod', 'SELECT * FROM nacadm.view_mod_interfaces');

__PACKAGE__->set_sql('from_scan', 'SELECT fk_device, port, name, snmpid, =
snmpid_rtt, type, speed, mtu, ipaddr, ipnetmask, description FROM nacadm.=
scaninterface WHERE port =3D ?');

As you can see interfaces are saved in the table 'interface'.
I have an app which scans devices for new interfaces and inserts them int=
o the table 'scaninterface'. This table hast almost the same field as tab=
le 'interface' but uses the 'port' field as primary/unique key.

I have a webpage which shows the difference between the two tables (new i=
nterfaces and a second which shows obsolete interfaces, which aren't foun=
d any more).

What I do is the following:

# read interface data from scaninterface (this works and NO primary key i=
s generated, so it seems this is a bug...)
($obj_new_interface) =3D NAC::Interface->search_from_scan($newport);
# set the monitor value (if the interface should be monitored or not)
$obj_new_interface->monitor($monitor);
# lookup matching NAC::Line object and save it's primary key in the 'line=
' object variable
$obj_new_interface->trig_line;

Should I create a new object class for the scaninterface table? Maybe eve=
n without the use of Class::DBI?
I can't immediately create the NAC::Interface object out of the scaninter=
face data because I have to check for a matching NAC::Line object first i=
f it doesn't exist (by displaying a message and a link which calls a crea=
te line webpage with pre-filled values).

-Alex


-----Urspr=FCngliche Nachricht-----
Von: Perrin Harkins [mailto:perrin@xxxx.xxx]=20
Gesendet: Donnerstag, 20. Januar 2005 19:46
An: Hartmaier Alexander
Cc: cdbi-talk@xxxxxx.xxxxx.xxx
Betreff: Re: create and insert

On Thu, 2005-01-20 at 17:24 +0100, Hartmaier Alexander wrote:
> This is the definition im my NAC::Interface class:
> __PACKAGE__->set_sql('from_scan', 'SELECT fk_device, port, name, snmpid=
, snmpid_rtt, type, speed, mtu, ipaddr, ipnetmask, description FROM nacad=
m.scaninterface WHERE port =3D ?');

I have to agree with Jay that I don't understand why you aren't using a
normal search() call here.

> I have also defined the sequence of my oracle db:
> __PACKAGE__->sequence('seq_interface');
> I is not needed that Class::DBI gets a value from the sequence,
> because an oracle trigger is defined for every table to do this.

I think you're not understanding how Class::DBI works.  It is not
possible to have a Class::DBI object without a primary key.  It has no
facilities for creating temporary objects in memory that are not in the
database.  Any time you create() an object it immediately gets inserted
into the database, before you even get the object reference back,
specifically so that it will have a primary key.

- 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)

create and insert
Hartmaier Alexander 16:00 on 20 Jan 2005

Re: create and insert
Dana Hudes 16:06 on 20 Jan 2005

Re: create and insert
Hartmaier Alexander 16:24 on 20 Jan 2005

Re: create and insert
Jay Strauss 17:45 on 20 Jan 2005

Re: create and insert
Perrin Harkins 18:46 on 20 Jan 2005

Re: create and insert
Jay Strauss 19:33 on 20 Jan 2005

Re: create and insert
Perrin Harkins 19:51 on 20 Jan 2005

Re: create and insert
Jay Strauss 17:39 on 20 Jan 2005

Re: create and insert
Peter Speltz 17:53 on 20 Jan 2005

Re: create and insert
Peter Speltz 18:06 on 20 Jan 2005

Re: create and insert
Hartmaier Alexander 09:40 on 21 Jan 2005

Re: create and insert
Jay Strauss 15:41 on 21 Jan 2005

Re: create and insert
Perrin Harkins 19:35 on 21 Jan 2005

Re: create and insert
Peter Speltz 05:50 on 22 Jan 2005

Re: create and insert
Perrin Harkins 17:19 on 22 Jan 2005

Re: create and insert
Peter Speltz 17:43 on 22 Jan 2005

Re: create and insert
Perrin Harkins 19:09 on 22 Jan 2005

Re: create and insert
Peter Speltz 22:22 on 22 Jan 2005

Re: create and insert
Perrin Harkins 00:18 on 23 Jan 2005

Re: create and insert
Hartmaier Alexander 14:07 on 24 Jan 2005

Re: create and insert
William McKee 16:15 on 24 Jan 2005

Re: create and insert
Peter Speltz 16:28 on 24 Jan 2005

Re: create and insert
Hartmaier Alexander 16:38 on 24 Jan 2005

Generated at 17:42 on 27 Jan 2005 by mariachi v0.52