Back to index

php5  5.3.10
pdo_sqlstate.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Wez Furlong <wez@php.net>                                    |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: pdo_sqlstate.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include "config.h"
00023 #endif
00024 
00025 #include "php.h"
00026 #include "php_ini.h"
00027 #include "ext/standard/info.h"
00028 #include "php_pdo.h"
00029 #include "php_pdo_driver.h"
00030 
00031 struct pdo_sqlstate_info {
00032        const char state[5];
00033        const char *desc;
00034 };
00035 
00036 static HashTable err_hash;
00037 
00038 static const struct pdo_sqlstate_info err_initializer[] = {
00039        { "00000",    "No error" },
00040        { "01000",    "Warning" },
00041        { "01001",    "Cursor operation conflict" },
00042        { "01002",    "Disconnect error" },
00043        { "01003",    "NULL value eliminated in set function" },
00044        { "01004",    "String data, right truncated" },
00045        { "01006",    "Privilege not revoked" },
00046        { "01007",    "Privilege not granted" },
00047        { "01008",    "Implicit zero bit padding" },
00048        { "0100C",    "Dynamic result sets returned" },
00049        { "01P01",    "Deprecated feature" },
00050        { "01S00",    "Invalid connection string attribute" },
00051        { "01S01",    "Error in row" },
00052        { "01S02",    "Option value changed" },
00053        { "01S06",    "Attempt to fetch before the result set returned the first rowset" },
00054        { "01S07",    "Fractional truncation" },
00055        { "01S08",    "Error saving File DSN" },
00056        { "01S09",    "Invalid keyword" },
00057        { "02000",    "No data" },
00058        { "02001",    "No additional dynamic result sets returned" },
00059        { "03000",    "Sql statement not yet complete" },
00060        { "07002",    "COUNT field incorrect" },
00061        { "07005",    "Prepared statement not a cursor-specification" },
00062        { "07006",    "Restricted data type attribute violation" },
00063        { "07009",    "Invalid descriptor index" },
00064        { "07S01",    "Invalid use of default parameter" },
00065        { "08000",    "Connection exception" },
00066        { "08001",    "Client unable to establish connection" },
00067        { "08002",    "Connection name in use" },
00068        { "08003",    "Connection does not exist" },
00069        { "08004",    "Server rejected the connection" },
00070        { "08006",    "Connection failure" },
00071        { "08007",    "Connection failure during transaction" },
00072        { "08S01",    "Communication link failure" },
00073        { "09000",    "Triggered action exception" },
00074        { "0A000",    "Feature not supported" },
00075        { "0B000",    "Invalid transaction initiation" },
00076        { "0F000",    "Locator exception" },
00077        { "0F001",    "Invalid locator specification" },
00078        { "0L000",    "Invalid grantor" },
00079        { "0LP01",    "Invalid grant operation" },
00080        { "0P000",    "Invalid role specification" },
00081        { "21000",    "Cardinality violation" },
00082        { "21S01",    "Insert value list does not match column list" },
00083        { "21S02",    "Degree of derived table does not match column list" },
00084        { "22000",    "Data exception" },
00085        { "22001",    "String data, right truncated" },
00086        { "22002",    "Indicator variable required but not supplied" },
00087        { "22003",    "Numeric value out of range" },
00088        { "22004",    "Null value not allowed" },
00089        { "22005",    "Error in assignment" },
00090        { "22007",    "Invalid datetime format" },
00091        { "22008",    "Datetime field overflow" },
00092        { "22009",    "Invalid time zone displacement value" },
00093        { "2200B",    "Escape character conflict" },
00094        { "2200C",    "Invalid use of escape character" },
00095        { "2200D",    "Invalid escape octet" },
00096        { "2200F",    "Zero length character string" },
00097        { "2200G",    "Most specific type mismatch" },
00098        { "22010",    "Invalid indicator parameter value" },
00099        { "22011",    "Substring error" },
00100        { "22012",    "Division by zero" },
00101        { "22015",    "Interval field overflow" },
00102        { "22018",    "Invalid character value for cast specification" },
00103        { "22019",    "Invalid escape character" },
00104        { "2201B",    "Invalid regular expression" },
00105        { "2201E",    "Invalid argument for logarithm" },
00106        { "2201F",    "Invalid argument for power function" },
00107        { "2201G",    "Invalid argument for width bucket function" },
00108        { "22020",    "Invalid limit value" },
00109        { "22021",    "Character not in repertoire" },
00110        { "22022",    "Indicator overflow" },
00111        { "22023",    "Invalid parameter value" },
00112        { "22024",    "Unterminated c string" },
00113        { "22025",    "Invalid escape sequence" },
00114        { "22026",    "String data, length mismatch" },
00115        { "22027",    "Trim error" },
00116        { "2202E",    "Array subscript error" },
00117        { "22P01",    "Floating point exception" },
00118        { "22P02",    "Invalid text representation" },
00119        { "22P03",    "Invalid binary representation" },
00120        { "22P04",    "Bad copy file format" },
00121        { "22P05",    "Untranslatable character" },
00122        { "23000",    "Integrity constraint violation" },
00123        { "23001",    "Restrict violation" },
00124        { "23502",    "Not null violation" },
00125        { "23503",    "Foreign key violation" },
00126        { "23505",    "Unique violation" },
00127        { "23514",    "Check violation" },
00128        { "24000",    "Invalid cursor state" },
00129        { "25000",    "Invalid transaction state" },
00130        { "25001",    "Active sql transaction" },
00131        { "25002",    "Branch transaction already active" },
00132        { "25003",    "Inappropriate access mode for branch transaction" },
00133        { "25004",    "Inappropriate isolation level for branch transaction" },
00134        { "25005",    "No active sql transaction for branch transaction" },
00135        { "25006",    "Read only sql transaction" },
00136        { "25007",    "Schema and data statement mixing not supported" },
00137        { "25008",    "Held cursor requires same isolation level" },
00138        { "25P01",    "No active sql transaction" },
00139        { "25P02",    "In failed sql transaction" },
00140        { "25S01",    "Transaction state" },
00141        { "25S02",    "Transaction is still active" },
00142        { "25S03",    "Transaction is rolled back" },
00143        { "26000",    "Invalid sql statement name" },
00144        { "27000",    "Triggered data change violation" },
00145        { "28000",    "Invalid authorization specification" },
00146        { "2B000",    "Dependent privilege descriptors still exist" },
00147        { "2BP01",    "Dependent objects still exist" },
00148        { "2D000",    "Invalid transaction termination" },
00149        { "2F000",    "Sql routine exception" },
00150        { "2F002",    "Modifying sql data not permitted" },
00151        { "2F003",    "Prohibited sql statement attempted" },
00152        { "2F004",    "Reading sql data not permitted" },
00153        { "2F005",    "Function executed no return statement" },
00154        { "34000",    "Invalid cursor name" },
00155        { "38000",    "External routine exception" },
00156        { "38001",    "Containing sql not permitted" },
00157        { "38002",    "Modifying sql data not permitted" },
00158        { "38003",    "Prohibited sql statement attempted" },
00159        { "38004",    "Reading sql data not permitted" },
00160        { "39000",    "External routine invocation exception" },
00161        { "39001",    "Invalid sqlstate returned" },
00162        { "39004",    "Null value not allowed" },
00163        { "39P01",    "Trigger protocol violated" },
00164        { "39P02",    "Srf protocol violated" },
00165        { "3B000",    "Savepoint exception" },
00166        { "3B001",    "Invalid savepoint specification" },
00167        { "3C000",    "Duplicate cursor name" },
00168        { "3D000",    "Invalid catalog name" },
00169        { "3F000",    "Invalid schema name" },
00170        { "40000",    "Transaction rollback" },
00171        { "40001",    "Serialization failure" },
00172        { "40002",    "Transaction integrity constraint violation" },
00173        { "40003",    "Statement completion unknown" },
00174        { "40P01",    "Deadlock detected" },
00175        { "42000",    "Syntax error or access violation" },
00176        { "42501",    "Insufficient privilege" },
00177        { "42601",    "Syntax error" },
00178        { "42602",    "Invalid name" },
00179        { "42611",    "Invalid column definition" },
00180        { "42622",    "Name too long" },
00181        { "42701",    "Duplicate column" },
00182        { "42702",    "Ambiguous column" },
00183        { "42703",    "Undefined column" },
00184        { "42704",    "Undefined object" },
00185        { "42710",    "Duplicate object" },
00186        { "42712",    "Duplicate alias" },
00187        { "42723",    "Duplicate function" },
00188        { "42725",    "Ambiguous function" },
00189        { "42803",    "Grouping error" },
00190        { "42804",    "Datatype mismatch" },
00191        { "42809",    "Wrong object type" },
00192        { "42830",    "Invalid foreign key" },
00193        { "42846",    "Cannot coerce" },
00194        { "42883",    "Undefined function" },
00195        { "42939",    "Reserved name" },
00196        { "42P01",    "Undefined table" },
00197        { "42P02",    "Undefined parameter" },
00198        { "42P03",    "Duplicate cursor" },
00199        { "42P04",    "Duplicate database" },
00200        { "42P05",    "Duplicate prepared statement" },
00201        { "42P06",    "Duplicate schema" },
00202        { "42P07",    "Duplicate table" },
00203        { "42P08",    "Ambiguous parameter" },
00204        { "42P09",    "Ambiguous alias" },
00205        { "42P10",    "Invalid column reference" },
00206        { "42P11",    "Invalid cursor definition" },
00207        { "42P12",    "Invalid database definition" },
00208        { "42P13",    "Invalid function definition" },
00209        { "42P14",    "Invalid prepared statement definition" },
00210        { "42P15",    "Invalid schema definition" },
00211        { "42P16",    "Invalid table definition" },
00212        { "42P17",    "Invalid object definition" },
00213        { "42P18",    "Indeterminate datatype" },
00214        { "42S01",    "Base table or view already exists" },
00215        { "42S02",    "Base table or view not found" },
00216        { "42S11",    "Index already exists" },
00217        { "42S12",    "Index not found" },
00218        { "42S21",    "Column already exists" },
00219        { "42S22",    "Column not found" },
00220        { "44000",    "WITH CHECK OPTION violation" },
00221        { "53000",    "Insufficient resources" },
00222        { "53100",    "Disk full" },
00223        { "53200",    "Out of memory" },
00224        { "53300",    "Too many connections" },
00225        { "54000",    "Program limit exceeded" },
00226        { "54001",    "Statement too complex" },
00227        { "54011",    "Too many columns" },
00228        { "54023",    "Too many arguments" },
00229        { "55000",    "Object not in prerequisite state" },
00230        { "55006",    "Object in use" },
00231        { "55P02",    "Cant change runtime param" },
00232        { "55P03",    "Lock not available" },
00233        { "57000",    "Operator intervention" },
00234        { "57014",    "Query canceled" },
00235        { "57P01",    "Admin shutdown" },
00236        { "57P02",    "Crash shutdown" },
00237        { "57P03",    "Cannot connect now" },
00238        { "58030",    "Io error" },
00239        { "58P01",    "Undefined file" },
00240        { "58P02",    "Duplicate file" },
00241        { "F0000",    "Config file error" },
00242        { "F0001",    "Lock file exists" },
00243        { "HY000",    "General error" },
00244        { "HY001",    "Memory allocation error" },
00245        { "HY003",    "Invalid application buffer type" },
00246        { "HY004",    "Invalid SQL data type" },
00247        { "HY007",    "Associated statement is not prepared" },
00248        { "HY008",    "Operation canceled" },
00249        { "HY009",    "Invalid use of null pointer" },
00250        { "HY010",    "Function sequence error" },
00251        { "HY011",    "Attribute cannot be set now" },
00252        { "HY012",    "Invalid transaction operation code" },
00253        { "HY013",    "Memory management error" },
00254        { "HY014",    "Limit on the number of handles exceeded" },
00255        { "HY015",    "No cursor name available" },
00256        { "HY016",    "Cannot modify an implementation row descriptor" },
00257        { "HY017",    "Invalid use of an automatically allocated descriptor handle" },
00258        { "HY018",    "Server declined cancel request" },
00259        { "HY019",    "Non-character and non-binary data sent in pieces" },
00260        { "HY020",    "Attempt to concatenate a null value" },
00261        { "HY021",    "Inconsistent descriptor information" },
00262        { "HY024",    "Invalid attribute value" },
00263        { "HY090",    "Invalid string or buffer length" },
00264        { "HY091",    "Invalid descriptor field identifier" },
00265        { "HY092",    "Invalid attribute/option identifier" },
00266        { "HY093",    "Invalid parameter number" },
00267        { "HY095",    "Function type out of range" },
00268        { "HY096",    "Invalid information type" },
00269        { "HY097",    "Column type out of range" },
00270        { "HY098",    "Scope type out of range" },
00271        { "HY099",    "Nullable type out of range" },
00272        { "HY100",    "Uniqueness option type out of range" },
00273        { "HY101",    "Accuracy option type out of range" },
00274        { "HY103",    "Invalid retrieval code" },
00275        { "HY104",    "Invalid precision or scale value" },
00276        { "HY105",    "Invalid parameter type" },
00277        { "HY106",    "Fetch type out of range" },
00278        { "HY107",    "Row value out of range" },
00279        { "HY109",    "Invalid cursor position" },
00280        { "HY110",    "Invalid driver completion" },
00281        { "HY111",    "Invalid bookmark value" },
00282        { "HYC00",    "Optional feature not implemented" },
00283        { "HYT00",    "Timeout expired" },
00284        { "HYT01",    "Connection timeout expired" },
00285        { "IM001",    "Driver does not support this function" },
00286        { "IM002",    "Data source name not found and no default driver specified" },
00287        { "IM003",    "Specified driver could not be loaded" },
00288        { "IM004",    "Driver's SQLAllocHandle on SQL_HANDLE_ENV failed" },
00289        { "IM005",    "Driver's SQLAllocHandle on SQL_HANDLE_DBC failed" },
00290        { "IM006",    "Driver's SQLSetConnectAttr failed" },
00291        { "IM007",    "No data source or driver specified; dialog prohibited" },
00292        { "IM008",    "Dialog failed" },
00293        { "IM009",    "Unable to load translation DLL" },
00294        { "IM010",    "Data source name too long" },
00295        { "IM011",    "Driver name too long" },
00296        { "IM012",    "DRIVER keyword syntax error" },
00297        { "IM013",    "Trace file error" },
00298        { "IM014",    "Invalid name of File DSN" },
00299        { "IM015",    "Corrupt file data source" },
00300        { "P0000",    "Plpgsql error" },
00301        { "P0001",    "Raise exception" },
00302        { "XX000",    "Internal error" },
00303        { "XX001",    "Data corrupted" },
00304        { "XX002",    "Index corrupted" }
00305 };
00306 
00307 void pdo_sqlstate_fini_error_table(void)
00308 {
00309        zend_hash_destroy(&err_hash);
00310 }
00311 
00312 int pdo_sqlstate_init_error_table(void)
00313 {
00314        int i;
00315        const struct pdo_sqlstate_info *info;
00316 
00317        if (FAILURE == zend_hash_init(&err_hash,
00318                      sizeof(err_initializer)/sizeof(err_initializer[0]), NULL, NULL, 1)) {
00319               return FAILURE;
00320        }
00321 
00322        for (i = 0; i < sizeof(err_initializer)/sizeof(err_initializer[0]); i++) {
00323               info = &err_initializer[i];
00324 
00325               zend_hash_add(&err_hash, info->state, sizeof(info->state), &info, sizeof(info), NULL);
00326        }
00327 
00328        return SUCCESS;
00329 }
00330 
00331 const char *pdo_sqlstate_state_to_description(char *state)
00332 {
00333        const struct pdo_sqlstate_info **info;
00334        if (SUCCESS == zend_hash_find(&err_hash, state, sizeof(err_initializer[0].state),
00335                      (void**)&info)) {
00336               return (*info)->desc;
00337        }
00338        return NULL;
00339 }
00340