CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
problem with select quary when I convert program to .exe file

 



mohsenalizadeh
Novice

Mar 17, 2010, 2:05 AM

Post #1 of 14 (8766 views)
problem with select quary when I convert program to .exe file Can't Post

hello
I writr this program to show answer of quary to the users and , then
users can update information.
when Run program with IDE ( for example : Komodo ), it works
correctly .but when I convert program to .exe with cava packager ,
its not working. ( select quary not working).

when I change the $dbh->fetchrow_array(); with WHILE loop :

While(our @rec = $dbh->fetchrow_array()){
our $name = $rec[1];
our $adminname = $rec[2];
our $myphone1 = $rec[3];
our $myphone2 = $rec[4];
our $myaddress = $rec[5];
our $mypercent = $rec[6];
}


and convert program to .exe , WHILE LOOP convert to Infinite loops .
---------------------------------------------------------------------

#!C:/strawberry/perl/bin/perl.exe

use Tk;
use DBI;

$mw = MainWindow->new(-background=>"gray");
$mw->title("$header");
$mw->maxsize(800,315);
$mw->minsize(800,315);

$cn = DBI->connect("DBI:mysql:telephontaxi","root","root",
{mysql_enable_utf8 => 1});
$dbh = $cn->prepare("select * from telephonetaxiinformation");
$dbh->execute();

our @rec = $dbh->fetchrow_array();
our $name = $rec[1];
our $adminname = $rec[2];
our $myphone1 = $rec[3];
our $myphone2 = $rec[4];
our $myaddress = $rec[5];
our $mypercent = $rec[6];

$dbh->finish;
$cn->disconnect;

$mw->Label(-text=>"$header",-font => "Titr 23",-anchor=>'center',-
width=>34,-background=>"gray")->place(-x => 0,-y=>0);
$fram = $mw->Frame(-relief => 'groove',-borderwidth => 0,-width=>780,-
height=>240)->place(-x => 10,-y=>64);

$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief
=>'groove',-textvariable => \$name)->place(-x =>410,-y=>15);

$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief
=>'groove',-textvariable => \$adminname)->place(-x =>410,-y=>55);

$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief
=>'groove',-width=>4,-textvariable => \$mypercent)->place(-x =>170,-
y=>30);

$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief
=>'groove',-textvariable => \$myphone1)->place(-x =>410,-y=>95);

$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief
=>'groove',-textvariable => \$myphone2)->place(-x =>50,-y=>95);

$fram->Entry(-font => "Tahoma 13 normal",-width=>60,-justify
=>'right',-relief =>'groove',-textvariable => \$myaddress)->place(-x
=>50,-y=>145);

$fram->Button(-text=>"Save",-font => "Tahoma 13 normal",-command =>
[ \&saveinformation ])->place(-x =>370,-y=>190);
$fram->Button(-text=>"Exit",-font => "Tahoma 13 normal",-command =>
[$mw => 'destroy'])->place(-x =>320,-y=>190);

MainLoop;


