/[registar]/convert.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /convert.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by dpavlin, Tue Jun 19 09:27:42 2001 UTC revision 1.7 by dpavlin, Tue Jun 19 13:39:05 2001 UTC
# Line 82  sub Log { Line 82  sub Log {
82  }  }
83    
84  sub CondInsert {  sub CondInsert {
85          my @values=pop @_;      # chop last argument which is array          my $table = shift @_;
86          my ($table, $name, $key, $fields) = @_;          my $name = shift @_;
87          my $sql = "SELECT $name FROM $table WHERE ($name = $key)";          my $key = shift @_;
88          my $cnt = $pgdbh->do($sql);          my $fields = shift @_;
89          return 0 if ($cnt > 0);          my @values=@_;          # chop argument(s) are values array
90          return 0 if ($#values == 0);          my $sql = "SELECT count($name) FROM $table WHERE ($name = ?)";
91            my $sth = $pgdbh->prepare($sql);
92            my $ret = $sth->execute($key);
93            my ($cnt) = $sth->fetchrow_array();
94            return 0 if (!$cnt == 0);
95          my @valtpl;          my @valtpl;
96          for (my $i=0; $i<=$#values; $i++) { push @valtpl,"?" }          for (my $i=0; $i<=$#values; $i++) { push @valtpl,"?" }
97          $sql = "INSERT INTO $table $fields VALUES (".join(",",@valtpl).")";          $sql = "INSERT INTO $table $fields VALUES (".join(",",@valtpl).")";
98          my $sth = $pgdbh->prepare($sql);          $sth = $pgdbh->prepare($sql);
99          my $ret = $sth->execute(@values);          $ret = $sth->execute(@values);
100          my $err = $pgdbh->errstr;          my $err = $pgdbh->errstr;
101          print &Log("[$sql] [".join(",",@values)."]".$err) if ($err);          print &Log("[$sql] [".join(",",@values)."]".$err) if ($err);
102          return $ret;          return $ret;
# Line 101  sub CondInsert { Line 105  sub CondInsert {
105  sub tblATK {  sub tblATK {
106          my ($table, $fields, $data) = @_;          my ($table, $fields, $data) = @_;
107          my $count = 0;          my $count = 0;
108          my $sth = $pgdbh->prepare("INSERT INTO atk_inn (sifra, naziv, razno) VALUES (?, ?, ?)");          my $sth = $pgdbh->prepare("INSERT INTO $table (sifra, naziv, razno) VALUES (?, ?, ?)");
109          unless ($sth) {          unless ($sth) {
110                  print &Log("[$table-prepare] ".$pgdbh->errstr);                  print &Log("[$table-prepare] ".$pgdbh->errstr);
111                  return 0;                  return 0;
# Line 225  sub tblLijek { Line 229  sub tblLijek {
229                  $oprez = &ConvertString($oprez);                  $oprez = &ConvertString($oprez);
230                  $tel = &ConvertString($tel);                  $tel = &ConvertString($tel);
231                  $fax = &ConvertString($fax);                  $fax = &ConvertString($fax);
232                  CondInsert("atk_inn", "sifra", $sif_atk,                  CondInsert("atk", "sifra", $sif_atk,
233                          "(sifra, naziv, razno)", ($sif_atk, $naz_atk, ''));                          "(sifra, naziv, razno)", ($sif_atk, $naz_atk, ''));
234                  CondInsert("atk_inn", "sifra", $sif_inn,                  CondInsert("inn", "sifra", $sif_inn,
235                          "(sifra, naziv, razno)", ($sif_inn, $naz_inn, ''));                          "(sifra, naziv, razno)", ($sif_inn, $naz_inn, ''));
236                  CondInsert("proizvodjaci", "sifra", $sif_proizvodjac,                  CondInsert("proizvodjaci", "sifra", $sif_proizvodjac,
237                          "(sifra, naziv, drzava, zastupnistvo, mjesto, zip, ulica_i_broj, razno, telefon, fax)",                          "(sifra, naziv, drzava, zastupnistvo, mjesto, zip, ulica_i_broj, razno, telefon, fax)",

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.26