queries not getting executed?

queries not getting executed?

am 21.08.2006 14:18:04 von rvbhute

This is my code.


#! C:\Perl\bin\perl.exe -w

use strict;
use DBI;
use CGI qw(:standard);
use CGI::Carp ;
use CGI::Carp 'fatalsToBrowser' ;

print header;
print start_html('IDS');

my $dbh = DBI->connect( 'dbi:Oracle:ilclpdv3',
'rbhute',
'rbhute',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::errstr";

print p('Connected');

my $sth = $dbh->prepare("select table_name from user_tables");
$sth->execute();
while (my ($table_name) = $sth->fetchrow_array()) {
print p("$table_name");
}
$sth->finish();

print p('Disconnected');
$dbh->disconnect();


It gives the following output.

Connected

T_IDS_JOBS

T_IDS_APP

T_IDS_CLNT_DIV

T_IDS_MST_CLNT

T_IDS_MST_USR

Disconnected


Whih is correct. However, when I change the query to read any of the
tables, it shows just "Connected" and "Disconnected".

Any idea of where I'm going wrong?
--
Rohit V. Bhute
http://blog.rvbhute.org/

Re: queries not getting executed?

am 21.08.2006 14:38:40 von jseger

Add some "or die" clauses to your prepare and execute statements, like
you did to your connect.


On 8/21/06, rohit bhute wrote:
> This is my code.
>
>
> #! C:\Perl\bin\perl.exe -w
>
> use strict;
> use DBI;
> use CGI qw(:standard);
> use CGI::Carp ;
> use CGI::Carp 'fatalsToBrowser' ;
>
> print header;
> print start_html('IDS');
>
> my $dbh = DBI->connect( 'dbi:Oracle:ilclpdv3',
> 'rbhute',
> 'rbhute',
> {
> RaiseError => 1,
> AutoCommit => 0
> }
> ) || die "Database connection not made: $DBI::errstr";
>
> print p('Connected');
>
> my $sth = $dbh->prepare("select table_name from user_tables");
> $sth->execute();
> while (my ($table_name) = $sth->fetchrow_array()) {
> print p("$table_name");
> }
> $sth->finish();
>
> print p('Disconnected');
> $dbh->disconnect();
>

>
> It gives the following output.
>
> Connected
>
> T_IDS_JOBS
>
> T_IDS_APP
>
> T_IDS_CLNT_DIV
>
> T_IDS_MST_CLNT
>
> T_IDS_MST_USR
>
> Disconnected
>
>
> Whih is correct. However, when I change the query to read any of the
> tables, it shows just "Connected" and "Disconnected".
>
> Any idea of where I'm going wrong?
> --
> Rohit V. Bhute
> http://blog.rvbhute.org/
>


--
------------------------------------------------------------ --------------------------------------------------
The darkest places in hell are reserved for those who maintain their
neutrality in times of moral crisis.
Dante Alighieri (1265 - 1321)

They who would give up an essential liberty for temporary security,
deserve neither liberty or security.
Benjamin Franklin

Our lives begin to end the day we become silent about things that matter.
Martin Luther King

The right of the people to be secure in their persons, houses, papers,
and effects, against unreasonable searches and seizures, shall not be
violated, and no warrants shall issue, but upon probable cause,
supported by oath or affirmation, and particularly describing the
place to be searched, and the persons or things to be seized.

Amendment IV to the Constitution of the United States
------------------------------------------------------------ --------------------------------------------------

RE: queries not getting executed?

am 21.08.2006 15:41:12 von rjk-dbi

rohit bhute [mailto:rvbhute@gmail.com] wrote:

> [snip]
>
> Whih is correct. However, when I change the query to read any of the
> tables, it shows just "Connected" and "Disconnected".
>
> Any idea of where I'm going wrong?

You've showed us the code that works, but not the code that doesn't... :)

Are you sure the tables you're reading from aren't actually empty?

Ronald

Re: queries not getting executed?

am 22.08.2006 03:02:31 von rvbhute

Ronald J Kimball wrote:
> Are you sure the tables you're reading from aren't actually empty?
>

Thats it! I forgot to commit the changes in the sqlplus window. So the
'select' statements were working fine there, but obviously there was
nothing actually in the tables.

The only change in the code was the query - select user_name from
t_ids_mst_usr .

--
Rohit V. Bhute
http://blog.rvbhute.org