R: about DBI

"Luca Notari" <[email protected]> Tue, 26 Feb 2008 15:08:51 +0100
Newsgroups gmane.comp.apache.mod-survey.general
Message-ID <002101c87881$1d384380$7101a8c0@asus01>
I've tried to do $compartment->deny_only(qw(:dangerous));

I still have problems in using DBI in perl snippet; as example, I put
here a piece of code that I've used from shell environment with success,
and inside mod_survey perl snippet without success:

THIS WORKS:=20
#!/usr/bin/perl
use DBI;
use DBD::mysql;
my $dbh =3D DBI->connect('DBI:mysql:test','root','passwd')
  or die "Couldn't connect to database: " . DBI->errstr;
$query=3D"SELECT * from test.test";
$query_handle =3D $dbh->prepare($query);
$query_handle->execute();
$query_handle->bind_columns(\$id, \$nome, \$descriz,\$user,\$email);

while($query_handle->fetch()) {
   print "$nome <br />";
}

AND THIS DOESN'T WORK:
{\
use DBD::mysql;
use DBI;

$dsn=3D"DBI:mysql:test:localhost:3306";
$dbh =3D DBI->connect("DBI:mysql:test:localhost:3306","root","pwd");
$query=3D"SELECT * from test.test";
$query_handle =3D $dbh->prepare($query);
$query_handle->execute();
$query_handle->bind_columns(\$id, \$nome, \$descriz,\$user,\$email);

while($query_handle->fetch()) {
   print "$nome <br />";
}

\}

It seems that this latter code make use of CPU very higher, and this not
happens launching from shell.=20
The limit of the IMPORT tag is that the retrieved variable is taken into
the list of submitted variables (I don't want this!) and, above all,
that is not possible to put 2 or more import tags into the same page.=20
To do these SQL statements:
1. Select count(*) from tableA where column1=3D'something';
2. Select count(*) from tableA where column2=3D'something';
3. Select count(*) from tableA where column3=3D'something';
4. Select count(*) from tableA where column4=3D'something';
5. Select count(*) from tableA where column5=3D'something';
If I'm right, I need at least 5 pages with IMPORT tag. What if I only
have 4 pages or less?

Luca Notari
-----Messaggio originale-----
Da: [email protected]
[mailto:[email protected]] Per conto di Joel
Palmius
Inviato: venerd=EC 15 febbraio 2008 14.56
A: [email protected]
Cc: survey discussion list
Oggetto: Re: survey-discussion-list: about DBI


If you want to completely disable security checking, I'd suggest you=20
change the permit line to:

   $compartment->deny_only(qw(:dangerous));

Ie, everything except in principle only dump() and chroot() is allowed.=20
With this, for example the following is possible:

<SURVEY TITLE=3D"test">

   <CUSTOM ESCAPED=3D"no">
     <pre>{&
      open(PIPE,"/bin/ls -l /etc |");
      $string =3D join('',<PIPE>);
      close(FIL);
      print $string;
   &}</pre>
   </CUSTOM>

   <TEXT NAME=3D"test" CAPTION=3D"test" />

</SURVEY>

To avoid problems with clashes with how mod_survey uses use() and
replaces=20
things inside the code in the Safe department, I'd suggest making an=20
external script which prints a value:

   <ROUTE CONTINUE=3D"{&
     $someguy =3D $ses->getValue("SUBMITTED_name");
     open(PIPE,"/usr/bin/perl /home/me/myscript.pl $someguy |");
     $allowed =3D <PIPE>;
     close(PIPE);
     chomp($allowed);

     if($allowed eq "yes")
     {
       print "continuesurvey.survey";
     }
     else
     {
       print "quotaerror.survey";
     }
   &}" />

The external script should have no problem with running DBI related
stuff.

   // Joel



  On Fri, 15 Feb 2008, Luca Notari wrote:

> Using IMPORT tag I can access a database via VARIABLE or ARRAY, and=20
> this variable is included in the list of variables of the survey.
>
>
> But what if I don't want to include the variable?
>
> to do this, I've tried to use DBI in perl snippet but In all cases,=20
> doesn't work for me(continuous document error or display error; I've=20
> opened the compartment->permit $compartment->permit(qw(:browse=20
> :filesys_read :sys_db :filesys_open :filesys_write :subprocess=20
> :base_core :default :base_io :others require
> caller))
> both in Display.pm and Document.pm
>
> I've also tried to use open function: open FILE,"myfile.txt", but,=20
> again nothing works:
>
>
> Document error
>
> Security exception: Undefined subroutine &Carp::longmess_heavy called=20
> at /usr/lib/perl5/5.8.3/Carp.pm line 166, line 30.
>
> Platform: linux-suse
> Modsurvey version 3.2.4
> Perl 5.8.3
> mod_perl 1.99
>
>
>
> The reason for which I have to fetch data from external is: check=20
> quotas. If I'm a respondent out of quotas, I have to route to a page=20
> named i.e. quotafull.survey. To do this, I 1) have to query my DBMS or

> 2) read a text data or csv data from external
>
> Is there any possibility to fetch data from external source (text=20
> files,
> databases) and put in a .survey script page with Perl snippets?
>
>
> (I can easy do this with php script, and try to call it via XMLHttp=20
> using javascript; but, according my knowledge, i have to put variables

> fetched somewhere in the page, for example using an 'hidden' field;=20
> but for variables to be available for perl, i think i have to submit=20
> them ; this is a problem as I need variables available in the same=20
> page)
>
> thanks,
>
> Luca Notari
>
>
Skickat av Joel Palmius <[email protected]>
till survey-discussion


Skickat av "Luca Notari" <[email protected]>
till survey-discussion