PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #48324 oci_bind_by_name() returning wrong id value
Submitted:19 May 2009 1:48am UTC Modified: 19 May 2009 5:12pm UTC
From:roger dot robins at det dot nsw dot edu dot au Assigned to:
Status:Bogus Category:OCI8 related
Version:5.2.9 OS:Linux Redhat ES 3.0
View/Vote Developer Edit Submission

Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can not add a comment to this report as it is marked as closed. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Category:
Summary:
From: roger dot robins at det dot nsw dot edu dot au
New email:
Version: OS:
New Comment:

[19 May 2009 1:48am UTC] roger dot robins at det dot nsw dot edu dot au
Description:
------------
When INSERTing a record into a table that has a database sequence for
calculating the table id (unique identifier) and that sequence's
next_val has reached double figures; and you use oci_bind_by_name to
return the id of the inserted row; then only the first digit of the two
digit row id is returned.

Code:
 $sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($values)
$returning";
$id = null;

$this->query_start($sql, $params, SQL_QUERY_INSERT);
$stmt = $this->parse_query($sql);
$descriptors = $this->bind_params($stmt, $params, $table);
if ($returning) {
      oci_bind_by_name($stmt, ":oracle_id", $id, -1, SQLT_LNG);
}
$result = oci_execute($stmt);
$this->free_descriptors($descriptors);
$this->query_end($result, $stmt);
oci_free_statement($stmt);

Reproduce code:
---------------
Environment:
PHP 5.2.9 compiled again Oracle 10.2 or 11.1 client, connecting to
Oracle 10.2 database.

'./configure' '--with-apxs2=/usr/local/apache/bin/apxs'
'--with-mysql=/usr/bin' '--enable-soap' '--with-curl' '--with-xmlrpc'
'--enable-mbstring' '--with-openssl' '--enable-zip' '--with-ldap'
'--with-oci8=/apps/oraoid/app/oraoid/product/11.1.0/client_1' 

Expected result:
----------------
When the database table sequence reaches double figures, the correct
table (seed) id should be returned as a result of sql INSERT command and
calling oci_bind_by_name. 

Actual result:
--------------
The id returned is only the first digit of the real row id.
[19 May 2009 5:12pm UTC] sixd@php.net
Passing a -1 length to the oci_bind_by_name call allocates only enough
storage for the current size of $id at the time of the call. A size of 1
is used for a null.

Instead of -1, pass a length big enough to hold your largest expected
return value.

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC