/[informatika.old]/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 /fill.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Fri Jan 25 14:47:43 2002 UTC (22 years, 2 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +5 -2 lines
File MIME type: text/plain
Error occurred while calculating annotation data.
sap organizacijske jedinice

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 use DBI;
7
8 $type=$file;
9 $type=~s/\.[^\.]+//g;
10
11 #---
12
13 my $dbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr;
14 open(IN,"< $file") || die "ne mogu otvoriti $file";
15 while (<IN>) {
16 chomp;
17 s/\015//g; # kill cr
18
19 tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2
20
21 s/^"//;
22 s/"$//;
23 s/\t"/\t/g;
24 s/"\t/\t/g;
25 s/ */ /g;
26
27 next if (/^#/);
28
29 @arr = split(/\t/,$_);
30
31 if ($type eq "otvoreni") {
32 $sql_insert="insert into otvoreni (ime,prezime,tojzoj,odjel,lokacija) values ('$arr[0]','$arr[1]','$arr[2]','$arr[3]','$arr[4]') ";
33 } elsif ($type eq "lokacije") {
34 $sql_insert="insert into lokacije (naziv) values ('$arr[0]') ";
35 } elsif ($type eq "kontant_osobe") {
36 @foo = ( 'a'..'z','0'..'9','A'..'Z' );
37 $passwd="";
38 for (1..8) { $passwd=$passwd.$foo[int(rand($#foo))] };
39 ($ime,$prezime) = split(/ /,$arr[1],2);
40 $sql_insert="insert into kontakt_osobe (ime,prezime,e_mail,passwd) values ('$ime','$prezime','$arr[0]','$passwd') ";
41 } elsif ($type eq "tipovi_racunala") {
42 $sql_insert="insert into tipovi_racunala (tip) values ('$arr[0]') ";
43 } elsif ($type eq "statusi") {
44 $sql_insert="insert into status_tip (opis) values ('$arr[0]') ";
45 } elsif ($type eq "kontakt_osobe_ic") {
46 @foo = ( 'a'..'k', 'm'..'z', '2'..'9', 'A'..'H', 'J'..'N',
47 'P'..'Z', '!', '#', '$', '%', '&', '(', ')', '=',
48 '-', '/', '?' );
49 srand;
50 $passwd="";
51 for (1..8) {
52 $ch=$foo[int(rand($#foo))];
53 $passwd=$passwd.$ch;
54 }
55 $sql_insert="insert into kontakt_osobe (ime,prezime,e_mail,passwd,prava) values ('$arr[0]','$arr[1]','$arr[2]','$passwd',64) ";
56 } elsif ($type eq "sap2informatika") {
57 next if ($arr[2] eq "");
58 $sql_insert="insert into sap2orgjed values ('$arr[0]','$arr[1]','$arr[2]')";
59 } else {
60 die "Nepoznat tip datoteke $type !!";
61 }
62
63 print "--$sql_insert\n";
64 $dbh->do("$sql_insert") || die $dbh->errstr();
65
66 }
67
68 print "\n";

  ViewVC Help
Powered by ViewVC 1.1.26