~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to lib/GenTest/Validator/Falcon.pm

initial import from internal tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package GenTest::Validator::Falcon;
 
2
 
 
3
require Exporter;
 
4
@ISA = qw(GenTest::Validator GenTest);
 
5
 
 
6
use strict;
 
7
 
 
8
use DBI;
 
9
use GenTest;
 
10
use GenTest::Constants;
 
11
use GenTest::Result;
 
12
use GenTest::Validator;
 
13
 
 
14
1;
 
15
 
 
16
sub init {
 
17
        my ($validator, $executors) = @_;
 
18
 
 
19
#       
 
20
# We could use the DBI connection already established by the Executor, however this will mean that
 
21
# the Validator SELECT statements will be interleaved with the other statements issued by the Executor.
 
22
# If we have transactions, SELECT-ing over entire tables will certainly change the behavoir of the transaction
 
23
#
 
24
 
 
25
        my $dsn = $executors->[0]->dsn();
 
26
        my $dbh = DBI->connect($dsn, undef, undef, { RaiseError => 1 });
 
27
        $validator->setDbh($dbh);
 
28
 
 
29
        $dbh->do("SET AUTOCOMMIT=ON");
 
30
 
 
31
        return 1;
 
32
 
 
33
}
 
34
 
 
35
 
 
36
sub validate {
 
37
        my ($validator, $executors) = @_;
 
38
 
 
39
        my $dbh = $validator->dbh();
 
40
        my $executor = $executors->[0];
 
41
        
 
42
        my $tables = $executor->tables();
 
43
        foreach my $table (@$tables) {
 
44
                my $sth = $dbh->prepare("
 
45
                        SELECT pk, COUNT(*) AS C
 
46
                        FROM `$table`
 
47
                        GROUP BY pk
 
48
                        HAVING C > 1
 
49
                ");
 
50
                $sth->execute();
 
51
                my $rows = $sth->rows();
 
52
                $sth->finish();
 
53
 
 
54
                if ($rows) {
 
55
                        $sth->finish();
 
56
                        say("Table $table contains duplicate primary keys.");
 
57
                        return STATUS_DATABASE_CORRUPTION;
 
58
                }
 
59
        }
 
60
 
 
61
        return STATUS_OK;
 
62
}
 
63
 
 
64
1;