Bug #48480 [Opn->Csd]: oci_bind_by_name() binds non-existing variables

From: Date: Thu, 04 Mar 2021 12:15:52 +0000
Subject: Bug #48480 [Opn->Csd]: oci_bind_by_name() binds non-existing variables
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232541@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48480&edit=1

 ID:                 48480
 Updated by:         cmb@php.net
 Reported by:        s dot pfalz at teles dot de
 Summary:            oci_bind_by_name() binds non-existing variables
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            OCI8 related
 Operating System:   Linux
 PHP Version:        5.2.9
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Indeed, like camporter1 said.


Previous Comments:
------------------------------------------------------------------------
[2019-01-03 22:13:29] camporter1 at gmail dot com

This does not appear to be a bug. The B f1 and f2 values are still bound when performing the C
iteration since the C iteration does not rebind f1 and f2, because $what does not contain them.

------------------------------------------------------------------------
[2009-06-05 11:36:42] s dot pfalz at teles dot de

Description:
------------
When using oci_bind_by_name() to add data feed by an associative array, this function adds
non-existant data! 
In the example code the function getDataArray() contains an associative array with a master key
called A,B and C. 
A and B arrays are complete, however for master key C the sub-fields "f1" and
"f2" are missing.
The code simply loops through the array, binds the values and execute the query. Normally I would
expect to run both A and B queries without any problem, however for the C query I would expect that
OCI8 lib complains about not all variables bound. See expected/actual result what happened.

Reproduce code:
---------------
// Requires table: CREATE TABLE TESTOCI(NAME VARCHAR2(10),f1 VARCHAR2(80), f2 VARCHAR2(80));
function getDataArray($which)
  {
  $data['A']['name']  = 'NAME_A';
  $data['A']['f1']    = 'A_VAL_F1';
  $data['A']['f2']    = 'A_VAL_F2';
  $data['B']['name']  = 'NAME_B';
  $data['B']['f1']    = 'B_VAL_F1';
  $data['B']['f2']    = 'B_VAL_F2';
  $data['C']['name']  = 'NAME_C';
  return($data[$which]);
  }

ini_set('error_reporting', E_ALL|E_NOTICE);
$sock = OCILogon('scott','tiger');
$stmt = OCIParse($sock,'INSERT INTO TESTOCI(NAME,F1,F2) VALUES(:name,:f1,:f2)');
$tdat = array('A','B','C');
for($i =0 ; $i < count($tdat); $i++)
  {
  $what = array();
  printf("HANDLING SET=%s\n",$tdat[$i]);
  $what = getDataArray($tdat[$i]);
  print_r($what);
  foreach($what AS $n => $v)
    {
    printf("Calling
OCIBindByName(\$stmt,'%s','%s',-1)\n",$n,$what[$n]);
    $rc = OCIBindByName($stmt,$n,$what[$n],-1);
    printf("OCIBindByName() returned %s\n",$rc);
    }
  print_r($what);
  OCIExecute($stmt,OCI_DEFAULT);
  unset($what);
  }
OCIFreeStatement($stmt);
OCICOMMIT($sock);
OCILogoff($sock);



Expected result:
----------------
I would expect that for the data array 'C' an error message should occure stating that not
all variables are bound (f1,f2). So the contents of the table should be empty because the code
should abort, and COMMIT_ON_SUCCESS is not set.



Actual result:
--------------
After running the code, the table contents look like this:

SQL> SELECT NAME,F1,F2 FROM TESTOCI;

NAME    F1              F2
--------------------------------
NAME_A  A_VAL_F1	A_VAL_F2
NAME_B  B_VAL_F1        B_VAL_F2
NAME_C  B_VAL_F1        B_VAL_F2

I really wonder how it is possible that the 3rd line contains the values of the previous call??


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



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


Thread (4 messages)

« previous php.bugs (#232541) next »