php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41388 Error in COM Object results
Submitted: 2007-05-14 15:29 UTC Modified: 2020-02-06 17:05 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:4 (100.0%)
From: superfelo at yahoo dot com Assigned: cmb (profile)
Status: Not a bug Package: COM related
PHP Version: 5.2.2 OS: Windows XP and 2003
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: superfelo at yahoo dot com
New email:
PHP Version: OS:

 

 [2007-05-14 15:29 UTC] superfelo at yahoo dot com
Description:
------------
As it is possible to see bellow, a COM Object is opened, then Data Base is read by a Recordset and a OLE object is loaded in such Recordset.

Later, using a GetChunk which is a Recordset function a number of bytes in OLE object is read but this function just result in the number of printable characters and it discards or ignore for instance, byte 0 or any other not printable character.

In the second example, it is possible to see a function to read 20 bytes after a certain position. Now the problem is similar. The 20 bytes has been counted by the results are just printable characters of such 20 bytes. So, result is less than 20 character because not all 20 characters are printable. 

Reproduce code:
---------------
$engine = new COM("DAO.DBEngine.35");
$engine->SystemDB = "c:\system.mda";
$engine->defaultuser = "admin";
$engine->defaultpassword = "";
$db = $engine->OpenDataBase("c:\bd.mdb");

$sqlstr = "SELECT DISTINCTROW tabla1.* FROM tabla1;" ;
$rst = $db->OpenRecordset("RsConfig",$sqlstr);
echo $rst->Fields["Campo1"]->GetChunk(1,20);
//-------------------------------------------------
$mstream =  new COM("ADODB.Stream");
$mstream->Type = 1; // 'adTypeBinary
$mstream->Open;
$mstream->Write($rst->Fields["Campo1"]->Value);
$mstream->position = 0;
echo $mstream->Read(20);


Expected result:
----------------
The actual number of bytes in a OLE object stored in a Recordset: This number of bytes of course, must include printable and not printable characters.

Actual result:
--------------
Just the number of printable characters.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-15 08:33 UTC] jani@php.net
Assigned to the maintainer.
 [2007-12-19 13:26 UTC] superfelo at yahoo dot com
Is there any progress?
Is working on the problem?
 [2008-11-18 16:33 UTC] xxx at xxx dot cc
?Se arreglar? alguna vez?
?Hay alguien trabajando en el problema?

Will fix any time?
Is anyone working on the problem?
 [2013-12-13 07:50 UTC] wez@php.net
-Status: Assigned +Status: Open -Assigned To: wez +Assigned To:
 [2020-02-06 17:05 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-02-06 17:05 UTC] cmb@php.net
According to the docs[1], getChunk() returns a Variant.  The
subtype isn't specified, but it is likely VT_ARRAY|VT_UI1 (you can
verify that with variant_get_type ()).  If you echo this Variant
(or otherwise convert it to a PHP string), internally it is
converted to an BSTR which is converted to a PHP string according
to the code page, which can't possibly work as intended.  Instead
you have to convert the Variant to a PHP array manually; for
instance:

    $bytes = [];
    foreach ($rst->Fields["Campo1"]->GetChunk(1,20) as $byte) {
        $bytes[] = chr($byte);
    }
    echo implode('', $bytes);

[1] <https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/field-getchunk-method-dao>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC