Link to home
Start Free TrialLog in
Avatar of nachtmsk
nachtmskFlag for United States of America

asked on

pulling HTML text from SQL database using PERL/DBI

Hi,
I'm using perl/dbi to query data from a SQL server database.
I've used perl and this DB dozens of times.
In this particular case, I am not getting anything back in the variable.
Here is the code:
 
my $dbh2 = DBI->connect('DBI:ODBC:MyDB', 'username',password', {PrintError=>0, RaiseError=>0} ) or die   "Can't connect: $DBI::errstr!";

my $hdata = $dbh2->prepare("SELECT sidedata FROM hsheetsave WHERE sheetid='2'");
$hdata->execute();
($query_headerdata) = $hdata->fetchrow_array;
$hdata->finish;
$dbh2->disconnect;

If I try to print out $query_headerdata I get nothing.
If I change the query to SELECT sheetid, then it works fine and I get a result, in this case 2.
The data that exists in sidedata is HTML markup. I verified that the data is there in the database by querying it using SQL directly on the server.
I'm thinking this issue might be that I'm pulling HTML markup out and  there is some encoding issue? I don't really know though.
Is there some special way I need to us DBI to pull HTML markup out of a SQL database?
Some help is very much appreciated.
Thanks,
Nacht
Avatar of FishMonger
FishMonger
Flag of United States of America image

When you queried the db from the cli, did you use the exact same sql statement as the one used in the script?

Why did you disable the error reporting in your sql statements?  It's possible that the prepare or execute statement failed and since you're not doing any error handling, you won't know if those statements fail.
Avatar of nachtmsk

ASKER

Yes, I used the exact same statement. In fact, I copy/pasted the statement from the code into the SQL window to run it. This is something I usually do when I have a problem similar to this. Usually it shows me something in wrong with the SQL, but in this case the SQL ran perfectly in the SQL window.

As for the error checking, your right, it should be enabled. If I enable it now though and I refresh the page that is calling this script, the page never draws. If I leave it at 0, the page at least draws, but not with any data from the script. Ah, ha!  I guess I can run this script from the command line to see what errors might be coming back when I enable the error reporting to a higher level.
Fishmonger,
So I ran the script from the command line with error reporting at a 9.
I got an error, imagine that!

fetchrow_array failed:  String data, right truncation at test.pl


So, why would I be getting a truncation error if I'm querying data? I would understand if I was trying to put it into the database, but it's already in.

What do you think?
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Something else I noticed.
The data type for the sidedata field in SQL is 'text'. If I change it to varchar(xx), then it works. But it doesn't work if I change it to varchar(MAX). Stranger and stranger....
Fishmonger, I think our posts crossed each other.
Yes, I am running on Windows using ODBC. I will check the config of that.
Thanks