Loading ...
Sorry, an error occurred while loading the content.
 

issues with MyBookmarks example

Expand Messages
  • dpchrist@sonic.net
    asp@perl.apache.org I am working on learning Apache::ASP and came across some issues with the MyBookmarks example as shown on
    Message 1 of 2 , Feb 12, 2004
      asp@...

      I am working on learning Apache::ASP and came across some issues with
      the "MyBookmarks" example as shown on
      http://www.apache-asp.org/articles/perlmonth2_build.html:

      1. I received the following warning in my Apache error log on every
      hit:

      [Thu Feb 12 00:25:22 2004] [error] [asp] [12691] [debug] $Response->Expi
      res() deprecated. Please access member directly with $Response->{Expire
      s} notation

      The solution was to modify global.asa as follows:

      <CVSENV>dpchrist@d3020g:~/public_html/apache.asp$ cvs -q diff -r 1.1 glo
      bal.asa
      Index: global.asa
      ===================================================================
      RCS file: /cvs/dpchrist/apache.asp/global.asa,v
      retrieving revision 1.1
      retrieving revision 1.2
      diff -r1.1 -r1.2
      42c42
      < $Response->Expires(0);
      ---
      > $Response->{Expires} = 0;

      2. My table of links was showing up empty on the bookmarks.asp page.

      The problem was that the column names in the @bookmarks array of
      hashrefs were uppercase, but the table generation code was using
      lower case keys.

      Here is the CSV file:

      <CVSENV>root@d3020g:~# cat /tmp/asp_apps_bookmarks/bookmarks
      BOOKMARK_ID,USERNAME,TITLE,URL
      1,dpchristholgerdanskecom,"Holger Danske home page",www.holgerdanske.com
      2,dpchristholgerdanskecom,Yahoo,www.yahoo.com
      3,dpchristholgerdanskecom,Google,www.google.com

      Note that the column names are upper case, even though the table
      creation query in global.asa specifies lower case. I assume this is
      a DBI and/or DBD::CSV issue.

      My work-around was to modify bookmarks.asp as follows:

      <CVSENV>dpchrist@d3020g:~/public_html/apache.asp$ cvs -q diff -r 1.1 boo
      kmarks.asp
      Index: bookmarks.asp
      ===================================================================
      RCS file: /cvs/dpchrist/apache.asp/bookmarks.asp,v
      retrieving revision 1.1
      diff -r1.1 bookmarks.asp
      130,132c130,132
      < my $text = $data->{bookmark_id} ?
      < "<a href=$data->{'url'}
      < >$data->{'title'}</a>"
      ---
      > my $text = $data->{BOOKMARK_ID} ?
      > "<a href=$data->{'URL'}
      > >$data->{'TITLE'}</a>"
      136c136
      < <% if($data->{bookmark_id}) { %>
      ---
      > <% if($data->{BOOKMARK_ID}) { %>
      139c139
      < "$Basename?delete=$data->{bookmark_id}"
      ---
      > "$Basename?delete=$data->{BOOKMARK_ID}"

      3. I don't know how to cleanly get the version numbers of installed
      Perl modules:

      <CVSENV>root@d3020g:~# perl -e "use warnings; use DBD::CSV; print ${DBD:
      :CSV::VERSION}"
      Use of uninitialized value in print at -e line 1.

      Here is my work-around:

      <CVSENV>root@d3020g:~# grep '^$VERSION ='
      /usr/local/share/perl/5.6.1/Apache/ASP.pm
      $VERSION = 2.57;

      <CVSENV>root@d3020g:~# grep 'VERSION =' /usr/lib/perl5/DBI.pm
      $DBI::VERSION = 1.21; # ==> ALSO update the version in the pod text belo
      w!

      <CVSENV>root@d3020g:~# grep 'VERSION =' /usr/local/share/perl/5.6.1/DBD/
      CSV.pm
      $VERSION = '0.2002';


      Clarifications would be appreciated.


      TIA,

      David


      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • Josh Chamas
      ... That s right! The My Bookmarks application probably predates that API change. Thanks for pointing this out, I ll updated this in a future release of
      Message 2 of 2 , Feb 13, 2004
        dpchrist@... wrote:
        > asp@...
        >
        > I am working on learning Apache::ASP and came across some issues with
        > the "MyBookmarks" example as shown on
        > http://www.apache-asp.org/articles/perlmonth2_build.html:
        >
        > 1. I received the following warning in my Apache error log on every
        > hit:
        >
        > [Thu Feb 12 00:25:22 2004] [error] [asp] [12691] [debug] $Response->Expi
        > res() deprecated. Please access member directly with $Response->{Expire
        > s} notation
        >

        That's right! The My Bookmarks application probably predates that API change.
        Thanks for pointing this out, I'll updated this in a future release of Apache::ASP,
        as the My Bookmarks sample app is part of the Apache::ASP distribution
        at ./site/apps/bookmarks

        > 42c42
        > < $Response->Expires(0);
        > ---
        >
        >> $Response->{Expires} = 0;

        Yep, this was the fix.

        >
        >
        > 2. My table of links was showing up empty on the bookmarks.asp page.
        >
        > The problem was that the column names in the @bookmarks array of
        > hashrefs were uppercase, but the table generation code was using
        > lower case keys.
        >
        > Here is the CSV file:
        >
        > <CVSENV>root@d3020g:~# cat /tmp/asp_apps_bookmarks/bookmarks
        > BOOKMARK_ID,USERNAME,TITLE,URL

        I am not sure why your CSV file gets created with uppercase columns. I just tried
        the application and mine created the columns with lowercase names in the CSV
        file. I had the same version of DBD::CSV, but a more recent DBI module.
        A complete work around to this problem is to not rely on the returned
        column names at all ... here is a diff that makes this happen:

        --- bookmarks/bookmarks.asp 12 Sep 2002 20:05:55 -0000 1.1.1.1
        +++ bookmarks/bookmarks.asp 14 Feb 2004 02:00:52 -0000
        @@ -62,14 +62,20 @@

        # get all the bookmarks
        ERROR:
        -my $sth = $Db->prepare_cached(
        - "select * from bookmarks where username=? ".
        - "order by bookmark_id"
        +my $rows = $Db->selectall_arrayref(
        + "select bookmark_id, username, title, url from bookmarks where username=? ".
        + "order by bookmark_id",
        + undef,
        + $Session->{'user'}
        );
        -$sth->execute($Session->{'user'});
        my @bookmarks;
        -while(my $bookmark = $sth->fetchrow_hashref()) {
        - push(@bookmarks, $bookmark);
        +for my $row ( @$rows ) {
        + push(@bookmarks, {
        + bookmark_id => $row->[0],
        + username => $row->[1],
        + title => $row->[2],
        + url => $row->[3],
        + });
        }
        %>

        Actually, not relying on the column names case is probably a good idea long
        term. It seems that each database has a different way of returning column
        names, so for portability its best to use columns by positional reference only.
        Oracle returns uppercase, MySQL returns as defined (mixed lower/upper), &
        I think PostgreSQL return all lowercase ( could be wrong on this. ).

        I'll update the app bundled with Apache::ASP, but will leave the article as is.
        It was published in 1999 after all, and pretty much works still anyway.

        Regards,

        Josh
        ________________________________________________________________________
        Josh Chamas, Founder | NodeWorks - http://www.nodeworks.com
        Chamas Enterprises Inc. | NodeWorks Directory - http://dir.nodeworks.com
        http://www.chamas.com | Apache::ASP - http://www.apache-asp.org



        ---------------------------------------------------------------------
        To unsubscribe, e-mail: asp-unsubscribe@...
        For additional commands, e-mail: asp-help@...
      Your message has been successfully submitted and would be delivered to recipients shortly.