/[corp]/sql/fill.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

Contents of /sql/fill.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Thu Mar 15 07:51:20 2001 UTC (21 years, 8 months ago) by dpavlin
Branch: DbP, MAIN
CVS Tags: r1, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
initial import

1 #!/usr/local/bin/perl -w
2
3 die "Kao argument ime datoteke (npr. xxxx.txt) !!" if (! defined($ARGV[0]));
4 $file=$ARGV[0];
5
6 $db="corp";
7 $dir="/home/dpavlin/corp";
8
9 use DBI;
10
11 $type=$file;
12 $type=~s/\.[^\.]+//g;
13
14 #---
15
16 my $dbh = DBI->connect("DBI:Pg:dbname=$db","","") || die $DBI::errstr;
17 open(IN,"< $file") || die "ne mogu otvoriti $file";
18 while (<IN>) {
19 chomp;
20 s/\015//g; # kill cr
21
22 tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2
23
24 s/^"//;
25 s/"$//;
26 s/\t"/\t/g;
27 s/"\t/\t/g;
28 s/\t /\t/g;
29 s/ \t/\t/g;
30 s/ */ /g;
31 s/'/\\'/g;
32
33 next if (/^#/);
34
35 @arr = split(/\t/,$_);
36
37 if ($type eq "products_rx") {
38 next if (! $arr[1]);
39 $have_smpc="false";
40 if ($arr[9]) {
41 $tm="'$arr[9]'";
42 } else {
43 $tm="null";
44 }
45 $arr[8] = 0 if (! $arr[8]);
46 $sql_insert="insert into products values ('$arr[1]','$arr[2]','$arr[3]','$arr[4]','$arr[7]','$arr[5]','$arr[6]',$arr[8],$have_smpc,$tm) ";
47 } elsif ($type eq "products_dddi") {
48 next if (! $arr[1]);
49 $sql_insert="insert into products values ('$arr[1]','$arr[2]','$arr[3]','$arr[4]','DDDI','$arr[5]','Zagreb','$arr[6]',false) ";
50 } elsif ($type eq "menu") {
51 $sql_insert="insert into menu values ('$arr[0]','$arr[1]','$arr[2]') ";
52 } elsif ($type eq "worldwide") {
53 $sql_insert="insert into worldwide values ($arr[0],'$arr[1]','$arr[2]', '$arr[3]', '$arr[4]', '$arr[5]', '$arr[6]', '$arr[7]', '$arr[8]', '$arr[9]', '$arr[10]') ";
54 } elsif ($type eq "emails") {
55 $from=shift @arr;
56 $to=join(",",@arr); $to=~s/ *//g; $to=~s/,+/,/g;
57 $sql_insert="insert into emails values ('$from','$to')";
58 } elsif ($type eq "history") {
59 $sql_insert="insert into history values ('$arr[0]','$arr[1]','$arr[2]') ";
60 } elsif ($type eq "countries") {
61 $sql_insert="insert into countries values ('$arr[0]','$arr[1]') ";
62 } elsif ($type eq "vet_type") {
63 $sql_insert="insert into vet_type values ('$arr[0]','$arr[1]') ";
64 } elsif ($type eq "vet_animal") {
65 $sql_insert="insert into vet_animal values ('$arr[0]','$arr[1]') ";
66 } elsif ($type eq "vet_products") {
67 $vet_type=shift @arr;
68 $smpc=$arr[5];
69 foreach $animal (split(/,\s*/,shift @arr)) {
70 $sql="insert into vet_animal_product values ('$animal',$smpc)";
71 print "----$sql\n";
72 $dbh->do("$sql") || die $dbh->errstr();
73 }
74 $sql_insert="insert into vet_products values ('$arr[0]','$arr[1]','$arr[2]','$arr[3]',$arr[4],'$vet_type') ";
75 } elsif ($type eq "analysts") {
76 $sql_insert="insert into analysts (company,analyst,e_mail) values ('$arr[0]','$arr[1]','$arr[2]') ";
77 } else {
78 die "Nepoznat tip datoteke $type !!";
79 }
80
81 print "--$sql_insert\n";
82 $dbh->do("$sql_insert") || die $dbh->errstr();
83
84 }
85 $dbh->do("update products set have_smpc=true where smpc in (select distinct smpc
86 from paragraphs)");
87
88 print "\n";

  ViewVC Help
Powered by ViewVC 1.1.26