~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to lib/GenTest/Executor.pm

merge from internal tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
use strict;
14
14
use GenTest;
 
15
use GenTest::Constants;
15
16
 
16
17
use constant EXECUTOR_DSN               => 0;
17
18
use constant EXECUTOR_DBH               => 1;
18
19
use constant EXECUTOR_ID                => 2;
19
 
use constant EXECUTOR_DEBUG             => 3;
20
 
use constant EXECUTOR_ROW_COUNTS        => 4;
21
 
use constant EXECUTOR_EXPLAIN_COUNTS    => 5;
22
 
use constant EXECUTOR_EXPLAIN_QUERIES   => 6;
23
 
use constant EXECUTOR_ERROR_COUNTS      => 7;
 
20
use constant EXECUTOR_ROW_COUNTS        => 3;
 
21
use constant EXECUTOR_EXPLAIN_COUNTS    => 4;
 
22
use constant EXECUTOR_EXPLAIN_QUERIES   => 5;
 
23
use constant EXECUTOR_ERROR_COUNTS      => 6;
24
24
 
25
25
1;
26
26
 
27
27
sub new {
28
 
        my $class = shift;
 
28
    my $class = shift;
29
29
        
30
30
        my $executor = $class->SUPER::new({
31
31
                'dsn'   => EXECUTOR_DSN,
32
32
                'dbh'   => EXECUTOR_DBH,
33
 
                'debug' => EXECUTOR_DEBUG
34
33
        }, @_);
35
 
 
36
 
        return $executor;
 
34
    
 
35
    return $executor;
37
36
}
38
37
 
39
38
sub dbh {
52
51
        $_[0]->[EXECUTOR_DSN] = $_[1];
53
52
}
54
53
 
55
 
sub debug {
56
 
        return $_[0]->[EXECUTOR_DEBUG];
57
 
}
58
 
 
59
54
sub id {
60
55
        return $_[0]->[EXECUTOR_ID];
61
56
}
64
59
        $_[0]->[EXECUTOR_ID] = $_[1];
65
60
}
66
61
 
 
62
sub type {
 
63
    my ($self) = @_;
 
64
    if ($self =~ m/GenTest::Executor::JavaDB/) {
 
65
        return DB_JAVADB;
 
66
    }elsif ($self =~/^GenTest::Executor::MySQL/) {
 
67
        return DB_MYSQL;
 
68
    }elsif ($self =~ m/GenTest::Executor::Postgres/) {
 
69
        return DB_POSTGRES;
 
70
    } else {
 
71
        return DB_UNKNOWN;
 
72
    }
 
73
    
 
74
}
 
75
 
 
76
my @dbid = ("Unknown","MySQL","Postgres","JavaDB");
 
77
 
 
78
sub getName {
 
79
    my ($self) = @_;
 
80
    return $dbid[$self->type()];
 
81
}
 
82
 
 
83
sub preprocess {
 
84
    my ($self, $query) = @_;
 
85
 
 
86
    my $id = $dbid[$self->type()];
 
87
 
 
88
    
 
89
    # Keep if match (+)
 
90
 
 
91
    # print "... $id before: $query \n";
 
92
    
 
93
    $query =~ s/\/\*\+[a-z:]*$id[a-z:]*:([^*]*)\*\//\1/gi;
 
94
 
 
95
    # print "... after: $query \n";
 
96
 
 
97
    return $query;
 
98
}
 
99
 
 
100
## This array maps SQL State class (2 first letters) to a status. This
 
101
## list needs to be extended
 
102
my %class2status = (
 
103
    "07" => STATUS_SEMANTIC_ERROR, # dynamic SQL error
 
104
    "08" => STATUS_SEMANTIC_ERROR, # connection exception
 
105
    "22" => STATUS_SEMANTIC_ERROR, # data exception
 
106
    "23" => STATUS_SEMANTIC_ERROR, # integrity constraint violation
 
107
    "25" => STATUS_TRANSACTION_ERROR, # invalid transaction state
 
108
    "42" => STATUS_SYNTAX_ERROR    # syntax error or access rule
 
109
                                   # violation
 
110
    
 
111
    );
 
112
 
 
113
sub findStatus {
 
114
    my ($self, $state) = @_;
 
115
 
 
116
    my $class = substr($state, 0, 2);
 
117
    if (defined $class2status{$class}) {
 
118
        return $class2status{$class};
 
119
    } else {
 
120
        return STATUS_UNKNOWN_ERROR;
 
121
    }
 
122
}
 
123
 
67
124
1;