Thread bless-Frage (13 answers)
Opened by Froschpopo at 2007-12-09 13:43

Froschpopo
 2007-12-09 20:00
#103666 #103666
User since
2003-08-15
2653 Artikel
BenutzerIn
[default_avatar]
Habs jetzt so gelöst:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package Friender::EasyDB;

use strict;
use DBI;
use Friender::Search::Search;

sub new {
        my $class = shift;
        my $self = {};
        bless($self, $class);
        $self->init(@_);
        return $self;
}

sub init {
        my $self = shift;
        my $dbh = DBI->connect_cached(@_,
                {
                        AutoCommit => 0,
                        RaiseError => 1
                }
        )
                or die $DBI::errstr;
        $self->{_DATA_}->{DBH} = $dbh;
}

sub search {
        my $self = shift;
        my $dbh = $self->{_DATA_}->{DBH};
        my ($st, @bind) = @_;
        return Friender::Search::Search->new($dbh, $st, @bind);
}

sub quick {
        my $self = shift;
        my $dbh = $self->{_DATA_}->{DBH};
        my ($st, @bind) = @_;
        return $dbh->selectrow_array($st, undef, @bind);
}

sub do {
        my $self = shift;
        my $dbh = $self->{_DATA_}->{DBH};
        my ($st, @bind) = @_;
        $dbh->do($st, undef, @bind);
}

sub disconnect {
        my $self = shift;
        my $dbh = $self->{_DATA_}->{DBH};
        $dbh->disconnect;
}

1;


und das "Child"-Modul, wie ich es mal nenne, sieht so aus:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Friender::Search::Search;

use strict;
use SQL::Abstract;

sub new {
        my $class = shift;
        my $self = {};
        bless($self, $class);
        $self->init(@_);
        return $self;
}

sub init {
        my $self = shift;
        my ($dbh, $st, @bind) = @_;
        my $sth = $dbh->prepare($st);
        $sth->execute(@bind)
                or die $DBI::errstr;
        $self->{_DATA_}->{RESULTS} = $sth;

}

sub get {
        my $self = shift;
        my $sth = $self->{_DATA_}->{RESULTS};
        return $sth->fetchrow_hashref;
}

1;


UND was hält man davon?

View full thread bless-Frage