diff --git a/gendata.pl b/gendata.pl index 6121b614..a5ffb8b7 100755 --- a/gendata.pl +++ b/gendata.pl @@ -28,7 +28,7 @@ use Getopt::Long; my ($spec_file, $config_file, $debug, $engine, $help, $dsn, $rows, $varchar_len, - $views, $server_id, $seed, $short_column_names, $notnull); + $views, $server_id, $seed, $short_column_names, $notnull, $strict_fields); my $opt_result = GetOptions( 'help' => \$help, @@ -43,7 +43,8 @@ 'varchar-length=i' => \$varchar_len, 'server-id=i' > \$server_id, 'notnull' => \$notnull, - 'short_column_names' => \$short_column_names + 'short_column_names' => \$short_column_names, + 'strict_fields' => \$strict_fields ); if (defined $config_file) { @@ -66,6 +67,7 @@ varchar_length => $varchar_len, server_id => $server_id, notnull => $notnull, + strict_fields => $strict_fields, short_column_names => $short_column_names); diff --git a/gentest.pl b/gentest.pl index e6e2e193..f612b9fc 100755 --- a/gentest.pl +++ b/gentest.pl @@ -83,6 +83,7 @@ 'valgrind-xml', 'notnull', 'short_column_names', + 'strict_fields', 'debug', 'logfile=s', 'logconf=s', @@ -131,6 +132,7 @@ 'sqltrace', 'notnull', 'short_column_names', + 'strict_fields', 'logfile', 'logconf', 'report-tt-logdir', diff --git a/lib/GenTest/App/GenTest.pm b/lib/GenTest/App/GenTest.pm index db5f5fba..586ad69b 100644 --- a/lib/GenTest/App/GenTest.pm +++ b/lib/GenTest/App/GenTest.pm @@ -130,7 +130,8 @@ sub run { views => $self->config->views, varchar_length => $self->config->property('varchar-length'), sqltrace => $self->config->sqltrace, - short_column_names=> $self->config->short_column_names, + short_column_names => $self->config->short_column_names, + strict_fields => $self->config->strict_fields, notnull => $self->config->notnull); } $gendata_result = $datagen->run(); diff --git a/lib/GenTest/App/Gendata.pm b/lib/GenTest/App/Gendata.pm index 5f200391..95e3b09e 100644 --- a/lib/GenTest/App/Gendata.pm +++ b/lib/GenTest/App/Gendata.pm @@ -39,6 +39,7 @@ use constant FIELD_AUTO_INCREMENT => 6; use constant FIELD_SQL => 7; use constant FIELD_INDEX_SQL => 8; use constant FIELD_NAME => 9; +use constant FIELD_DEFAULT => 10; use constant TABLE_ROW => 0; use constant TABLE_ENGINE => 1; @@ -72,6 +73,7 @@ use constant GD_SERVER_ID => 8; use constant GD_SQLTRACE => 9; use constant GD_NOTNULL => 10; use constant GD_SHORT_COLUMN_NAMES => 11; +use constant GD_STRICT_FIELDS => 12; sub new { my $class = shift; @@ -87,6 +89,7 @@ sub new { 'varchar_length' => GD_VARCHAR_LENGTH, 'notnull' => GD_NOTNULL, 'short_column_names' => GD_SHORT_COLUMN_NAMES, + 'strict_fields' => GD_STRICT_FIELDS, 'server_id' => GD_SERVER_ID, 'sqltrace' => GD_SQLTRACE},@_); @@ -154,6 +157,11 @@ sub short_column_names { } +sub strict_fields { + return $_[0]->[GD_STRICT_FIELDS]; +} + + sub run { my ($self) = @_; @@ -219,12 +227,22 @@ sub run { croak "Dates and times are severly broken. Cannot be used for other than MySQL/Drizzle"; } } - $field_perms[FIELD_NULLABILITY] = $fields->{null} || $fields->{nullability} || [ (defined $self->[GD_NOTNULL] ? 'NOT NULL' : undef) ]; - $field_perms[FIELD_SIGN] = $fields->{sign} || [ undef ]; - $field_perms[FIELD_INDEX] = $fields->{indexes} || $fields->{keys} || [ undef, 'KEY' ]; - $field_perms[FIELD_CHARSET] = $fields->{charsets} || [ undef ]; - $field_perms[FIELD_COLLATION] = $fields->{collations} || [ undef ]; + if ($self->strict_fields) { + $field_perms[FIELD_NULLABILITY] = $fields->{null} || $fields->{nullability} || [ undef ]; + $field_perms[FIELD_DEFAULT] = $fields->{default} || [ undef ]; + $field_perms[FIELD_SIGN] = $fields->{sign} || [ undef ]; + $field_perms[FIELD_INDEX] = $fields->{indexes} || $fields->{keys} || [ undef ]; + $field_perms[FIELD_CHARSET] = $fields->{charsets} || [ undef ]; + $field_perms[FIELD_COLLATION] = $fields->{collations} || [ undef ]; + } else { + $field_perms[FIELD_NULLABILITY] = $fields->{null} || $fields->{nullability} || [ (defined $self->[GD_NOTNULL] ? 'NOT NULL' : undef) ]; + $field_perms[FIELD_SIGN] = $fields->{sign} || [ undef ]; + $field_perms[FIELD_INDEX] = $fields->{indexes} || $fields->{keys} || [ undef, 'KEY' ]; + $field_perms[FIELD_CHARSET] = $fields->{charsets} || [ undef ]; + $field_perms[FIELD_COLLATION] = $fields->{collations} || [ undef ]; + } + $data_perms[DATA_NUMBER] = $data->{numbers} || ['digit', 'digit', 'digit', 'digit', (defined $self->[GD_NOTNULL] ? 'digit' : 'null') ]; # 20% NULL values $data_perms[DATA_STRING] = $data->{strings} || ['letter', 'letter', 'letter', 'letter', (defined $self->[GD_NOTNULL] ? 'letter' : 'null') ]; $data_perms[DATA_BLOB] = $data->{blobs} || [ 'data', 'data', 'data', 'data', (defined $self->[GD_NOTNULL] ? 'data' : 'null') ]; @@ -260,7 +278,7 @@ sub run { my @fields = (undef); - foreach my $cycle (FIELD_TYPE, FIELD_NULLABILITY, FIELD_SIGN, FIELD_INDEX, FIELD_CHARSET, FIELD_COLLATION) { + foreach my $cycle (FIELD_TYPE, FIELD_NULLABILITY, FIELD_DEFAULT, FIELD_SIGN, FIELD_INDEX, FIELD_CHARSET, FIELD_COLLATION) { @fields = map { my $old_field = $_; if (not defined $field_perms[$cycle]) { @@ -298,7 +316,7 @@ sub run { # $field_copy[FIELD_INDEX] = 'nokey' if $field_copy[FIELD_INDEX] eq ''; my $field_name; - if ($self->[GD_SHORT_COLUMN_NAMES]) { + if ($self->short_column_names) { $field_name = 'c'.($field_no++); } else { $field_name = "col_".join('_', grep { $_ ne '' } @field_copy); @@ -347,11 +365,11 @@ sub run { $fields[$field_id]->[FIELD_SQL] = "`$field_name` ". join(' ' , grep { $_ ne '' } @field_copy); - if ($field_copy[FIELD_TYPE] =~ m{timestamp}sio ) { - if (defined $self->[GD_NOTNULL]) { - $field->[FIELD_SQL] .= ' NOT NULL'; + if (!$self->strict_fields && $field_copy[FIELD_TYPE] =~ m{timestamp}sio ) { + if (defined $self->[GD_NOTNULL]) { + $field->[FIELD_SQL] .= ' NOT NULL'; } else { - $field->[FIELD_SQL] .= ' NULL DEFAULT 0'; + $field->[FIELD_SQL] .= ' NULL DEFAULT 0'; } } } diff --git a/runall-new.pl b/runall-new.pl index 19bdf4ba..10f76696 100755 --- a/runall-new.pl +++ b/runall-new.pl @@ -69,7 +69,7 @@ $start_dirty, $filter, $build_thread, $sqltrace, $testname, $report_xml_tt, $report_xml_tt_type, $report_xml_tt_dest, $notnull, $logfile, $logconf, $report_tt_logdir, $querytimeout, $no_mask, - $short_column_names); + $short_column_names, $strict_fields); my $gendata=''; ## default simple gendata @@ -106,6 +106,7 @@ 'gendata:s' => \$gendata, 'notnull' => \$notnull, 'short_column_names' => \$short_column_names, + 'strict_fields' => \$strict_fields, 'seed=s' => \$seed, 'mask=i' => \$mask, 'mask-level=i' => \$mask_level, @@ -385,6 +386,7 @@ 'filter', 'notnull', 'short_column_names', + 'strict_fields', 'valgrind', 'valgrind-xml', 'testname', @@ -441,6 +443,7 @@ $gentestProps->filter($filter) if defined $filter; $gentestProps->notnull($notnull) if defined $notnull; $gentestProps->short_coulmn_names($short_column_names) if defined $short_column_names; +$gentestProps->strict_fields($strict_fields) if defined $strict_fields; $gentestProps->valgrind(1) if $valgrind; $gentestProps->sqltrace($sqltrace) if $sqltrace; $gentestProps->querytimeout($querytimeout) if defined $querytimeout; diff --git a/runall.pl b/runall.pl index 4700f95a..cd555273 100755 --- a/runall.pl +++ b/runall.pl @@ -69,7 +69,7 @@ $start_dirty, $filter, $build_thread, $testname, $report_xml_tt, $report_xml_tt_type, $report_xml_tt_dest, $notnull, $sqltrace, $lcov, $transformers, $logfile, $logconf, $report_tt_logdir,$querytimeout, - $short_column_names); + $short_column_names, $strict_fields); my $threads = my $default_threads = 10; my $queries = my $default_queries = 1000; @@ -106,6 +106,7 @@ 'skip-gendata' => \$skip_gendata, 'notnull' => \$notnull, 'short_column_names' => \$short_column_names, + 'strict_fields' => \$strict_fields, 'seed=s' => \$seed, 'mask=i' => \$mask, 'mask-level=i' => \$mask_level, @@ -420,6 +421,7 @@ push @gentest_options, "--gendata=$gendata" if not defined $skip_gendata; push @gentest_options, "--notnull" if defined $notnull; push @gentest_options, "--short_column_names" if defined $short_column_names; +push @gentest_options, "--strict_fields" if defined $strict_fields; push @gentest_options, "--engine=$engine" if defined $engine; push @gentest_options, "--rpl_mode=$rpl_mode" if defined $rpl_mode; push @gentest_options, map {'--validator='.$_} split(/,/,$validators) if defined $validators;