Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

jrsimmon's scratchpad

by jrsimmon (Hermit)
on Nov 28, 2007 at 23:49 UTC ( #653716=scratchpad: print w/replies, xml ) Need Help??

This isn't verbatim what I'm doing, since posting a webapp in here doesn't really make sense. But I'll try to be true to the problem I'm trying to solve. Please forgive me any typos.

What I would like to do is use CGI::Application::Plugin::DBH to provide access to my database in conjunction with CGI::Ajax. When the page loads normally, the CGI::Application setup sub is called and Plugin::DBH can do its thing. However, when 'BUILD_CHART' is called from the the javascript function 'GET_CHART', it doesn't go through the setup routine. Can I still access the database config set up Plugin::DBH when executing a the 'BUILD_CHART' sub? How?

package MyWebApp; use base 'CGI::Application'; use strict; use CGI; use CGI::Ajax; use CGI::Carp qw(fatalsToBrowser); use CGI::Application::Plugin::DBH qw(dbh_config dbh); use DBI qw(:sql_types); use DBIx::Chart; sub setup{ my $self = shift; $self->start_mode('mode1'); $self->mode_param('rm'); $self->run_modes( 'mode1' => 'runMode1', 'mode2' => 'runMode2' ); $self->dbh_config('dbh1', ['DBI:DB2:DS1', 'usr', 'pwd', {RaiseError +=> 0, PrintError => 0}]); } sub runMode1 { my $q = new CGI; my $pjx = new CGI::Ajax('GET_CHART' => \&BUILD_CHART, 'skip_header' +=> 1); open(SRC, "pageSrc.htm") or die $!; my $src = <SRC>; close(SRC); my $output = $q->start_html; $output .= $src; $output .= $q->end_html; return $pjx->build_html($q, $output); } sub BUILD_CHART { my ($chartSelection, $screenWidth) = @_; my $chartWidth = $screenWidth / 2; #this is where I want to take advantage of CGI::Application::Plugin: +:DBH -- so that I don't have to build this connection every time an a +jax call is made to this subroutine my $dbh = DBIx::Chart->connect('DBI:DB2:DS1', 'usr', 'pwd', {RaiseEr +ror => 0, PrintError => 0}) or die $DBI::errstr; my $qryStatement = "SELECT SOMETHING FROM SOMEWHERE"; my $chartStatement = "RETURNING BARCHART(*), IMAGEMAP WHERE ..."; my $sth = $dbh->prepare("$qryStatement $chartStatement"); unless(eval{$sth->execute();}){ die "Failed to execute!"; } my $tempChartRef = $sth->fetchrow_arrayref or die "Failed to fetch!" +; $sth->finish; my $imageData = $$tempChartRef[0]; my $imageMap = $$tempChartRef[1]; my $imageName = &WRITE_IMAGE_TO_DISK($imageData, 'PNG', 'barchart'); my $html = "<IMG SRC=\"/$imageName\" USEMAP=\"#barMap\">"; $html .= $imageMap; return $html; }
Log In?

What's my password?
Create A New User
[james28909]: another thing, i used to be atheist. life experiences, personal evidence. and my own perception is the reason why i believe the things i do.
[erix]: and now you are agnostic?
[james28909]: arunbear, your picking bits of history to fit your own narrative. right now, humans are smarter than in any of those times.
[james28909]: in order for there to be a mutation, there has to be a universe with laws setup that even allow a mutation.
[james28909]: everything past the first two things you piked from my posts are irrelevant to me and my beliefs. they are side effects.
[james28909]: two or three. if it has to do with how humans are handling said situations, then that is after they were able to evolve into those problems. agnostic means only believe with evidence. i took that from a tyson video
[james28909]: and it seems that racism suggest that there is indeed a better race, but that is for evolution to decide

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (17)
As of 2017-12-15 14:53 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (433 votes). Check out past polls.