common/tools/bitops.pl
changeset 1281 c5308055d94d
parent 1280 61388ab6ba2c
child 1285 05c7556875df
equal deleted inserted replaced
1280:61388ab6ba2c 1281:c5308055d94d
     8 
     8 
     9 use Getopt::Long;
     9 use Getopt::Long;
    10 
    10 
    11 my $help = 0;
    11 my $help = 0;
    12 my $create = 0;
    12 my $create = 0;
       
    13 my $stringcheck = 0;
    13 my $file = '';
    14 my $file = '';
    14 my $id = '';
    15 my $id = '';
    15 my $append = 0;
    16 my $append = 0;
    16 my $delete = '';
    17 my $delete = '';
    17 my $verbose = 0;
    18 my $verbose = 0;
    18 my $dryrun = 0;
    19 my $dryrun = 0;
    19 GetOptions((
    20 GetOptions((
    20 	'create!' => \$create,
    21 	'create!' => \$create,
       
    22 	'stringcheck!' => \$stringcheck,
    21 	'file=s' => \$file,
    23 	'file=s' => \$file,
    22 	'update=s' => \$id,
    24 	'update=s' => \$id,
    23 	'append!' => \$append,
    25 	'append!' => \$append,
    24 	'remove=s' => \$delete,
    26 	'remove=s' => \$delete,
    25 	'help!' => \$help,
    27 	'help!' => \$help,
    32   print <<_EOH;
    34   print <<_EOH;
    33 bitops
    35 bitops
    34 Executes operations on the BIT db
    36 Executes operations on the BIT db
    35 
    37 
    36 Usage:
    38 Usage:
    37   bitops.pl -c -f FILE
    39   bitops.pl -c [-n] -f FILE
    38   bitops.pl -u ID [-a] -f FILE
    40   bitops.pl -u ID [-a] -f FILE
    39   bitops.pl -r ID
    41   bitops.pl -r ID
    40 
    42 
    41 Options:
    43 Options:
    42   -h, --help            Show this help message and exit
    44   -h, --help            Show this help message and exit
    43   -c, --create          Create entry for a new build then set the attributes to
    45   -c, --create          Create entry for a new build then set the attributes to
    44                         the values provided in FILE. Returns the build id for
    46                         the values provided in FILE. Returns the build id for
    45                         the newly created build.
    47                         the newly created build.
       
    48   -s, --stringcheck     Check that the build_id_string is unique, otherwise do
       
    49                         not create build.
    46   -u ID, --update ID    Update entry for build number ID with the values
    50   -u ID, --update ID    Update entry for build number ID with the values
    47                         provided in FILE. For the update operation only the
    51                         provided in FILE. For the update operation only the
    48                         entry in the BUILDS table will be actually updated, the
    52                         entry in the BUILDS table will be actually updated, the
    49                         entries in the other tables will be deleted, then the
    53                         entries in the other tables will be deleted, then the
    50                         data supplied will be inserted (this behaviour can be
    54                         data supplied will be inserted (this behaviour can be
   326 
   330 
   327 ConnectToDB();
   331 ConnectToDB();
   328 my $newbuildid = -1;
   332 my $newbuildid = -1;
   329 if ($create)
   333 if ($create)
   330 {
   334 {
       
   335   if ($stringcheck && defined $builds_entry->{build_id_string} && !$dryrun)
       
   336   {
       
   337     print "Check that the build_id_string is unique\n" if ($verbose);
       
   338     my $query=$db->prepare("select id from builds where build_id_string='$builds_entry->{build_id_string}';");
       
   339     $query->execute();
       
   340     my @ids_existing=();
       
   341     my $id_existing=-1;
       
   342     $query->bind_columns(\$id_existing);
       
   343     while($query->fetch())
       
   344     {
       
   345       push(@ids_existing, $id_existing);
       
   346     }
       
   347     if (scalar(@ids_existing))
       
   348     {
       
   349       print "ERROR: The supplied build_id_string already exists for build id: @ids_existing. Not creating build.\n";
       
   350       exit(1);
       
   351 	}
       
   352   }
       
   353   
   331   if (keys %{$builds_entry})
   354   if (keys %{$builds_entry})
   332   {
   355   {
   333     my $field_list = '';
   356     my $field_list = '';
   334     my $qm_list = '';
   357     my $qm_list = '';
   335     my @fields = ();
   358     my @fields = ();