cpatrick has asked for the wisdom of the Perl Monks concerning the following question:

Hi all-
I am hoping someone out there has encountered this issue, and may be able to pose a possible solution. I am currently writing a cgi perl script to access a sybase table and print the results in HTML. Everything is working fine, minus a small truncation issue.
In the script, I am reading a database column that is of type varchar(1000). I perform the following perl commands:


$statement = 'SELECT Location, Usage, FROM DevelopmentTool';
$sth = $dbh->prepare($statement);
$sth->execute;


I then loop the results, and print the results into an HTML table. The location result though I am noticing truncates the output at 255 characters all of the time. I did a select directly from the database, and the entire result resides in the database, but for some reason, when selecting via the perl module and printing the results, the result always truncates.

Is there something that I am possibly missing in my query, which may prevent this truncation issue?

Thanks in advance for any help.

Chris.
  • Comment on Perl Database Select Results Being Truncated

Replies are listed 'Best First'.
Re: Perl Database Select Results Being Truncated
by injunjoel (Priest) on Apr 28, 2005 at 16:02 UTC
    Greetings all,
    Disclaimer: The following is a best guess. I am by no means a Sybase guru.
    My first question would be, are you sure the datatype should be varchar(1000)?
    That seems to ring a bell in my memory about varchar size limit being <=255 or something like that.
    Perhaps Sybase is converting it internally into something like a TEXT field or Blob since you mentioned that a direct query gives you the results you are looking for? I am wondering if Sybase is labeling the column as a varchar when Perl is trying to use it? possibly leading to the clipping you are seeing.
    Not really an answer I know but one thing to possibly try is changing the datatype of that column to a Text/Blob and read the docs about LongReadLen to figure out how to fetch it out.

    -InjunJoel

    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
      I'll talk to our database team. I originally wanted a blob type, but they said that they would give me a varchar 1000 to fit my need, but that raises a good point if Perl somehow truncates based on the 255 typical limitation of varchar. The thing that confuses me though is that if 255 is the varchar limit, why the sybase dbase allows it, and allows for me to do a command like select and retrieve the entire entry?

      Thanks again for any continued assistance.
        Hi again-

        I've tried the LongReadLen, and it still truncates. The database team has said that they kept the type varchar to save space in the database, and that it is possible to go over the 255 character contstraint for the varcar, so I am at a loss why the truncation still happens. Here is a clip of the new code with the LongReadLen attribute set:


        $dbh->{LongReadLen} = 65536;
        $statement = 'SELECT Description FROM DevelopmentTool WHERE ShortName like "%PSP%"';
        $sth = $dbh->prepare($statement);
        $sth->execute;

        while (($Description) = $sth->fetchrow) {

        print $Description . "\n\n";

        }
        Talk soon.
Re: Perl Database Select Results Being Truncated
by mpeppler (Vicar) on Apr 28, 2005 at 15:44 UTC
    Which database is this, and what perl module/client are you using?

    Michael

      I am using a Sybase database, and the Perl DBI module.

      I even tried to write a simple, non-CGI version of the script, where the perl code only does the select on the trouble column, and print to the command line...same results.
        Ah.

        Then please make sure that you have Sybase 12.5 Client Libraries installed, and that your DBD::Sybase module is recent (1.04 or later), and that it was built with the 12.5 libraries.

        Otherwise the client side of the connection tells the server side that it doesn't know about "wide" varchar columns, and you get the 255 char truncation.

        Michael

Re: Perl Database Select Results Being Truncated
by TedPride (Priest) on Apr 28, 2005 at 17:24 UTC
    Another, much more likely possibility is that the information is being cropped on input rather than output. Have you checked your database file, either by looking at the file itself or through an admin utility, to make sure there's more than 255 characters of data?

    And yes, Sybase varchar is usually 255 characters max.

      The 255 char limit was dropped in 12.5, and is now raised to a few bytes shorter than a page (a page being 2k, 4k, 8k or 16k).

      However as I mentioned above, because this change requires a change in the protocol between client and server you need to have a (relatively) recent version of the client for this to work correctly.

      Michael

        That did it...thank you so much for the help. I was pointing to older versions of the perl executable, and once I updated to versino 5.8.3, it worked the first time.

        Thanks again for the help.

        Chris
      Hi there-

      Actually, that was the first thing I did. Within the database file, I can query and retrieve the entire entry without truncation, so I know the file is valid.

      Thanks again for all of the help...
        Greetings again,
        I read through the source of DBD::Sybase and came upon this little snippet
        # Calling sp_datatype_info returns the appropriate data for the server + that # we are currently connected to. # In general the data is static, so it's not really necessary, but ASE + 12.5 # introduces some changes, in particular char/varchar max lenghts that + depend # on the server's page size. 12.5.1 introduces the DATE and TIME datat +ypes.

        might be worth investigating? If not, I think mpeppler is the author of this module, perhaps you can /msg him about this.

        -InjunJoel

        "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo