in reply to Re: Updating or Inserting a database from a txt file
in thread Updating or Inserting a database from a txt file
Also can you please tell me what went wrong with my aproach even though i dont use a primary key? Here is the code!$dbh->do( "CREATE TABLE games (gamename text, gamedesc text, gamecount +er int, primary key(gamename))" );
my (@row, $gamename, $gamedesc, $gamecount); my $select = $dbh->prepare( "SELECT * FROM games WHERE gamename=?" ); my $insert = $dbh->prepare( "INSERT INTO games (gamename, gamedesc, ga +mecounter) VALUES (?, ?, ?)" ); my $update = $dbh->prepare( "UPDATE games SET gamedesc=?, gamecount=?+ +1 where gamename=?" ); open (FILE, "<../data/games/descriptions.txt") or die $!; while (<FILE>) { chomp; ($gamename, $gamedesc) = split /\t/; $select->execute( $gamename ); if ($select->rows) { $update->execute( $gamedesc, $gamecount, $gamename ); } else { $insert->execute( $gamename, $gamedesc, 0 ); } } close (FILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Updating or Inserting a database from a txt file
by Adrade (Pilgrim) on May 12, 2005 at 09:11 UTC | |
by Nik (Initiate) on May 12, 2005 at 10:22 UTC | |
|
Re^3: Updating or Inserting a database from a txt file
by Nik (Initiate) on May 11, 2005 at 12:54 UTC | |
by bart (Canon) on May 12, 2005 at 07:36 UTC | |
by Nik (Initiate) on May 12, 2005 at 07:37 UTC |