#!/usr/bin/perl #* #* GnuDialer - Complete, free predictive dialer #* #* Complete, free predictive dialer for contact centers. #* #* Copyright (C) 2006, GnuDialer Project #* #* Richard Lyman #* #* This program is free software, distributed under the terms of #* the GNU General Public License. #* use DBI; $drh = DBI->install_driver('mysql') or die("Unable to install driver"); $dbh = DBI->connect("DBI:mysql:dialer",'dialer','1234') or die("Unable to connect"); &create_dnc_table; &what_dbs; $dbh->disconnect; ##################################################################################### sub create_dnc_table { $mystring = "CREATE TABLE IF NOT EXISTS `DNC` ( `id` int(11) unsigned NOT NULL auto_increment, `phone` varchar(64) NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `phone` (`phone`) ) TYPE=MyISAM COMMENT='DoNotCalls'" ; $sth = $dbh->prepare("$mystring"); $sth->execute or die("Unable to excute query"); } #################################################################################################### sub what_dbs { my $ret = 0; my $sth = $dbh->prepare("SHOW TABLES"); $sth->execute or print "query: what_dbs failed"; while(@table = $sth->fetchrow_array) { if ($table[0] ne 'cdr' && $table[0] ne 'CDR' &&$table[0] ne 'dnc' && $table[0] ne 'DNC') { drop_what_columns($table[0]); #this cleans up the old columns update_tables($table[0]); #this adds the new columns } } $sth->finish; return $ret; } #################################################################################################### sub update_tables { local($thetable) = @_; $mystring = "ALTER IGNORE TABLE " . $thetable . " ADD cb_type ENUM('0','1') default '0'"; $mystring = $mystring . ", ADD cb_attempts int(8)"; $mystring = $mystring . ", ADD cb_agent VARCHAR(6) default '000'"; $mystring = $mystring . ", ADD INDEX ( cb_attempts )"; $sth = $dbh->prepare("$mystring"); $sth->execute or die("Unable to excute query"); $sth->finish; } ################################################################################################## sub drop_what_columns { local($thetable) = @_; my $sth = $dbh->prepare("SHOW COLUMNS FROM " . $thetable ); $sth->execute or print "query: what_columns failed"; $mystring = "ALTER IGNORE TABLE " . $thetable ; while(@column = $sth->fetchrow_array) { if ($column[0] eq 'cb_type') { $mystring = $mystring . ", DROP cb_type"; } if ($column[0] eq 'cb_agent') { $mystring = $mystring . ", DROP cb_agent"; } if ($column[0] eq 'cb_attempts') { $mystring = $mystring . ", DROP cb_attempts"; } } $sth = $dbh->prepare("$mystring"); $sth->execute or die("Unable to excute query"); } #*************************