php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30804 multiple returned lob resource being overwritten
Submitted: 2004-11-16 14:48 UTC Modified: 2010-10-27 12:07 UTC
Votes:9
Avg. Score:4.8 ± 0.6
Reproduced:8 of 8 (100.0%)
Same Version:4 (50.0%)
Same OS:1 (12.5%)
From: michael dot caplan at lechateau dot ca Assigned: sixd (profile)
Status: Closed Package: OCI8 related
PHP Version: 5CVS-2005-04-05 OS: RHE 3
Private report: No CVE-ID: None
 [2004-11-16 14:48 UTC] michael dot caplan at lechateau dot ca
Description:
------------
I'm not 100% sure if this is a bug, or just a 'quirk', but my attempt to get feedback on this issue on the php db support list was unsuccessful.  So, here I am....

I am selecting multiple columns from a table, one being a clob.  the query returns multiple records for the query.  The results are all good, execpt the clob column in certain circumstances.  

Normally, with such a db return, I would loop through the results and grab the clobs one by one.  Under 'special' circumstances, I would want to first loop throught the results and assign the results to a new array before fetching the clob.  This is where things get funky.  In this senario, the last returned record's clob column overwrites all previous clob columns (all the previous records have there unique data, except the clob columns which contains the data for the last record across all previous records).


A working example:


$query = 'select 
                id,
                author,
                cdate,
                views,
                title,
                message,
                top
            from 
                APP_THREADS 
            where 
                TYPE = \'D\'';
$stmt = ociparse($fw_db->connection, $query);
ociexecute($stmt);

while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) {
    echo $row['MESSAGE']->load();
    echo $row['id'];
    // etc....
}


as expected, I get all clobs from the result set.  But in this example, I do not:


$query = 'select 
                id,
                author,
                cdate,
                views,
                title,
                message,
                top
            from 
                APP_THREADS 
            where 
                TYPE = \'D\'';

$stmt = ociparse($fw_db->connection, $query);
ociexecute($stmt);

while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) {
    // assign all lob resources to array for later loading
    $messages[] = $row['MESSAGE'];
}

foreach ($messages as $message) {
    echo $message->load();
}


In this example, the last assigned lob resource overwrites all previous lob resources.  When fetching the clob content later on, each record returns the data from the last lob.  

I am pretty unawair of the internal mechanics of how resources are handled, and this just might be a quirk of how db result resources for oci8 are handled, and is unavoidable.  (it looks like one resource is returned for all lobs, not multiple resources for each lob).

However, it is a pretty counter intuitive 'quirk'.  If I can loop through the results and assign all non resource elements to an array for later operations, should I not be able to do the same thing with resources?


Thanks.

Michael


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-06 21:35 UTC] michael dot caplan at lechateau dot ca
It was a little difficult to test -- php kept on segfaulting with the DB abstraction lib I normaily use.  I tried a new test as follows, but unfortunately I had the same results:

CREATE TABLE "INTRANET"."CLOB_TEST" 
   (	"ID" NUMBER NOT NULL ENABLE, 
	"TEXT_TEXT" VARCHAR2(500) NOT NULL ENABLE, 
	"CLOB_TEXT" CLOB, 
	 PRIMARY KEY ("ID")
)

ID  TEXT_TEXT  CLOB_TEXT          
--  ---------  -----------------  
1   text1      this is a clob of text1 
2   text2      this is a clob of text2  
3   text3      this is a clob of text3 
4   text4      this is a clob of text4  
5   text5      this is a clob of text5   

<?php
$db = ocinlogon('intranet', 'stidemoron', 'webdev');

$query = 'select 
                ID,
                TEXT_TEXT,
                CLOB_TEXT
            from 
                CLOB_TEST';

$stmt = ociparse($db, $query);
ociexecute($stmt);

while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) {
    echo $row['ID'] . "\r\n";
    echo $row['TEXT_TEXT'] . "\r\n";
    echo $row['CLOB_TEXT']->load() . "\r\n";
    
}

echo "----2-----\r\n";

$stmt = ociparse($db, $query);
ociexecute($stmt);

$res = array();
while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) {
    $res[] = $row['CLOB_TEXT'];
}

foreach($res as $r) {
    echo $r->load() . "\r\n";
}

?>

results:

1
text1
this is a clob of text1
2
text2
this is a clob of text2
3
text3
this is a clob of text3
4
text4
this is a clob of text4
5
text5
this is a clob of text5
----2-----
this is a clob of text5
this is a clob of text5
this is a clob of text5
this is a clob of text5
this is a clob of text5
 [2006-03-21 04:05 UTC] maxim@php.net
Well,

    echo $row['CLOB_TEXT']->load();

is not exactly the same as 
    
    $res[] = $row['CLOB_TEXT'];

In the last one you are assigning the whole object to an element of an array. This may be the reason it overwrites all the rest. 

Try this:

    $res[] = $row['CLOB_TEXT']->load();

and the print as 

foreach($res as $r) {
    echo $r . "\r\n";
}

Just my guess.

maxim
 [2006-03-21 10:05 UTC] tony2001@php.net
The problem is that we allocate ONE LOB descriptor, bind it to the statement and then fetch real data into it.
So there may be multiple resources, but all of them will point to the same lob descriptor in the end.
I still don't see a decent way to change it, but in the same time I don't think this is a major problem.
 [2008-07-04 13:35 UTC] rain_c1 at yahoo dot com
This Bug is also valid for PDO_OCI.
In PDO_OCI there is no load() method for LOBs. So the described workaround does not work. This makes this bug much more serious than evaluated until now in the discussion.
 [2010-10-27 12:07 UTC] tony2001@php.net
-Status: Suspended +Status: Closed -Package: Feature/Change Request +Package: OCI8 related -Assigned To: tony2001 +Assigned To: sixd
 [2010-10-27 12:07 UTC] tony2001@php.net
AFAIK this is fixed for a long time already.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 18:01:34 2024 UTC