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

Hi.
I'm using the dbi module to access an Oracle 8 database running on Windows NT.
Surprisingly, I get an error message, if one of the fields in the table is longer than aprox. 200 characters. It seems to be limiting me in the amount of data the dbi can handle.

Does anyone know what could the problem be?

Thanks,
Ralph :)

Replies are listed 'Best First'.
(Ovid) Re: dbi problem
by Ovid (Cardinal) on Oct 15, 2000 at 03:55 UTC
    I've dealt with similar issues using MS SQL Server 7.0. Apparently, DBI sometimes insists upong trying a "varchar" when you want a longvarchar. I used an approach like the following to deal with this:
    #!c:\perl\bin\perl.exe -w use strict; use DBI qw':sql_types'; my $DSN = '********'; my $USER = '********'; my $PASSWORD = '********'; # Connect to database my $dbh = DBI->connect("dbi:ODBC:$DSN", $USER, $PASSWORD, {RaiseError => 1}) or die "Couldn't connect to database: " . DBI->errstr; # 0 - Trace disabled. # 1 - Trace DBI method calls returning with results or errors. # 2 - Trace method entry with parameters and returning with results. # 3 - As above, adding some high-level information from the driver # and some internal information from the DBI. # 4 - As above, adding more detailed information from the driver. # Also includes DBI mutex information when using threaded Perl. # 5 and above - As above but with more and more obscure information. DBI->trace(2, "trace.txt");
    The trace statement creates a file ("trace.txt", in this case) with a trace of the DBI functions, including what variable types it's trying to bind columns to. You can read through the trace to find out if it's trying to bind the wrong type. If so, the following should work (so long as you use :sql_types):
    $sth->bind_param($bind_col, $variable, SQL_LONGVARCHAR);
    The sql must be prepared first, and it must be prepared with placeholders. Then, $bind_col is the number of the placeholder you wish to bind and $variable is the data to be bound to it. Also, note that the $sth->execute( $variable ); statement will still contain the variable being bound.

    If you're creating some tricky SQL, consult the trace file after this method to ensure that you are binding the correct column.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

RE: dbi problem
by lachoy (Parson) on Oct 15, 2000 at 08:06 UTC

    Not sure if this is your problem, but it's worth a shot. From the DBI docs:

    LongReadLen (unsigned integer, inherited) This attribute may be used to control the maximum length of 'long' ('blob', 'memo' etc.) fields which the driver will read from the database automatically when it fetches each row of data. The LongReadLen attribute only relates to fetching/reading long values it is not involved in inserting/updating them. A value of 0 means don't automatically fetch any long data (fetch should return undef for long fields when LongReadLen is 0). The default is typically 0 (zero) bytes but may vary between drivers. Applications fetching long fields should set this value to slightly larger than the longest long field value which will be fetched.

    Use it like this:

    $dbh->{LongReadLen} = 65536; my $sth = $dbh->prepare( 'select blah from bleh' ); $sth->execute; ...
Re: dbi problem
by jptxs (Curate) on Oct 15, 2000 at 01:50 UTC

    update part duex: there should be no problem with Oracle 8 and Longs from the way i read perldoc DBD::Oracle. But I stick by my first statement: use the VARCHAR if you can - it will make your life much easier. FYI: jptxs is an Oracle consultant : )

    update: saw this second post just as i found the sections on limits for longs : ) more in a second, but first question is why not just use varchar if it can hold what you need it to? it'll be easier to maintain too.

    A search through preldoc DBI and Programming the Perl DBI reveal nothing about limits to how much data you can transfer.

    Oracle has limits on certian types of datatypes (RAW can't be greater than 2000 bytes and VARCHARs are not allowed over 4000 bytes). Maybe you're actually hitting one of these limits? Why don't you post your code and we'll all find out : )

    -- I'm a solipsist, and so is everyone else. (think about it)

RE: dbi problem
by PsychoSpunk (Hermit) on Oct 16, 2000 at 20:13 UTC
    We had a similar problem with the DBD::ODBC. If I recall correctly, it was the value that was returned that caused this problem, so it was only on SELECT statements. Our solution was to pass LongTruncOk => 1 in the hash reference that you pass into your connect string. I didn't solve this problem, so I'm not sure what effect it truly has. But, if it's any assistance, I'm glad to help.

    ALL HAIL BRAK!!!

Re: dbi problem
by Anonymous Monk on Oct 15, 2000 at 01:49 UTC
    And one more thing...
    the field is type in the database 'LONG'.
    With varchar2 it does work.
    Ralph :)
Re: dbi problem
by Anonymous Monk on Oct 15, 2000 at 02:26 UTC
    hi.
    i'm not using varchar2, cause it limits me to 2000 characters, and i need more than that.

    ralph :)

      OK. could you maybe post the code and the text of the errors you're getting?

      -- I'm a solipsist, and so is everyone else. (think about it)

Re: dbi problem
by Anonymous Monk on Oct 17, 2000 at 13:08 UTC
    Hi.

    Thanks to all for your help. I was finally able to solve it by adding the line...
    $dbh->{LongReadLen} = 65536;

    Thanks again!
    Ralph :)