Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^8: Inserting, update and deleteting a database under conditions

by Nik
on Jan 15, 2008 at 16:29 UTC ( #662499=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Inserting, update and deleteting a database under conditions
in thread Inserting, update and deleteting a database under conditions

Like this:

#===================================================================== +========== my $db = ( $ENV{'SERVER_NAME'} !~ /varsa/ ) ? DBI->connect('DBI:mysql:orthodox;localhost', 'root', '******' +, {RaiseError=>1}) : DBI->connect('DBI:mysql:skieros_orthodox;www.freegreece.net', + 'skieros_root', '******', {RaiseError=>1}); #===================================================================== +========== my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt"; my @filenames = map {/([^\/]+)\.txt$/} @files; my @dbfiles = $db->do( 'SELECT title, body FROM articles' ); foreach my $filename (@filenames) { unless( grep /^\Q$filename\E$/, @dbfiles ) { open FILE, "<$filename" or die "Cannot open $filename: $!"; my $data = <FILE>; close FILE; unless( grep /^\Q$data\E$/, @dbfiles ) { $db->do('INSERT INTO test (title, body) VALUES (?, ?)', undef +, $filename, $data) } } }
The content of @dbfiles isnt what i think it is though. What i wanted to return is all table's articles contents.


Comment on Re^8: Inserting, update and deleteting a database under conditions
Download Code
Replies are listed 'Best First'.
Re^9: Inserting, update and deleteting a database under conditions
by Anonymous Monk on Jan 15, 2008 at 22:30 UTC
    1. @dbfiles doesn't contain what I thought
    2. @dbfiles is filled using $dbh->do
    3. I wonder what the return value of $dbh->do is?
    4. I wonder if the DBI documentation mentions the return value of the do method?
    OK, that should tell you why your code returns what it does. To get your code to do what you want, I'd recommend consulting DBI recipes.
      Thanks, i guess if at some point i don't start reading i'll question myself and other for eternity.... :-)

      Thanks for the links, lets hope they are written in an easy way so i will be able to understand them.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://662499]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2015-07-08 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls