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

I'm pushing stored procedures into sybase:dbi from a file. Apparently I'm bumping up against perl's max string length constraint. I want to know if there is a way to increase the max string length as (or before?) I build this string. And is there a prefered way to give this extremely long string to dbi other than: $sth = $dbh->prepare($long_ass_string); $sth->execute();

Replies are listed 'Best First'.
Re: max string len
by shenme (Priest) on Feb 04, 2005 at 23:02 UTC
    Whatever problems you have aren't "Perl string max string length" problems.
    my $long_winded_string = "This is a weighty argument, though a bi +t light on the reasoning" x 1_048_576; printf "How long is it? %d characters\n", length( $long_winded_st +ring ); __DATA__ How long is it? 66060288 characters
    You may indeed be having problems convincing Sybase to take your large BLOBs (hint)

    Update: I went looking (Google) and found this mention from the "Programming the Perl DBI" book, in "Appendix B. Driver and Database Characteristics":

    LongReadLen and LongTrunkOk attributes have no effect. The default limit for TEXT/IMAGE data is 32 KB, but this can be changed by the SET TEXTSIZE Transact-SQL command.
Re: max string len
by cowboy (Friar) on Feb 04, 2005 at 23:04 UTC

    Max string length constraint?

    I'm able to easily use a string containing 100,000,000, characters.

    Can you post example code, and the error messages you are receiving?

    If there is a limit, I am guessing it is dbi:sybase, rather than perl that is hitting it.

    Something you might try is using $dbh->do() rather than preparing and then executing the statement. It wouldn't suprise me if the driver had a limit of what it could store as a prepared statement.
Re: max string len
by Old_Gray_Bear (Bishop) on Feb 04, 2005 at 23:12 UTC
    I suspect what you are running into is shortage of memory, not length of string. I just build a 1G string before my windows box decided to croak (Process short of Virtual memory....). I don't recall seeing anything in The Camel putting an artificial limit on the length of a string. Perhaps you could post the message that you are getting?

    ----
    I Go Back to Sleep, Now.

    OGB

Re: max string len
by Anonymous Monk on Feb 04, 2005 at 23:12 UTC
    This fails to print out the entire file... I managed to exclude perl:dbi from the problem.
    open(SQL, "$filepath") || die "Cannot open file $filepath: $!"; @lines =<SQL>; for($ii=0; $ii < @lines; $ii++) { $command_str = $command_str . $lines[$ii]; } print $command_str; print "\n";
      Seeing your example here, I imagine you want something like this:
      my $command_str = join('', <SQL>); printf("%s\n", $command_str);
      Using concatenation like that is a very inefficient way to build a string. cowboy's suggestion is fine, or you could also replace everything from @lines = <SQL> on down with
      { local $/; $command_str = <SQL>; }
      and don't bother with @lines.
      Maybe your DATA in the file has carraige returns in it.

      Try removing them? or try replacing all carriage returns

      And another suggestion, maybe you can tell what exactly isn't showing. You said 'fails to print out the entire file' then how much data is it printing?

Re: max string len
by Anonymous Monk on Feb 04, 2005 at 23:15 UTC
    this file is only 12,000 chars in size. Thanks big bear. I'm thinking that the . concat is blowing up somehow....
      I seriously doubt it. Perl is not the issue here unless you are doing something drastically different than you are showing us. Check the database, check the actual file, the paths, etc.