Gossamer Forum
Home : General : Perl Programming :

Oracle Placeholder Problem in my Perl Script

Quote Reply
Oracle Placeholder Problem in my Perl Script
 
Hi Pals..

I am facing problem while running a query (with oracle placeholder) in my Perl script.
Following is the code :


#!/usr/bin/perl -w
use warnings;
use strict;
use CGI;
use DBI;
use CGI::Carp qw(fatalsToBrowser);

my $query=new CGI;
my $cgiobj = CGI -> new();
#my $xlsdata;
my $querydata;
my $querycreated;

#print "Content-type:text/html\n\n";
my $querytitle = $cgiobj -> param('querytitle');

$ENV{ORACLE_HOME}="/home/oracle/product/10.2.0/db_1";
our $conn = DBI->connect("dbi:Oracle:host=10.0.0.1;sid=dev;","queryeditor","editor");
die($DBI::errstr) unless $conn;

print $querytitle;
print "Content-type: application/HTML\n";
print "Content-disposition: inline; filename=\"Report.html\"\n";
print "Pragma: no-cache\n";
print "Expires: 0\n\n";

my $query_detail1 = "select querydata from querydetail where querytitle='$querytitle'";
my $query_records1 = $conn->prepare($query_detail1) or die("Error on preparing the sql statement1 \n");
$query_records1->execute() or die("Error on getting the data from QUERYDETAIL \n");
while(my @query_resultset1= $query_records1->fetchrow_array)
{
my $mainquery= $query_resultset1[0];
#print $mainquery;
my $query_records2 = $conn->prepare($mainquery) or die("Error on preparing the sql statement2 \n");
$query_records2->execute() or die("Error on getting the data from QUERYDETAIL \n");

print "<h1><center>Report</center></h1><br><br>";

my $dat = $query_records2 -> fetchall_arrayref;
foreach my $i ( 0..$#{ $dat } ) {
foreach my $j ( 0..$#{ $dat->[$i] } ) {
print $dat->[$i][$j]."<br>";
}
}
}

I am making the final result in HTML report format. For example I am using the "select * from EMP where EMPNO = &eno " query here. So, $mainquery will carry this query and will process the rest.

What could be the problem ? If you need more detail..then i can supply iy to you..

thanks in advance..
Warm Regards,
Saravanan


Quote Reply
Re: [slg_saravanan] Oracle Placeholder Problem in my Perl Script In reply to
Hi Saravanan,

The problem should be the placeholder of Oracle that DBI does not understand. You may try to replace that with the question mark(?), the passing the parameter to the execute method. Something like below



Code:
$mainquery =~ s/&\w+/\?/g;
my $query_records2 = $conn->prepare($mainquery) or die("Error on preparing the sql statement2 \n");
$query_records2->execute("some thing to replace here") or die("Error on getting the data from QUERYDETAIL \n");


Hope that helps

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Oracle Placeholder Problem in my Perl Script In reply to
Hi Dat..

Thanks a lot..will try that.

Warm Regards,
Saravanan