Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBI MS SQL problems with selecting

Status
Not open for further replies.

danielemasson

Programmer
Apr 6, 2002
23
0
0
CO
Hi every one .. im just having problems with the TEXT fields when selecting from a perl script, when selecting INT, VARCHAR, etc. theres no problem ... but when selecting TEXT fields the while (@row = fetch_qrray) doesnt retrieve anything ... heres the code ... any help will be very appreciated, is there something i shuld know about selecting this kind of fields ??? im running MS SQL 6.5 on Win NT 4.0. Thanks

use DBI;
use CGI;

$q = new CGI;

print $q->header();


$dbh = DBI->connect("DBI:ODBC:DATABASE","user","pass",{PrintError => '1'}) || print "CANT CONNECT";

# cabecera is a field of type TEXT !!
# if i only select 'codigo' it works perfect !!
$sth=$dbh->prepare("select codigo,cabecera from noticia where region='4' and seccion = '4'") || print "Can't prepare statement: $DBI::errstr";


$sth->execute || print "Can't prepare statement: $DBI::errstr";

print &quot;Query will return $sth->{NUM_OF_FIELDS} fields.<br><br>&quot;;
print &quot;Field names: @{ $sth->{NAME} }<br><br>&quot;;

my $hashrow;
while ($var = $sth->fetchrow_hashref) {
print &quot;=> $var->{'codigo'} , $var->{'cabecera'}<br>&quot;;
}
 
First: I'm assuming that the 'q' in &quot;(@row = fetch_qrray)&quot; from your post is supposed to be an 'a'. And then, from there, I'm pretty sure that you mean &quot;(@row = $sth->fetchrow_array)&quot;. And then, going from there, I don't even see you trying your described method in the code snippet.

Instead I see that you are using the fetchrow_hashref() method. Just to eradicate the possiblity that you are having a problem due to the case sensitivity of hash keys (versus the case insensitivity of SQL) you should try this:

while ($var = $sth->fetchrow_hashref(&quot;NAME_lc&quot;){

Passing the NAME_lc argument will force the returned hash's key's to be lowercase - which may fix your problem.

--jim

 
youre right about those little mistakes, i tried NAME_lc ... still the loop doesnt retrieve anything it doesnt even go trough the rows.
 
Are you sure that the SQL statement actually produces a record set? Have you tested via some other SQL-client?

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top