~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/lib/GenTest/Transform/ConvertLiteralsToSubqueries.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# This program is free software; you can redistribute it and/or modify
3
 
# it under the terms of the GNU General Public License as published by
4
 
# the Free Software Foundation; version 2 of the License.
5
 
#
6
 
# This program is distributed in the hope that it will be useful, but
7
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
8
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9
 
# General Public License for more details.
10
 
#
11
 
# You should have received a copy of the GNU General Public License
12
 
# along with this program; if not, write to the Free Software
13
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
14
 
# USA
15
 
 
16
 
package GenTest::Transform::ConvertLiteralsToSubqueries;
17
 
 
18
 
require Exporter;
19
 
@ISA = qw(GenTest GenTest::Transform);
20
 
 
21
 
use strict;
22
 
use lib 'lib';
23
 
use GenTest;
24
 
use GenTest::Transform;
25
 
use GenTest::Constants;
26
 
 
27
 
my $initialized = 0;
28
 
 
29
 
sub transform {
30
 
        my ($class, $orig_query, $executor) = @_;
31
 
 
32
 
 
33
 
        if ($initialized != 1) {
34
 
                my $dbh = $executor->dbh();
35
 
                $dbh->do("CREATE DATABASE IF NOT EXISTS literals");
36
 
                $dbh->do("CREATE TABLE IF NOT EXISTS literals.integers (i1 INTEGER NOT NULL PRIMARY KEY)");
37
 
                foreach my $i (-128..256) {
38
 
                        $dbh->do("INSERT IGNORE INTO literals.integers VALUES ($i)");
39
 
                }
40
 
 
41
 
                $dbh->do("CREATE TABLE IF NOT EXISTS literals.strings (s1 VARCHAR(255) NOT NULL PRIMARY KEY)");
42
 
 
43
 
                $initialized = 1;
44
 
        }
45
 
 
46
 
        # We skip LIMIT queries because LIMIT N can not be converted into LIMIT ( SELECT ... ) 
47
 
        return STATUS_WONT_HANDLE if $orig_query =~ m{LIMIT}sio;
48
 
        return STATUS_WONT_HANDLE if $orig_query =~ m{GROUP BY \d}sio;
49
 
        return STATUS_WONT_HANDLE if $orig_query =~ m{ORDER BY \d}sio;
50
 
 
51
 
        my @transformed_queries;
52
 
 
53
 
        {
54
 
                my $new_integer_query = $orig_query;
55
 
                my @integer_literals;
56
 
 
57
 
                # We do not want to match "integers" in parts of dates, times, etc.
58
 
                # Thus only using those that are followed by certain characters or space.
59
 
                if ( $new_integer_query =~ m{\s+(\d+)(\s|\)|,|;)} ) {
60
 
                        $new_integer_query =~ s{\s+(\d+)}{
61
 
                                push @integer_literals, $1;
62
 
                                " (SELECT i1 FROM literals.integers WHERE i1 = $1 ) ";
63
 
                        }sgexi;
64
 
                }
65
 
 
66
 
                if ($new_integer_query ne $orig_query) {
67
 
                        push @transformed_queries, [
68
 
                                "INSERT IGNORE INTO literals.integers VALUES ".join(",", map { "($_)" } @integer_literals).";",
69
 
                                $new_integer_query." /* TRANSFORM_OUTCOME_UNORDERED_MATCH */"
70
 
                        ];
71
 
                }
72
 
        }
73
 
 
74
 
        {       
75
 
                my $new_string_query = $orig_query;
76
 
                my @string_literals;
77
 
 
78
 
                $new_string_query =~ s{\s+'(.+?)'}{
79
 
                        push @string_literals, $1;
80
 
                        " (SELECT s1 FROM literals.strings WHERE s1 = '$1' ) ";
81
 
                }sgexi;
82
 
        
83
 
                if ($new_string_query ne $orig_query) {
84
 
                        push @transformed_queries, [
85
 
                                "INSERT IGNORE INTO literals.strings VALUES ".join(",", map { "('$_')" } @string_literals).";",
86
 
                                $new_string_query." /* TRANSFORM_OUTCOME_UNORDERED_MATCH */"
87
 
                        ];
88
 
                }
89
 
        }
90
 
 
91
 
        if ($#transformed_queries > -1) {
92
 
                return \@transformed_queries;
93
 
        } else {
94
 
                return STATUS_WONT_HANDLE;
95
 
        }
96
 
}
97
 
 
98
 
1;