sub saveinformation{
$cn = DBI->connect("DBI:mysql:telephontaxi","root","root",
{mysql_enable_utf8 => 1});
$dbh = $cn->prepare("update telephonetaxiinformation set
azansname='$name',azansadmin='$adminname',phone1='$myphone1',

phone2='$myphone2',azansaddress='$myaddress',azanspercent='$mypercent'
where azansid='1'");
$dbh->execute();
$cn->disconnect;
$dbh->finish;
$cn1 = DBI->connect("DBI:mysql:telephontaxi","root","root",
{mysql_enable_utf8 => 1});
$dbh1 = $cn1->prepare("select azansid from
telephonetaxiinformation where azansname='$name'");
$dbh1->execute();
my @rec = $dbh1->fetchrow_array();
print $rec[0];
if($rec[0] ne ""){
$message = "save correctly...";

$fram->Label(-text=>"$message",-font => "homa 15")->place(-
x =>600,-y=>190);
$mw->messageBox (
-default => 'Ok',
-title => "$message",
-message => "$message",
-type => 'Ok',
);
}
$dbh1->finish;
$cn1->disconnect;

}


FishMonger
Veteran / Moderator

Mar 17, 2010, 5:35 AM

Post #2 of 14 (8761 views)
Re: [mohsenalizadeh] problem with select quary when I convert program to .exe file [In reply to] Can't Post

Please use the code tags, they will retain the code formatting which makes it much earier fur us to read your code.

Start by adding these 2 pragmas, which should be in every Perl script you write.

Code
use strict; 
use warnings;


Change all 'our' declarations to 'my' declarations. The strict pragma will point out other vars that need to be declared.

Add this to the DBI connect statement.

Code
RaiseError => 1


I am not familiar with the cava packager. Did you receive any errors or warnings when you created the exe?

Have you tried building the exe with PAR::Packer?
http://search.cpan.org/~smueller/PAR-Packer-1.002/lib/PAR/Packer.pm


(This post was edited by FishMonger on Mar 17, 2010, 5:36 AM)


FishMonger
Veteran / Moderator

Mar 17, 2010, 5:42 AM

Post #3 of 14 (8758 views)
Re: [mohsenalizadeh] problem with select quary when I convert program to .exe file [In reply to] Can't Post

One problem you may be having is that the cava packer does not find and include modules that are loaded at runtime. In this case that would be DBD::mysql. Add this and try again.

Code
use DBD::mysql;



mohsenalizadeh
Novice

Mar 22, 2010, 12:17 AM

Post #4 of 14 (8655 views)
Re: [FishMonger] problem with select quary when I convert program to .exe file [In reply to] Can't Post

Hi
I add

use DBD::mysql;

Code
 and

use strict;
use warnings;

Code
 and

RaiseError => 1

Code
 in my code and then convert to .exe file , but my select Quarru not working. 
NOTICE :
when program convert to .exe file , INSERT and UPDATE working correctly , only SELECT quary not working.
thankyou.


mohsenalizadeh
Novice

Mar 22, 2010, 2:37 AM

Post #5 of 14 (8649 views)
Re: [FishMonger] problem with select quary when I convert program to .exe file [In reply to] Can't Post

Hi
I noticed a new point , before convert script to .exe ,if run program withour IDE ( Run with comman line ), My SELECT quary does not work.But UPDATE AND INSERT Commands to work properly.
Why ? Frown
please help me


FishMonger
Veteran / Moderator

Mar 22, 2010, 7:07 AM

Post #6 of 14 (8644 views)
Re: [mohsenalizadeh] problem with select quary when I convert program to .exe file [In reply to] Can't Post

You need to be more specific.

What do you mean by?

Quote
My SELECT quary does not work.

Is the prepare statement failing, or does it simply not return any data?

Have you tried outputting $cn1->errstr in a $mw->messageBox?


mohsenalizadeh
Novice

Mar 22, 2010, 7:36 AM

Post #7 of 14 (8641 views)
Re: [FishMonger] problem with select quary when I convert program to .exe file [In reply to] Can't Post

Hi
when program run in command line , I recived this error :


Code
fetchrow_array failed: fetch() without execute()


but , when run in IDE ,program work correctly.
I try outprint in textbox.
thankyou.


(This post was edited by mohsenalizadeh on Mar 22, 2010, 7:43 AM)


FishMonger
Veteran / Moderator

Mar 22, 2010, 7:46 AM

Post #8 of 14 (8638 views)
Re: [mohsenalizadeh] problem with select quary when I convert program to .exe file [In reply to] Can't Post

Do you have 2 different versions of the script, one designed as a gui and one as a cli script?

Please post the version of your script that generated the error and use the code tags so that the code formatting is retained.


mohsenalizadeh
Novice

Mar 22, 2010, 7:58 AM

Post #9 of 14 (8636 views)
Re: [FishMonger] problem with select quary when I convert program to .exe file [In reply to] Can't Post

Hi
this is my code :

Code
 
#!C:/strawberry/perl/bin/perl.exe



use Tk;
use DBI;
use DBD::mysql;
#use strict;
#use warnings;


my $cn = DBI->connect("DBI:mysql:telephontaxi","root","root",{mysql_enable_utf8 => 1,RaiseError => 1}) or die("Cant Connected to Databses....");
$dbh = $cn->prepare("select * from telephonetaxiinformation");
$dbh->execute();
while(our @rec = $dbh->fetchrow_array()){
our $name = $rec[1];
our $adminname = $rec[2];
our $myphone1 = $rec[3];
our $myphone2 = $rec[4];
our $myaddress = $rec[5];
our $mypercent = $rec[6];
}


$dbh->finish;
$cn->disconnect;

my $mw = MainWindow->new(-background=>"gray");
$mw->title("header");
$mw->maxsize(800,315);
$mw->minsize(800,315);





$mw->Label(-text=>"header",-font => "Titr 23",-anchor=>'center',-width=>34,-background=>"gray")->place(-x => 0,-y=>0);
my $fram = $mw->Frame(-relief => 'groove',-borderwidth => 0,-width=>780,-height=>240)->place(-x => 10,-y=>64);

$fram->Label(-text => "name")->place(-x =>650,-y=>15);
$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$name)->place(-x =>410,-y=>15);



$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$adminname)->place(-x =>410,-y=>55);


