From:             andrew dot craft at wyndhamworldwide dot com
Operating system: Windows XP SP2 32bit
PHP version:      5.2.1
PHP Bug Type:     MySQLi related
Bug description:  Insert row with unique key violation, no error.

Description:
------------
I am using mysql 5.0.27.

There is a table that has a unique index on it. When inserting a new row
that would violate the uniqueness using a prepared statement no
errors/exceptions are raised. When looking at the query log the statement
is prepared but no executions queries. Should there not be an exception
raised for the error?

I did a google search and searched the bug database but did not find an
existing issue.

Reproduce code:
---------------
CREATE TABLE `docs_classification` (
  `classification_id` smallint(6) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `description` varchar(255) NOT NULL,
  `short_name` char(3) NOT NULL,
  `bit_value` int(11) NOT NULL,
  PRIMARY KEY  (`classification_id`),
  UNIQUE KEY `bit_value` (`bit_value`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

//////////
First Run

array('test1', 'test1test1', 'TS1', '1'),
array('test2', 'test2test2', 'TS2', '2'),
array('test3', 'test3test3', 'TS3', '4')
);

$m = new mysqli('localhost', 'dbuser', '','dbname');
$sql = 'INSERT INTO dbtable '
' (classification_id, name, description, short_name, bit_value) '.
' VALUES (NULL, ?, ?, ?, ?)';

$stmt = $m->prepare($sql);

foreach ($a as $b)
{
        $stmt->bind_param('ssss', $b[0], $b[1], $b[2], $b[3]);
        $stmt->execute();
}

///////
Then repeat above code and no errors are raised.

Expected result:
----------------
Expected to be notified of the duplicate entry error in the bit_value
field when re-running the code.

Actual result:
--------------
No errors or indication of any errors.

In the query log it shows the sql being prepared but no Execute commands.

-- 
Edit bug report at http://bugs.php.net/?id=40969&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=40969&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=40969&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=40969&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40969&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=40969&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40969&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40969&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40969&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40969&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40969&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=40969&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=40969&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40969&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40969&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40969&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40969&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40969&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40969&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40969&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40969&r=mysqlcfg

Reply via email to