PDO uses inconsistant error codes between DBs

Josh Waihi - June 30, 2009 - 01:05
Project:Drupal
Version:7.x-dev
Component:simpletest.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Issue tags:PostgreSQL Surge
Description

The simpletest 'Invalid data' currently has one fail in Postgresql (and most likely sqlite too) because of this:

<?php
     
// 23000 means "Integrity constraint violation" according to ANSI SQL.
     
$this->assertEqual($e->errorInfo[0], '23000', t('Exception has proper SQLSTATE.'));
?>

This error code is only returned from MySQL. PostgreSQL returns 23505 - "duplicate key value violates unique constraint", which is more accurate than what MySQL reports back. It would seem to me that were looking for error codes between in the 23000s is that how we want to patch this?

#1

andypost - June 30, 2009 - 01:39

Suppose testing environment should know db type and use local code

#2

andypost - July 1, 2009 - 11:49

Another trouble with that issue - this exception handler works inside simpletest's exception handler so sometimes (depends on php version and env config) bring unpredictable results, for example broke batch while returning exception after JSON data

#3

Josh Waihi - July 5, 2009 - 02:55

The simple fact that databases will return different error codes means that this is an unreliable way to write code. It is not a condition Drupal can rely on due to its inconsistantcy between databases.

So lets just remove it and not encourage the use of it in code.

AttachmentSizeStatusTest resultOperations
505812-remove-ANSI-SQLSTATE-error-codes.patch975 bytesIdlePassed: 11562 passes, 0 fails, 0 exceptionsView details | Re-test

#4

andypost - July 5, 2009 - 03:45

Suppose much better to remove this test at all then leave without assert

#5

Josh Waihi - July 5, 2009 - 04:05
Status:active» needs review

@andypost, this test does other assertions that are usefull, its merely the error code assertion that is not of any use.

#6

andypost - July 5, 2009 - 23:42
Status:needs review» reviewed & tested by the community

So lets commit this, I see no useful info in this assertion

#7

Dries - July 6, 2009 - 13:33
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks!

#8

System Message - July 20, 2009 - 13:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#9

c960657 - August 15, 2009 - 21:13

FWIW, Sqlite also returns 23000.

 
 

Drupal is a registered trademark of Dries Buytaert.