Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You need to import the SQL type constants from DBI and specify that SQL_LONGVARCHAR as the type of the data to be added to the memo field.

The code below extracts the news from the Google RSS feed and inserts the stories into an Access database via DBI and ODBC. The database connection is made on the fly without needing configuration. The description item is a memo field in the Access database.

#! /usr/bin/perl # use strict; use warnings; use LWP; use XML::RSSLite; use DBI ':sql_types'; use Date::Parse; use Date::Format; use HTML::Entities; use Data::Dumper; my $rssUrl = 'http://news.google.com/news?M=&M=&M=&M=&%20Toubro=&outpu +t=rss'; unless (getRss()) { $ENV{HTTP_PROXY}='myproxy:80'; getRss(); } sub getRss { my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; $ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.11) + Gecko/20050728'); my $response = $ua->get($rssUrl); my $rssContent; if ($response->is_success) { $rssContent = $response->content; # or whatever } my $mdb = "C:\\perl\\rssnewsdb\\rss.mdb"; my $DSN = "driver=Microsoft Access Driver (*.mdb);dbq=$mdb"; my $dbh = DBI->connect("dbi:ODBC:$DSN", ",") or die "$DBI::errstr\n"; if ($rssContent) { $rssContent =~ s/ isPermaLink="false"//g; my %rssHash; parseRSS(\%rssHash, \$rssContent); foreach my $item (@{$rssHash{item}}) { my $sql = "INSERT INTO tFeed ( [guid], title, link, category , + publicationdate, description) VALUES(?,?,?,?,?,?)"; my $sth = $dbh->prepare($sql); my $guid = $item->{'guid'}; my $title = $item->{'title'}; my $link = $item->{'link'}; my $description = $item->{'description'}; my $category = $item->{'category'}; my $publicationdate = time2str ('%c', str2time($item->{'pubDat +e'})); $description =~ s/<.*?>/ /g; $description =~ s/&/&/g; decode_entities $description; $description =~ s/\s+/ /g; $description =~ s/^\s+//g; print "$description\n\n"; $sth->bind_param(1, $guid); $sth->bind_param(2, $title); $sth->bind_param(3, $link); $sth->bind_param(4, $category); $sth->bind_param(5, $publicationdate); $sth->bind_param(6, $description, SQL_LONGVARCHAR); eval { $sth->execute() or die $dbh->errstr; }; if ($@) { print "Failed to add - $title\n"; } } return 1; } else { print "error!\n"; } return undef; }

In reply to Re: Accessing MS-Access memofield via DBI by inman
in thread Accessing MS-Access memofield via DBI by reneeb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-03-29 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found