[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at pub.open-bio.org
Mon Jul 25 21:13:51 UTC 2005
mwilkinson
Mon Jul 25 17:13:51 EDT 2005
Update of /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi
In directory pub.open-bio.org:/tmp/cvs-serv21605/MOBY/Adaptor/moby/queryapi
Modified Files:
mysql.pm
Log Message:
more of the same. Pass hashes instead of hashrefs, and avoid passing database ids
moby-live/Perl/MOBY/Adaptor/moby/queryapi mysql.pm,1.33,1.34
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm 2005/07/25 20:55:35 1.33
+++ /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm 2005/07/25 21:13:51 1.34
@@ -482,8 +482,9 @@
}
# inserts a new tuple into object table
+# pass object_type object_lsid description authority contact_email
sub insert_object{
- my ($self, @args) = @_;
+ my ($self, %args) = @_;
my $dbh = $self->dbh;
$dbh->do("insert into object
(object_type,
@@ -493,24 +494,30 @@
contact_email)
values (?,?,?,?,?)",
undef,
- (get_value('object_type', @args),
- get_value('object_lsid', @args),
- get_value('description', @args),
- get_value('authority', @args),
- get_value('contact_email', @args)));
+ $args{'object_type'},
+ $args{'object_lsid'},
+ $args{'description'},
+ $args{'authority'},
+ $args{'contact_email'});
my $id=$dbh->{mysql_insertid};
return $id;
}
+# pass 'type' which is either an LSID or a term
sub delete_object{
- my ($self, @args) = @_;
+ my ($self, %args) = @_;
my $dbh = $self->dbh;
- my $statement = "delete from object "; #OMG!! This is a very dangerous thing to start with.........**********
- # ************** MUST FIX THAT LINE OR WE MAY BE DEAD ONE DAY ********************
- my @bindvalues = ();
- ($statement, @bindvalues) =_add_condition($statement, @args);
- $dbh->do( $statement,
- undef, @bindvalues );
+ my $term = $args{type};
+ return 0 unless $term;
+ my $statement = "delete from object where ";
+ my $condition;
+ if ($term =~ /^urn\:lsid/){
+ $condition = " object_lsid = ?";
+ } else {
+ $condition = " object_type = ?";
+ }
+ $statement = $statement.$condition;
+ $dbh->do( $statement,undef, ($term) );
if ($dbh->err){
return (1, $dbh->errstr);
@@ -520,8 +527,14 @@
}
}
+# pass "type" here, should be an LSID, preferably...
sub query_object_term2term{
- my ($self, @args) = @_;
+ my ($self, %args) = @_;
+ my $type = $args{type};
+ my $result = $self->query_object(type => $type);
+ my $row = shift(@$result);
+ my $id = $row->{object_id};
+ return [{}] unless $id;
my $dbh = $self->dbh;
my $statement = "select
@@ -530,28 +543,33 @@
object1_id,
object2_id,
object2_articlename
- from object_term2term ";
- my @bindvalues = ();
-
- if (@args > 0)
- {
- ($statement, @bindvalues) =_add_condition($statement, @args);
- }
-
- my $result = do_query($dbh, $statement, @bindvalues);
- return $result;
+ from object_term2term where object2_id = ?";
+ my $result2 = do_query($dbh, $statement, ($id));
+ return $result2;
}
+# pass object1_type, object2_type, object2_articlename, relationship_type
sub insert_object_term2term{
- my ($self, @args) = @_;
+ my ($self, %args) = @_;
+ my $type1 = $args{object1_type};
+ my $result = $self->query_object(type => $type1);
+ my $row = shift(@$result);
+ my $id1 = $row->{object_id};
+ my $type2 = $args{object2_type};
+ $result = $self->query_object(type => $type2);
+ $row = shift(@$result);
+ my $id2 = $row->{object_id};
+ my $relationship_type = $args{relationship_type};
+ my $object2_articlename = $args{object2_articlename};
+
my $dbh = $self->dbh;
$dbh->do(
-q{insert into object_term2term (relationship_type, object1_id, object2_id, object2_articlename) values (?,?,?,?)},
+ q{insert into object_term2term (relationship_type, object1_id, object2_id, object2_articlename) values (?,?,?,?)},
undef,
- ( get_value('relationship_type', @args),
- get_value('object1_id', @args),
- get_value('object2_id', @args),
- get_value('object2_articlename', @args) )
+ $relationship_type,
+ $id1,
+ $id2,
+ $object2_articlename
);
return $dbh->{mysql_insertid};
More information about the MOBY-guts
mailing list