Solved

pulling HTML text from SQL database using PERL/DBI

Posted on 2014-02-25
6
214 Views
Last Modified: 2014-03-03
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
0
Comment
Question by:nachtmsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 39886302
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.
0
 

Author Comment

by:nachtmsk
ID: 39886332
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.
0
 

Author Comment

by:nachtmsk
ID: 39886349
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?
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 28

Accepted Solution

by:
FishMonger earned 500 total points
ID: 39886417
How is that db field defined and what's the total length of data being stored in that field?

Take a look at the DBI attributes LongTruncOk and LongReadlen

Are you running this on Windows?  There are a couple of related ODBC adjustments that can be set to fix this issue, but I'm not exactly sure what adjustments need to be made.
0
 

Author Comment

by:nachtmsk
ID: 39886424
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....
0
 

Author Comment

by:nachtmsk
ID: 39886431
Fishmonger, I think our posts crossed each other.
Yes, I am running on Windows using ODBC. I will check the config of that.
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question