3 CXGN::Chado::Db - a class to handle Db terms.
5 implements an object for the Chado 'db' database table:
7 Column | Type | Modifiers
8 db_id | integer | not null default nextval('public.db_db_id_seq'::text)
9 name | character varying(255) | not null
10 description | character varying(255) |
11 urlprefix | character varying(255) |
12 url | character varying(255) |
17 my $db=CXGN::Chado::Db->new($dbh, $db_id);
18 my $db_name= $db->get_db_name();
21 $db->set_description("new description for SGN db");
26 my $db=CXGN::Chado::Db->new($dbh);
27 $db->set_db_name($db_name);
28 $db->set_urlprefix($prefix);
30 my $db_id=$db->store();
35 Naama Menda <nm249@cornell.edu>
36 Lukas Mueller <lam87@cornell.edu> (added implementation of Bio::Ontology::TermI)
41 package CXGN
::Chado
::Db
;
43 use base qw
/ CXGN::DB::Object /;
48 Usage: CXGN::Chado::Db->new($dbh, $id)
51 Args: a database handle, a database db_id (optional)
61 my $self= $class->SUPER::new
($dbh);
64 $self->set_db_id($id);
72 Usage: my $db = CXGN::Chado::Db->new_with_name($dbh, "GO");
73 Desc: an alternate constructor that takes a db name as parameter
74 db name is case insensitive, but if more than one is found
75 only one db_id is returned + a warning.
76 Side Effects: accesses the database.
86 my $query = "SELECT db_id FROM db WHERE name ilike ?";
87 my $sth = $dbh->prepare($query);
90 while (my ($id) = $sth->fetchrow_array()) {
93 if (scalar(@ids) > 1 ) { warn "Db.pm: new with name found more than one db with iname $name! Please check your databse."; }
94 my $db_id= $ids[0] || undef; #return only the 1st id
95 my $self = CXGN
::Chado
::Db
->new($dbh, $db_id);
104 my $query = "SELECT name, description, urlprefix, url
107 my $sth = $self->get_dbh()->prepare($query);
108 $sth->execute($self->get_db_id());
109 my ($name, $description, $urlprefix, $url) =
110 $sth->fetchrow_array();
112 $self->set_db_name($name);
113 $self->set_description($description);
114 $self->set_urlprefix($urlprefix);
115 $self->set_url($url);
121 Desc: store a new db in the database (update if db_id exists)
122 Ret: a database id (db_id)
124 Side Effects: accesses the database
132 my $db_id= $self->get_db_id();
135 my $query = "INSERT INTO public.db (name, description, urlprefix,url) VALUES(?,?,?,?)";
136 my $sth= $self->get_dbh()->prepare($query);
137 $self->d( "Db.pm: storing * " . $self->get_db_name() . "\n\n");
138 $sth->execute($self->get_db_name, $self->get_description, $self->get_urlprefix, $self->get_url());
139 $db_id= $self->get_dbh()->last_insert_id("db", "public");
140 $self->set_db_id($db_id);
142 my $query = "UPDATE public.db SET description=?, urlprefix=? , url=? WHERE db_id=?";
143 my $sth= $self->get_dbh()->prepare($query);
144 $sth->execute($self->get_description(), $self->get_urlprefix(),$self->get_url(), $db_id);
149 =head2 Class properties
151 The following class properties have accessors (get_db_id, set_db_id...):
164 return $self->{db_id
};
169 $self->{db_id
}=shift;
175 return $self->{db_name
};
181 $self->{db_name
}=shift;
185 sub get_description
{
187 return $self->{description
};
190 sub set_description
{
192 $self->{description
}=shift;
198 return $self->{urlprefix
};
203 $self->{urlprefix
}=shift;