3
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
4
# Use is subject to license terms.
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; version 2 of the License.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21
use lib "$ENV{RQG_HOME}/lib";
25
use GenTest::Constants;
26
use GenTest::Properties;
27
use GenTest::Generator::FromGrammar;
28
use GenTest::Executor;
31
my $DEFAULT_QUERIES = 1000;
33
my @ARGV_saved = @ARGV;
35
my $opt_result = GetOptions($options,
45
help() if !$opt_result;
47
my $config = GenTest::Properties->new(options => $options,
48
defaults => {seed => 1,
49
queries=> $DEFAULT_QUERIES},
57
required => ['grammar'],
60
my $seed = $config->seed;
61
if ($seed eq 'time') {
63
say("Converting --seed=time to --seed=$seed");
66
my $generator = GenTest::Generator::FromGrammar->new(
67
grammar_file => $config->grammar,
69
mask => $config->mask,
70
mask_level => $config->property('mask-level')
73
return STATUS_ENVIRONMENT_FAILURE if not defined $generator;
77
if (defined $config->dsn) {
78
$executor = GenTest::Executor->newFromDSN($config->dsn);
79
exit (STATUS_ENVIRONMENT_FAILURE) if not defined $executor;
82
if (defined $executor) {
83
my $init_result = $executor->init();
84
exit ($init_result) if $init_result > STATUS_OK;
85
$executor->cacheMetaData();
88
foreach my $i (1..$config->queries) {
89
my $queries = $generator->next([$executor]);
91
(not defined $queries) ||
94
say("Grammar produced an empty query. Terminating.");
95
exit(STATUS_ENVIRONMENT_FAILURE);
97
my $sql = join('; ',@$queries);
105
$0 - Generate random queries from an SQL grammar and pipe them to STDOUT
107
--grammar : Grammar file to use for generating the queries (REQUIRED);
108
--seed : Seed for the pseudo-random generator
109
--queries : Numer of queries to generate (default $DEFAULT_QUERIES);
110
--dsn : The DSN of the database that will be used to resolve rules such as _table , _field
111
--mask : A seed to a random mask used to mask (reeduce) the grammar.
112
--mask-level: How many levels deep the mask is applied (default 1)
113
--help : This help message