$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-width=>4,-textvariable => \$mypercent)->place(-x =>170,-y=>30);



$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$myphone1)->place(-x =>410,-y=>95);


$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$myphone2)->place(-x =>50,-y=>95);


$fram->Entry(-font => "Tahoma 13 normal",-width=>60,-justify =>'right',-relief =>'groove',-textvariable => \$myaddress)->place(-x =>50,-y=>145);




$fram->Button(-text=>"Save",-font => "Tahoma 13 normal",-command => [ \&saveinformation ])->place(-x =>370,-y=>190);
$fram->Button(-text=>"Exit",-font => "Tahoma 13 normal",-command => [$mw => 'destroy'])->place(-x =>320,-y=>190);

MainLoop;




sub saveinformation{
$cn = DBI->connect("DBI:mysql:telephontaxi","root","root",{mysql_enable_utf8 => 1,RaiseError => 1});
$dbh = $cn->prepare("update telephonetaxiinformation set azansname='$name',azansadmin='$adminname',phone1='$myphone1',
phone2='$myphone2',azansaddress='$myaddress',azanspercent='$mypercent'
where azansid='1'");
$dbh->execute();
$cn->disconnect;
$dbh->finish;
my $cn1 = DBI->connect("DBI:mysql:telephontaxi","root","root",{mysql_enable_utf8 => 1,RaiseError => 1});
my $dbh1 = $cn1->prepare("select azansid from telephonetaxiinformation where azansname='$name'");
$dbh1->execute();
my @rec = $dbh1->fetchrow_array();
print $rec[0];
if($rec[0] ne ""){
my $message = "save correctly...";

$fram->Label(-text=>"$message",-font => "homa 15")->place(-x =>600,-y=>190);
$mw->messageBox (
-default => 'Ok',
-title => "$message",
-message => "$message",
-type => 'Ok',
);
}
$dbh1->finish;
$cn1->disconnect;

}

thankyou


FishMonger
Veteran / Moderator

Mar 22, 2010, 8:08 AM

Post #10 of 14 (8635 views)
Re: [mohsenalizadeh] problem with select quary when I convert program to .exe file [In reply to] Can't Post

The first step is to fix these problems.

Quote
C:\test>perl -c mohsenalizadeh.pl
Variable "$name" is not imported at mohsenalizadeh.pl line 41.
Variable "$adminname" is not imported at mohsenalizadeh.pl line 45.
Variable "$mypercent" is not imported at mohsenalizadeh.pl line 48.
Variable "$myphone1" is not imported at mohsenalizadeh.pl line 52.
Variable "$myphone2" is not imported at mohsenalizadeh.pl line 55.
Variable "$myaddress" is not imported at mohsenalizadeh.pl line 58.
Variable "$name" is not imported at mohsenalizadeh.pl line 73.
Variable "$adminname" is not imported at mohsenalizadeh.pl line 73.
Variable "$myphone1" is not imported at mohsenalizadeh.pl line 73.
Variable "$myphone2" is not imported at mohsenalizadeh.pl line 73.
Variable "$myaddress" is not imported at mohsenalizadeh.pl line 73.
Variable "$mypercent" is not imported at mohsenalizadeh.pl line 73.
Variable "$name" is not imported at mohsenalizadeh.pl line 80.
Global symbol "$dbh" requires explicit package name at mohsenalizadeh.pl line 13.
Global symbol "$dbh" requires explicit package name at mohsenalizadeh.pl line 14.
Global symbol "$dbh" requires explicit package name at mohsenalizadeh.pl line 15.
Global symbol "$dbh" requires explicit package name at mohsenalizadeh.pl line 25.
Global symbol "$name" requires explicit package name at mohsenalizadeh.pl line 41.
Global symbol "$adminname" requires explicit package name at mohsenalizadeh.pl line 45.
Global symbol "$mypercent" requires explicit package name at mohsenalizadeh.pl line 48.
Global symbol "$myphone1" requires explicit package name at mohsenalizadeh.pl line 52.
Global symbol "$myphone2" requires explicit package name at mohsenalizadeh.pl line 55.
Global symbol "$myaddress" requires explicit package name at mohsenalizadeh.pl line 58.
Global symbol "$dbh" requires explicit package name at mohsenalizadeh.pl line 73.
Global symbol "$name" requires explicit package name at mohsenalizadeh.pl line 73.
Global symbol "$adminname" requires explicit package name at mohsenalizadeh.pl line 73.
Global symbol "$myphone1" requires explicit package name at mohsenalizadeh.pl line 73.
Global symbol "$myphone2" requires explicit package name at mohsenalizadeh.pl line 73.
Global symbol "$myaddress" requires explicit package name at mohsenalizadeh.pl line 73.
Global symbol "$mypercent" requires explicit package name at mohsenalizadeh.pl line 73.
Global symbol "$dbh" requires explicit package name at mohsenalizadeh.pl line 76.
Global symbol "$dbh" requires explicit package name at mohsenalizadeh.pl line 78.
Global symbol "$name" requires explicit package name at mohsenalizadeh.pl line 80.
mohsenalizadeh.pl had compilation errors.



FishMonger
Veteran / Moderator

Mar 22, 2010, 8:14 AM

Post #11 of 14 (8633 views)
Re: [mohsenalizadeh] problem with select quary when I convert program to .exe file [In reply to] Can't Post

The process of fixing those problems will probably reveal the cause of your error message.

Which fetchrow_array is the error message referring to, the one on line 15 or line 82?


mohsenalizadeh
Novice

Mar 22, 2010, 8:22 AM

Post #12 of 14 (8630 views)
Re: [FishMonger] problem with select quary when I convert program to .exe file [In reply to] Can't Post

I fixed this problem , then my code is :

Code
 
#!C:/strawberry/perl/bin/perl.exe



use Tk;
use DBI;
use DBD::mysql;
use strict;
use warnings;

our $name;
our $adminname;
our $myphone1;
our $myphone2;
our $myaddress;
our $mypercent;

my $cn = DBI->connect("DBI:mysql:telephontaxi","root","root",{mysql_enable_utf8 => 1,RaiseError => 1}) or die("Cant Connected to Databses....");
my $dbh = $cn->prepare("select * from telephonetaxiinformation");
$dbh->execute();
while(our @rec = $dbh->fetchrow_array()){
$name = $rec[1];
$adminname = $rec[2];
$myphone1 = $rec[3];
$myphone2 = $rec[4];
$myaddress = $rec[5];
$mypercent = $rec[6];
}


$dbh->finish;
$cn->disconnect;

my $mw = MainWindow->new(-background=>"gray");
$mw->title("header");
$mw->maxsize(800,315);
$mw->minsize(800,315);





$mw->Label(-text=>"header",-font => "Titr 23",-anchor=>'center',-width=>34,-background=>"gray")->place(-x => 0,-y=>0);
my $fram = $mw->Frame(-relief => 'groove',-borderwidth => 0,-width=>780,-height=>240)->place(-x => 10,-y=>64);

$fram->Label(-text => "name")->place(-x =>650,-y=>15);
$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$name)->place(-x =>410,-y=>15);



