Solved

pulling HTML text from SQL database using PERL/DBI

Posted on 2014-02-25
6
215 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

717 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