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

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/conf/smf/parse.pl

  • 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
 
use strict;
2
 
use Data::Dumper;
3
 
use DBI;
4
 
 
5
 
my @php_files = @ARGV;
6
 
my %queries;
7
 
 
8
 
foreach my $php_file (@php_files) {
9
 
        open (FILE, $php_file) or die $!;
10
 
        read (FILE, my $php_code, -s $php_file) or die $!;
11
 
        close FILE;
12
 
 
13
 
        my @file_selects = $php_code =~ m{(SELECT.*?)'}sog;
14
 
        foreach my $file_select (@file_selects) {
15
 
                $file_select =~ s{\{db_prefix\}}{smf_}sgio;
16
 
                my ($trial_select , $grammar_select) = ($file_select , $file_select);
17
 
 
18
 
                $trial_select =~ s{(\{.*?\})}{1}sgio;
19
 
 
20
 
                $grammar_select =~ s{\{([a-z_]*?):[a-z_]*?\}}{_\1}sgio;
21
 
                $grammar_select =~ s{\{STEP_LOW\}}{_step_low}sgio;
22
 
                $grammar_select =~ s{\{STEP_HIGH\}}{_step_high}sgio;
23
 
 
24
 
                push @{$queries{'select'}} , [ $trial_select , $grammar_select ];
25
 
        }
26
 
 
27
 
        my @file_updates = $php_code =~  m{(UPDATE.*?)'}sog;
28
 
        foreach my $file_update (@file_updates) {
29
 
                $file_update =~ s{\{db_prefix\}}{smf_}sgio;
30
 
                my ($trial_update , $grammar_update) = ($file_update, $file_update);
31
 
 
32
 
                $trial_update =~ s{(\{.*?\})}{1}sgio;
33
 
                $grammar_update =~ s{\{([a-z_]*?):[a-z_]*?\}}{_\1}sgio;
34
 
                push @{$queries{'update'}} , [ $trial_update , $grammar_update ];
35
 
        }
36
 
 
37
 
        my @file_deletes = $php_code =~  m{(DELETE.*?)'}sog;
38
 
        foreach my $file_delete (@file_deletes) {
39
 
                $file_delete =~ s{\{db_prefix\}}{smf_}sgio;
40
 
                my ($trial_delete , $grammar_delete) = ($file_delete, $file_delete);
41
 
 
42
 
                $trial_delete =~ s{(\{.*?\})}{1}sgio;
43
 
                $grammar_delete =~ s{\{([a-z_]*?):[a-z_]*?\}}{_\1}sgio;
44
 
                push @{$queries{'delete'}} , [ $trial_delete , $grammar_delete ];
45
 
        }
46
 
 
47
 
        my @file_insertsphp = $php_code =~ m{'db_insert']\((.*?)\);}sgio;
48
 
        my @file_inserts;
49
 
        
50
 
        foreach my $file_insertphp (@file_insertsphp) {
51
 
                $file_insertphp =~ s{[\r\n]}{}sgio;
52
 
                my ($insert_replace, $table) = $file_insertphp =~ m{'(.*?)'.*?'(.*?)'}sio;
53
 
 
54
 
                $insert_replace = 'insert '.$insert_replace if $insert_replace !~ m{^(insert|replace)}sgio;
55
 
 
56
 
                $table =~ s{\{db_prefix\}}{smf_}sgio;
57
 
 
58
 
                die $file_insertphp if $table eq '';
59
 
                my ($array) = $file_insertphp =~ m{array\((.*?)\)}sio;
60
 
                my @array_elements = split (',', $array);
61
 
 
62
 
                my @col_names;
63
 
                my @col_values;
64
 
                my @col_types;
65
 
                foreach my $array_element (@array_elements) {
66
 
                        next if $array_element =~ m{^\s+$}sgio;
67
 
                        my ($col_name, $col_type) = $array_element =~ m{'(.*?)'\s+=>\s+'(.*?)'}sio;
68
 
                        my $col_value;
69
 
                        $col_type =~ s{\-}{_}sgio;
70
 
                        $col_type = "_".$col_type;
71
 
                        if (defined $col_name) {
72
 
                                $col_type eq 'unknown_type' if $col_type eq '';
73
 
                                push @col_names, $col_name;
74
 
                                push @col_values, 1;
75
 
                                push @col_types, $col_type;     
76
 
                        }
77
 
                }
78
 
 
79
 
                if ($#col_names > -1) {
80
 
                        push @{$queries{'insert_replace'}} , [
81
 
                                 uc($insert_replace)." INTO $table (".join(',', @col_names).") VALUES (".join(',', @col_values).")",
82
 
                                 uc($insert_replace)." INTO $table (".join(',', map {'`'.$_.'`' }@col_names).") VALUES (".join(',', @col_types).")"
83
 
                        ]
84
 
                }
85
 
        }
86
 
}
87
 
 
88
 
my $dbh = DBI->connect('dbi:mysql:database=smf2:user=root', undef , undef , { PrintError => 1});
89
 
 
90
 
my %errors;
91
 
print '
92
 
        query:
93
 
                insert_replace | insert_replace | insert_replace | insert_replace | insert_replace | insert_replace |
94
 
                update | update | update | update | update |
95
 
                delete |
96
 
                select | select | select ;
97
 
 
98
 
        _int: _mediumint_unsigned | _tinyint_unsigned | _digit ;
99
 
        _string: _english | _varchar(1) | _varchar(2) | _varchar(255) | REPEAT ( _varchar(2) , _tinyint_unsigned );
100
 
        _string_16: _english | _varchar(1) | _varchar(2) | _varchar(16) |  REPEAT ( _varchar(2) , _digit );
101
 
        _string_40: _english | _varchar(1) | _varchar(2) | _varchar(40) |  REPEAT ( _varchar(2) , _digit );
102
 
        _string_255: _english | _varchar(1) | _varchar(2) | _varchar(255) | REPEAT ( _varchar(2) , _tinyint_unsigned );
103
 
        _string_65534: _english | _varchar(1) | _varchar(2) | _varchar(255) | REPEAT ( _varchar(2) , _smallint_unsigned );
104
 
        _array_int: _int | _array_int , _int ;
105
 
        _array_string: _string | _string , _string ;
106
 
        _raw: _digit ;
107
 
        _step_low: _digit | _tinyint_unsigned ;
108
 
        _step_high: _tinyint_unsigned | _smallint_unsigned ;
109
 
';
110
 
 
111
 
foreach my $query_type ('select', 'insert_replace','update','delete') {
112
 
        my $type_queries = $queries{$query_type};
113
 
        my @type_rules;
114
 
        foreach my $type_query (@$type_queries) {
115
 
                my ($trial_query, $grammar_rule) = ($type_query->[0], $type_query->[1]);
116
 
                my $sth = $dbh->prepare($trial_query);
117
 
                $sth->execute();
118
 
                $errors{$sth->err()}++;
119
 
 
120
 
                if (($sth->err() == 0) || ($sth->err() == 1062)) {
121
 
                        $grammar_rule =~ s{(data|next_time|time_offset|time_regularity|time_unit|time_updated|time_removed)}{`$1`}sgio;
122
 
                        $grammar_rule =~ s{``}{`}sgio;
123
 
                        push @type_rules, $grammar_rule;
124
 
                }
125
 
        }
126
 
        print "\n\n$query_type:\n".join("|\n\t", @type_rules).";\n\n";
127
 
}
128
 
 
129
 
print STDERR Dumper \%errors;
130
 
exit;