Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Combining Ffile:fetch with MySQL

by Marshall (Canon)
on Jul 18, 2022 at 18:28 UTC ( [id://11145579]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Combining Ffile:fetch with MySQL
in thread Combining Ffile:fetch with MySQL

Ok, now I understand better. You are using an existing DB, not making one? You need to use the Perl DBI - Data Base Interface. There are links to the FAQ's and some tutorials. You can see some Monk links here: https://www.perlmonks.org/?node=Tutorials#Database-Programming.

A wild guess and some untested example code would be:
Instead of printing the link, you would use your code to download that doc, then do whatever you are going to do with it.

Update: I see that you are using MySQL instead of SQLite. Brain cramp on my part. But code is essentially the same - just a difference in how to get the DB connection. The dbi would be: dbi::MySQL, then you need an account and password. For SQLite, these are null strings. See the doc's referenced above for a connection example with username/password.

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use DBI qw(:sql_types); my $dbfile = "./YourDbName.sqlite"; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",{RaiseError = +> 1}) or die "Couldn't connect to database: " . DBI->errstr; my $get_links_4date_sql = "SELECT Identifer, LINK FROM YourTableName WHERE Publish date IS ?"); my $get_links_4date = $dbh->prepare ($get_links_4date_sql); my $date = "20220701"; $get_links_4date->execute($date); my $array_ref = $get_links_4date->fetchall_arrayref; foreach my $row_ref (@$array_ref) { my ($id,$link) = @$row_ref; print "$id \t $link\n"; }
I can't anticipate exactly what kind of SQL you need. Above just gets docs for a particular date. Although sounds like what you need is: for each unique id, download latest version of the document. The SQL for that is of course more involved but doable.

Hope this gets you further along your way.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found