BioPerl-DB
view release on metacpan or search on metacpan
lib/Bio/DB/BioSQL/mysql/SpeciesAdaptorDriver.pm view on Meta::CPAN
placeholders as necessary for the given unique key.
The statement is expected to return the primary key as the first and
then as many columns as $adp->get_persistent_slots() returns, and in
that order.
Example :
Returns : A DBI prepared statement handle with as many placeholders as
necessary for the given unique key
Args : The calling Bio::DB::BioSQL::BasePersistenceAdaptor derived object
(basically, it needs to implement dbh() and get_persistent_slots()).
A reference to a hash with the names of the object''s slots in the
unique key as keys and their values as values.
A reference to an array of foreign key objects or slots
(class names if slot).
=cut
sub prepare_findbyuk_sth{
my ($self,$adp,$ukval_h,$fkslots) = @_;
# get the slot/attribute map
my $table = $self->table_name($adp);
my $node_table = $self->table_name("TaxonNode");
my $pkname = $self->primary_key_name($node_table);
my $fkname = $self->foreign_key_name("TaxonNode");
my $slotmap = $self->slot_attribute_map($table);
# SELECT columns
my @attrs = $self->_build_select_list($adp,$fkslots);
# WHERE clause constraints
my @cattrs = ();
foreach (keys %$ukval_h) {
my $col;
if(exists($slotmap->{$_})) {
$col = $slotmap->{$_};
}
push(@cattrs, $col || "NULL");
$self->warn("slot $_ is in unique key, but can't be mapped to ".
"an entity column: you won't find anything")
unless $col;
}
# create the sql statement
my $sql = "SELECT " . join(", ", @attrs) .
" FROM $node_table, $table".
" WHERE $node_table.$pkname = $table.$fkname AND ".
join(" AND ", map { "$_ = ?"; } @cattrs);
$adp->debug("preparing UK select statement: $sql\n");
# prepare statement and return
return $adp->dbh()->prepare($sql);
}
=head2 prepare_delete_sth
Title : prepare_delete_sth
Usage :
Function: Creates a prepared statement with one placeholder variable suitable
to delete one row from the respective table the given class maps to.
We override this here in order to delete from the taxon
node table, not the taxon name table. The node table will
cascade to the name table.
Example :
Returns : A DBI statement handle for a prepared statement with one placeholder
Args : The calling adaptor (basically, it needs to implement dbh()).
Optionally, additional arguments.
=cut
sub prepare_delete_sth{
my ($self, $adp) = @_;
# default is a simple DELETE statement
#
# we need the table name and the name of the primary key
my $tbl = $self->table_name("TaxonNode");
my $pkname = $self->primary_key_name($tbl);
# straightforward SQL:
my $sql = "DELETE FROM $tbl WHERE $pkname = ?";
$adp->debug("preparing DELETE statement: $sql\n");
my $sth = $adp->dbh()->prepare($sql);
# done
return $sth;
}
=head2 insert_object
Title : insert_object
Usage :
Function:
Example :
Returns : The primary key of the newly inserted record.
Args : A Bio::DB::BioSQL::BasePersistenceAdaptor derived object
(basically, it needs to implement dbh(), sth($key, $sth),
dbcontext(), and get_persistent_slots()).
The object to be inserted.
A reference to an array of foreign key objects; if any of those
foreign key values is NULL (some foreign keys may be nullable),
then give the class name.
=cut
sub insert_object{
my ($self,$adp,$obj,$fkobjs) = @_;
# get the INSERT statements: we need one for the taxon node and one for
# the taxon name table
my $cache_key_t = 'INSERT taxon '.ref($obj);
my $cache_key_tn = 'INSERT taxname '.ref($obj);
my $sth_t = $adp->sth($cache_key_t);
my $sth_tn = $adp->sth($cache_key_tn);
my $sth_max = $adp->sth("SELECT MAX TAXON SETID");
# we need the slot map regardless of whether we need to construct the
# SQL or not, because we need to know which slots do not map to a column
# (indicated by them being mapped to undef)
my $table = $self->table_name($adp);
my $node_table = $self->table_name("TaxonNode");
my $fkname = $self->foreign_key_name("TaxonNode");
my $slotmap = $self->slot_attribute_map($table);
( run in 0.645 second using v1.01-cache-2.11-cpan-39bf76dae61 )