$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$adminname)->place(-x =>410,-y=>55);


$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-width=>4,-textvariable => \$mypercent)->place(-x =>170,-y=>30);



$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$myphone1)->place(-x =>410,-y=>95);


$fram->Entry(-font => "Tahoma 13 normal",-justify =>'right',-relief =>'groove',-textvariable => \$myphone2)->place(-x =>50,-y=>95);


$fram->Entry(-font => "Tahoma 13 normal",-width=>60,-justify =>'right',-relief =>'groove',-textvariable => \$myaddress)->place(-x =>50,-y=>145);




$fram->Button(-text=>"Save",-font => "Tahoma 13 normal",-command => [ \&saveinformation ])->place(-x =>370,-y=>190);
$fram->Button(-text=>"Exit",-font => "Tahoma 13 normal",-command => [$mw => 'destroy'])->place(-x =>320,-y=>190);

MainLoop;




sub saveinformation{
$cn = DBI->connect("DBI:mysql:telephontaxi","root","root",{mysql_enable_utf8 => 1,RaiseError => 1});
$dbh = $cn->prepare("update telephonetaxiinformation set azansname='$name',azansadmin='$adminname',phone1='$myphone1',
phone2='$myphone2',azansaddress='$myaddress',azanspercent='$mypercent'
where azansid='1'");
$dbh->execute();
$cn->disconnect;
$dbh->finish;
my $cn1 = DBI->connect("DBI:mysql:telephontaxi","root","root",{mysql_enable_utf8 => 1,RaiseError => 1});
my $dbh1 = $cn1->prepare("select azansid from telephonetaxiinformation where azansname='$name'");
$dbh1->execute();
my @rec = $dbh1->fetchrow_array();
print $rec[0];
if($rec[0] ne ""){
my $message = "save correctly...";

$fram->Label(-text=>"$message",-font => "homa 15")->place(-x =>600,-y=>190);
$mw->messageBox (
-default => 'Ok',
-title => "$message",
-message => "$message",
-type => 'Ok',
);
}
$dbh1->finish;
$cn1->disconnect;

}



mohsenalizadeh
Novice

Mar 22, 2010, 8:39 AM

Post #13 of 14 (8624 views)
Re: [FishMonger] problem with select quary when I convert program to .exe file [In reply to] Can't Post

fetchrow in line 22 rase error.


FishMonger
Veteran / Moderator

Mar 22, 2010, 9:12 AM

Post #14 of 14 (8620 views)
Re: [mohsenalizadeh] problem with select quary when I convert program to .exe file [In reply to] Can't Post

Don't use package globals unless they are actually needed.

Change all of your 'our' declarations to 'my' declarations.

Your choice of var names for the db calls are misleading. $dbh is normally used as the DataBase Handle, not the statement handle.

Why are you using a while loop to retrieve every record/row in the database, but only use the very last one that it returned?

The code you posted should not have generated the error you posted. Your opening statements said that you only receive this error after using the cava packager to convert the script to an exe. Is that correct, even after adding the use DBD::mysql statement?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives