php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70104 odbc_fetch_array returns uninitialized values for Booleans
Submitted: 2015-07-20 19:42 UTC Modified: 2020-10-06 23:22 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: brucebailey320 at gmail dot com Assigned: cmb (profile)
Status: Closed Package: ODBC related
PHP Version: 5.6.11 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: brucebailey320 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-07-20 19:42 UTC] brucebailey320 at gmail dot com
Description:
------------
The PHP function odbc_fetch_array returns uninitialized values for PostgreSQL boolean values.  On older systems, this function returned '1' for true and '0' for false values.  On our 64 bit system, the boolean values appear to be uninitialized data.

Additional information

Increasing buffer size in php_odbc.c (odbc.so) in function odbc_bindcols, just prior to call to SQLBindCol makes problem stop exhibiting.
SQLColAttributes(...,SQL_COLUMN_TYPE,...) returns type of SQL_VARCHAR on system with problem, SQL_CHAR on system where code works as expected.
SQLColAttributes is deprecated (shouldn't matter, though)

Recreation steps:

// Create table/data in PostgreSQL

DROP TABLE IF EXISTS public.persons;
create table public.persons (id int, name varchar(255), switch_sw boolean);
insert into public.persons values (0, 'smith', true);
insert into public.persons values (1, 'jones', false);
insert into public.persons values (2, 'bailey', true);
insert into public.persons values (3, 'johnson', false);


Software levels

kernel - Linux C921189 3.10.0-123.20.1.el7.x86_64 . . . GNU/Linux
ODBC - libodbc.so.1 (cannot exactly determine version)
PostgreSQL - 9.3.0
PHP - 5.6.7

This system is little endian


Test script:
---------------
<?php

   if(!($conn = odbc_connect("..." , "..." , "...")))
      die("odbc_connect failed\n");

   if(!($rows = odbc_exec($conn, "select * from persons;")))
      die("odbc_exec failed\n");

   for(;;)
   {
      if (!($row = odbc_fetch_array ($rows)))
         break;

      print_r($row);
   }

   odbc_close($conn);
?>


Expected result:
----------------
Array
(
    [id] => 0
    [name] => smith
    [switch_sw] => 1
)
. . .


Actual result:
--------------
Array
(
    [id] => 0
    [name] => smith
    [switch_sw] => . // some unreadable binary content
)
. . .


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-06 14:41 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-10-06 14:41 UTC] cmb@php.net
I cannot reproduce that with PHP 7.3 and the PostgreSQL
Unicode(x64) driver on a PostgreSQL 10 database server (on
Windows).  The boolean fields are reported to be SQL_VARCHARs,
with a length of 1 (byte), and are returned as expected.

Is that still an issue for you with any of the actively supported
PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2020-10-06 22:55 UTC] brucebailey320 at gmail dot com
-Status: Feedback +Status: Assigned
 [2020-10-06 22:55 UTC] brucebailey320 at gmail dot com
You can go ahead and close this defect
 [2020-10-06 23:22 UTC] requinix@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 12:01:31 2024 UTC