Solved

pulling HTML text from SQL database using PERL/DBI

Posted on 2014-02-25
6
210 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
  • 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now