head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2001.09.28.02.35.45;	author rdean;	state Exp;
branches;
next	1.1;

1.1
date	2001.09.28.01.51.46;	author rdean;	state Exp;
branches;
next	;


desc
@@


1.2
log
@updated fields
@
text
@#!/usr/bin/perl -w
use strict;
use diagnostics;
use DBI;

$::db_host = "localhost";
$::db_user = "kong";
$::db_pass = "ratsnav";
$::db_name = "kong";
my $verbose = 0;

sub ConnectToDatabase {
    if (!defined $::db) {
        $::db = DBI->connect("DBI:mysql:host=$::db_host;database=$::db_name", $::db_user, $::db_pass)
            || die "could not connect to database";
    }
}

sub SqlQuote {
    my ($str) = (@@_);
#     if (!defined $str) {
#         confess("Undefined passed to SqlQuote");
#     } 
    $str =~ s/([\\\'])/\\$1/g;
    $str =~ s/\0/\\0/g;
    # If it's been SqlQuote()ed, then it's safe, so we tell -T that.
    #$str = detaint_string($str);
    return "'$str'";
}   

sub SendSQL {
    my ($str, $dontshadow) = (@@_);
    $::currentquery = $::db->prepare($str);
    $::currentquery->execute || die "$str: " . $::db->errstr;
}

sub MoreSQLData {
    if (defined @@::fetchahead) {
        return 1;
    }
    if (@@::fetchahead = $::currentquery->fetchrow_array) {
        return 1;
    }
    return 0;
}

sub FetchSQLData {
    if (defined @@::fetchahead) {
        my @@result = @@::fetchahead;
        undef @@::fetchahead;
        return @@result;
    }
    return $::currentquery->fetchrow_array;
}

sub FetchOneColumn {
    my @@row = FetchSQLData();
    return $row[0];
}

my $dryRun = 0;
if(!$dryRun) {
    ConnectToDatabase();

    SendSQL("delete from bugs");  # all rows
    SendSQL("delete from buckets");
    SendSQL("delete from big_desc_hist");
};

while(my $line = <STDIN>) {
   print("==>".$line) if $verbose;
   chomp($line);
   my @@fields = ();
   my $quoted = 0;
   my $partialToken;
   while(length($line)) {  # for every token
   print("-->$line\n") if $verbose;
      $partialToken = '';
      if($line =~ s/^,//)  {  # if empty
         push(@@fields,"");
         print("got empty\n") if $verbose;
      } elsif($line =~ s/^([^",][^,]*),?//)  {  # unquoted token
         push(@@fields,$1);
         print("got unquoted\n") if $verbose;
      } else {  # else quoted token
         $line =~ s/^"// or die("internal error");
         while(1) { # for each char (until end of file)
            while(length($line) == 0) { 
               $partialToken .= "\n";
               $line = <STDIN>;
               print("continue ->{$line}") if $verbose;
               chomp($line) if defined($line);
            };
            if(!defined($line)) {
               $line = "";
               last;
            }
            print("  >$line\n") if $verbose;
            if($line =~ s/^""//) {  # "" is escaped "
                $partialToken .= '"';
            } elsif ($line =~ s/^",// or $line =~ s/^"$//) {
               last;
            } elsif ($line =~ /^"/) {
               print("########### parse error {$partialToken} {$line}\n");
               $line =~ s/.//;  # remove first char
            } else {
               $line =~ s/^(.)//;
               $partialToken .= $1;
            }
         }
         push(@@fields,$partialToken);
         print("got quoted\n") if $verbose;
      };
   };

   my($framework,$number,$name,$priority,$program,$pdsndev,undef,$pdsntest,undef,$hadev,undef,$hatest,undef,
     $ggsndev,undef,$ggsntest,undef,undef,undef,undef,$mustdo,$long) = @@fields;
   #print ("==> $name program=$program priority=$priority pdsndev=$pdsndev ggsntest=$ggsntest must=$mustdo\n");
   next if (!defined($mustdo) or $mustdo !~ /^\d+$/);
   #print ("==>       number=$number priority=$priority\n");
   $number =~ s/^\s+//;  # trim leading white space
   $number =~ s/\s+$//;  # trim tailing white space
   $name = "$name ($number)";
   my $release = $mustdo ? "2.0" : "3.0";
   $long = "" if !defined($long);
   my $component = "multiple";
   if($ggsndev && !$pdsndev && !$hadev) {
      $component = "GGSN";
   } elsif(!$ggsndev && $pdsndev && !$hadev) {
      $component = "PDSN";
   } elsif(!$ggsndev && !$pdsndev && $hadev) {
      $component = "HA";
   };
   if($framework eq "Advanced DEV") {
      $framework = "AdvancedDev";
   } elsif($framework =~ /oadmap/) {
      $framework = "Roadmap";
   } elsif($framework =~ /Product DEV/) {
      $framework = "DevImprovements";
   };
   my $sql = "insert into bugs set short_desc = ".SqlQuote($name).
                                ",target_milestone   = ".SqlQuote($release).
                                ",priority   = ".SqlQuote($priority).
                                ",status   = ".SqlQuote("new").
                                ",groupset   = 0 ".
                                ",assigned_to   = 2 ".
                                ",bug_severity   = ".SqlQuote("normal").
                                ",sponsor   = ".SqlQuote("other").
                                ",plan   = ".SqlQuote("Cambia").
                                ",creation_ts = now() ".
                                ",delta_ts = now() ".
                                ",reporter   = 2 ".
                                ",component   = ".SqlQuote($component).
                                ",committee   = ".SqlQuote($framework).
                                ",big_desc   = ".SqlQuote($long);
   if($dryRun) {
       print("$sql\n");
   } else {
       SendSQL($sql);
       SendSQL("SELECT LAST_INSERT_ID()");
       my $id = FetchOneColumn();
       print("id is $id framework {$framework} {$number}\n");
       #print("id is $id pdsn {$pdsndev} {$pdsntest} ha {$hadev} {$hatest} ggsn {$ggsndev} {$ggsntest}\n");
       SendSQL("INSERT INTO buckets SET effort = $pdsndev,  pool = 'pdsn dev',  stage = 'pre-req', id = $id")
          if $pdsndev =~ /\d/;
       SendSQL("INSERT INTO buckets SET effort = $pdsntest, pool = 'pdsn test', stage = 'pre-req', id = $id")
          if $pdsntest =~ /\d/;
       SendSQL("INSERT INTO buckets SET effort = $hadev,    pool = 'ha dev',    stage = 'pre-req', id = $id")
          if $hadev =~ /\d/;
       SendSQL("INSERT INTO buckets SET effort = $hatest,   pool = 'ha test',   stage = 'pre-req', id = $id")
          if $hatest =~ /\d/;
       SendSQL("INSERT INTO buckets SET effort = $ggsndev,  pool = 'ggsn dev',  stage = 'pre-req', id = $id")
          if $ggsndev =~ /\d/;
       SendSQL("INSERT INTO buckets SET effort = $ggsntest, pool = 'ggsn test', stage = 'pre-req', id = $id")
          if $ggsntest =~ /\d/;
       SendSQL("INSERT INTO big_desc_hist " .
               "(bug_id,who,bug_when,thetext,version) VALUES " .
               "($id,2,now(),".SqlQuote($long).",0)");
   };
}

#SendSQL("select bug_id from bugs");
#my $rick = FetchSQLData();
#print("id is $rick\n");




@


1.1
log
@initial
@
text
@d135 1
a135 1
      $framework = "Advanced_Development";
d137 1
a137 1
      $framework = "Roadmap_Features";
d139 1
a139 1
      $framework = "Development_Improvements";
d149 1
a149 1
                                ",product   = ".SqlQuote("Cambia").
@

