| 1 | package Bio::DOOP::DBSQL; | ||
| 2 | |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use DBI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Bio::DOOP::DBSQL - MySQL control object | ||
| 10 | |||
| 11 | =head1 VERSION | ||
| 12 | |||
| 13 | Version 0.06 | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | 2 | our $VERSION = '0.06'; | |
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | $db = Bio::DOOP::DBSQL->connect("user","pass","database","localhost"); | ||
| 22 | |||
| 23 | $res = $db->query("SELECT * FROM sequence LIMIT 10"); | ||
| 24 | |||
| 25 | foreach (@$res) { | ||
| 26 | @fields = @{$_}; | ||
| 27 | print "@fields\n"; | ||
| 28 | } | ||
| 29 | |||
| 30 | =head1 DESCRIPTION | ||
| 31 | |||
| 32 | This object provides low level access to the MySQL database. In most | ||
| 33 | cases you do not need it, because the DOOP API handles the database | ||
| 34 | queries. Still, if you need some special query and the DOOP | ||
| 35 | API can't help you, use the query method to access the database. | ||
| 36 | |||
| 37 | =head1 AUTHORS | ||
| 38 | |||
| 39 | Tibor Nagy, Godollo, Hungary and Endre Sebestyen, Martonvasar, Hungary | ||
| 40 | |||
| 41 | =head1 METHODS | ||
| 42 | |||
| 43 | =head2 connect | ||
| 44 | |||
| 45 | You can connect to the database with this method. The arguments are the | ||
| 46 | following : username, password, database name, host. The return value | ||
| 47 | is a Bio::DOOP::DBSQL object. You must use this object in the arguments | ||
| 48 | of other objects. | ||
| 49 | |||
| 50 | $db = Bio::DOOP::DBSQL->connect("user","pass","database","localhost"); | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | 0 | ▶ | sub connect { |
|
Subroutine
connect: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 55 | 0 | my $self = {}; | |
| 56 | 0 | my $dummy = shift; | |
| 57 | 0 | $self->{USER} = shift; | |
| 58 | 0 | $self->{PASS} = shift; | |
| 59 | 0 | $self->{DATABASE} = shift; | |
| 60 | 0 | $self->{HOST} = shift; | |
| 61 | |||
| 62 | 0 | my $host = $self->{HOST}; | |
| 63 | 0 | my $db = $self->{DATABASE}; | |
| 64 | |||
| 65 | 0 | $self->{DB} = DBI->connect("dbi:mysql:$db:$host",$self->{USER},$self->{PASS}); | |
| 66 | |||
| 67 | 0 | bless $self; | |
| 68 | 0 | return ($self); | |
| 69 | } | ||
| 70 | |||
| 71 | =head2 query | ||
| 72 | |||
| 73 | You can run special SQL statements on the database. In this example we count | ||
| 74 | the number of clusters. | ||
| 75 | |||
| 76 | Returns an arrayref with the results of the MySQL query. | ||
| 77 | |||
| 78 | $db->query("SELECT COUNT(*) FROM cluster;"); | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | 0 | ▶ | sub query { |
|
Subroutine
query: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 83 | 0 | my $self = shift; | |
| 84 | 0 | my $q = shift; | |
| 85 | |||
| 86 | 0 | my $sth = $self->{DB}->prepare($q); | |
| 87 | 0 | $sth->execute(); | |
| 88 | 0 | my $results = $sth->fetchall_arrayref(); | |
| 89 | |||
| 90 | 0 | return($results); | |
| 91 | } | ||
| 92 | |||
| 93 | 2 | 1; | |