Merged the eq_interview table with the eq_ppi table.
[eq/.git] / bin / merge_eq_ppi_eq_interview_tables
1 #!/usr/bin/perl
2
3 use DBI;
4 use Getopt::Std;
5
6 ###################################################
7 # GLOBALS
8 $dbname = "phpgroupware";
9 $dbhost = "192.168.0.2"; # This can be an IP address or name
10 $dbport = 3306;
11 $dbuser = "phpgroupware"; # This may require an additional '\@localhost'
12 $dbpass = "phpgroupware"; 
13 ###################################################
14
15 ###################################################
16 # Connect to the database
17 $dbh=DBI->connect("dbi:mysql:dbname=$dbname:host=$dbhost:port=$dbport",$dbuser,$dbpass,{
18     AutoCommit=>0,
19     PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
20 ###################################################
21
22 # Add a new 'aaronic' column to the eq_ppi table
23 $sth = $dbh->prepare("ALTER TABLE `eq_ppi` ADD `aaronic` INT( 16 ) NOT NULL DEFAULT '0' AFTER `elder`");
24 $sth->execute or die "-E- DB error: $DBI::errstr\n";
25
26 # Parse the data out of the eq_interview table and add them to the eq_ppi table
27 $sth = $dbh->prepare("select * from eq_interview");
28 $sth->execute or die "-E- DB error: $DBI::errstr\n";
29 while($row = $sth->fetchrow_hashref) {
30     $interviewer = $row->{interviewer};
31     $elder = $row->{elder};
32     $aaronic = $row->{aaronic};
33     $date = $row->{date};
34     $notes = $row->{notes};
35     $notes =~ s/\'/\\\'/g;
36     $eqpresppi = 0;
37     #print "$interviewer $elder $aaronic $date $eqpresppi $notes\n";
38     $sth2 = $dbh->prepare("insert into eq_ppi values (NULL,'$interviewer','$elder','$aaronic','$date','$notes','$eqpresppi')");
39     $sth2->execute or die "-E- DB error: $DBI::errstr\n";
40 }
41
42 print "\n-> Succesfully imported all eq_interview table entries into eq_ppi table...\n";
43 print "-> You may drop the eq_interview table once you know all your data was transferred to the eq_ppi table correctly..\n";
44
45 ###################################################
46 # Disconnect from the database
47 $dbh->disconnect();
48 ###################################################
49
50