new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / debian / ossec-hids / usr / share / doc / ossec-hids / contrib / ossecmysql.pm
1 use DBI;
2 use strict;
3 package ossecmysql;
4
5 sub new(){
6         my $type = shift;
7         my %conf=@_;
8         my $self={};
9         my $flag;
10         $self->{database}=$conf{database};
11         $self->{dbhost}=$conf{dbhost};
12         $self->{dbport}=$conf{dbport};
13         $self->{dbuser}=$conf{dbuser};
14         $self->{dbpasswd}=$conf{dbpasswd};
15
16         $self->{dsn} = "DBI:mysql:database=$self->{database};host=$self->{dbhost};port=$self->{dbport}";
17         $self->{dbh} = DBI->connect($self->{dsn}, $self->{dbuser},$self->{dbpasswd});
18         bless $self, $type;
19 }
20 sub fetchrecord(){
21         my $self= shift ;
22         my ($rows)=@_;
23         my ($pointer,$numrows,$fields)=(${$rows}[0],${$rows}[1],${$rows}[2]);
24         my @result;
25         return if $pointer == $numrows;
26         for (my $i=0; $i <  $fields; $i ++){
27          my $field=  @{$rows}[($pointer * $fields) + 3 + $i ];
28          push (@result, $field);
29         }
30         ${$rows}[0] ++;
31         
32         return @result;
33 }
34 sub fetchrows(){
35         my $self = shift ;
36         my ($query)=shift;
37         my @params= @_;
38         my @rows;
39         my $numFields;
40         my $numRows;
41         $numRows=$numFields=0;
42         $self->{sth}=$self->{dbh}->prepare($query);
43         $self->{sth}->execute(@params) ;
44         $numRows = $self->{sth}->rows;
45         my @row=();
46         return @rows unless $numRows>0;
47         $numFields = $self->{sth}->{'NUM_OF_FIELDS'};
48         push (@rows,0,$numRows,$numFields);
49         while(@row=$self->{sth}->fetchrow_array){
50                 push (@rows,@row);
51         }
52
53         $self->{sth}->finish;
54         return @rows;
55         
56 }
57
58 sub execute(){
59         my $self = shift ;
60         my $flag;
61         my ($query)=shift;
62         my @params= @_;
63         my @rows= ();
64         my $numFields;
65         my $numRows;
66         $numRows=$numFields=0;
67         $self->{sth} = $self->{dbh}->prepare($query);
68         return $self->{sth}->execute(@params) ;
69 }
70
71 sub lastid(){
72         my $self = shift ;
73         return $self->{sth}->{mysql_insertid};
74 }
75 1