Edit report at http://bugs.php.net/bug.php?id=30804&edit=1

 ID:                 30804
 Updated by:         tony2...@php.net
 Reported by:        michael dot caplan at lechateau dot ca
 Summary:            multiple returned lob resource being overwritten
-Status:             Suspended
+Status:             Closed
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            OCI8 related
 Operating System:   RHE 3
 PHP Version:        5CVS-2005-04-05
-Assigned To:        tony2001
+Assigned To:        sixd
 Block user comment: N

 New Comment:

AFAIK this is fixed for a long time already.


Previous Comments:
------------------------------------------------------------------------
[2008-07-04 13:35:24] 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.

------------------------------------------------------------------------
[2006-03-21 10:05:41] tony2...@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.

------------------------------------------------------------------------
[2006-03-21 04:05:20] ma...@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

------------------------------------------------------------------------
[2005-04-06 21:35:25] 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

------------------------------------------------------------------------
[2004-11-16 14:48:26] 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



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=30804&edit=1

Reply via email to