updating files within the database based on dates compared
From: A L (perlcgi828_at_yahoo.com)
Date: 10/24/03
- Next message: Tim Bunce: "Re: Perl 5.8/DBI 1.38 on AIX 5.1 -> make test fails with symbol resolution errors (IO.so)"
- Previous message: Kbass: "Re: DBI Postgres"
- Next in thread: Hardy Merrill: "Re: updating files within the database based on dates compared"
- Reply: Hardy Merrill: "Re: updating files within the database based on dates compared"
- Reply: James D. White: "Re: updating files within the database based on dates compared"
- Reply: Jeff Zucker: "Re: updating files within the database based on dates compared"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 24 Oct 2003 08:19:52 -0700 (PDT) To: dbi-users@perl.org
Dear dbi-users@perl.org,
Okay, so, by being ignored, it dawned on me that my question may have been considered to be stupid. But, since my goal is to program better, more time was spent, even though spending a whole week checking the code and looking at whatever books could be found to figure out what was wrong with it (thinking it should have a simple solution) didn't produce any result .
Although my code does function when WHERE in the prepare statement is specified within a database, it isn't exactly what was intended. This code should automatically update all the rows when there are matching idnum with same file name without having to type specific name for WHERE (for example, not WHERE='Sally" but WHERE=?). With another program example, which uses the same prepare and excute statement format as this code, the code works, but not in this program. Both program looks the same to me, but this one isn't working. And, I can't figure out why.
It really would help me a lot if you would spend a little bit of time to show me why it's not working, even if you find this question to be stupid. To me it is not, it is important to me to understand why I don't get this. Any feedback would be much appreciated.
Angela
#!/usr/bin/perl
use DBI;
my $dbh = DBI->connect("dbi:mysql:", "usrname", "password") || die $DBI::errstr;
my $db_database = DBI->connect("dbi:mysql:database", "usrname", "password") || die $DBI::errstr;
my $insert_database=$db_database->prepare("INSERT INTO table1 values (?,?,?,?,?,?,?)");
my $dbh1 = DBI->connect("dbi:mysql:database", "usrname", "password") || die $DBI::errstr;
my $lookup_access=$dbh1->prepare("select retrieval_date FROM table1 WHERE idnum= ?");
$Top="/home/Top/";
chdir $Top;
my $count=0;
while (my $subdir=<*>){
chdir $subdir;
while (my $file=<*.txt>){
$file=~/^(\w*)./;
my $access=$1;
$lookup_access->execute($access);
my @result=$lookup_access->fetchrow();
my @file=stat("$access.txt");
my $mtime=$file[9];
my @testime=gmtime($mtime) ;
my $year=$testime[5]+1900;
my $mon=$testime[4]+1;
my $mday=$testime[3];
my $mon=sprintf("%02d",$mon);
my $mday=sprintf("%02d",$mday);
my $date= "$year-$mon-$mday";
if (@result){
my $result=$date;
if ($result){
my $update_table1=$dbh1->prepare(
"UPDATE table1
SET retrieval_date='$result'
WHERE idnum='Sally");#need to work for all the updated files, not just one file
$update_table1->execute();
}
}
}
chdir "..";
}
$dbh->disconnect;
---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
- Next message: Tim Bunce: "Re: Perl 5.8/DBI 1.38 on AIX 5.1 -> make test fails with symbol resolution errors (IO.so)"
- Previous message: Kbass: "Re: DBI Postgres"
- Next in thread: Hardy Merrill: "Re: updating files within the database based on dates compared"
- Reply: Hardy Merrill: "Re: updating files within the database based on dates compared"
- Reply: James D. White: "Re: updating files within the database based on dates compared"
- Reply: Jeff Zucker: "Re: updating files within the database based on dates compared"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|