===== extra/perror.c 1.52 vs edited ===== --- 1.52/extra/perror.c 2007-06-17 11:20:16 -04:00 +++ edited/extra/perror.c 2007-10-25 07:47:04 -04:00 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2001 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ #include "../storage/ndb/include/mgmapi/mgmapi_error.h" #endif -static my_bool verbose, print_all_codes; +static my_bool verbose, print_all_codes, print_nonnegative_codes_as_cpp_defines; #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE static my_bool ndb_code; @@ -64,6 +64,11 @@ (uchar**) &print_all_codes, (uchar**) &print_all_codes, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif + {"cpp", 'c', "Print error definitions.", + (gptr*) &print_nonnegative_codes_as_cpp_defines, + (gptr*) &print_nonnegative_codes_as_cpp_defines, + 0, GET_BOOL, NO_ARG, + 0, 0, 0, 0, 0, 0}, {"silent", 's', "Only print the error message.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"verbose", 'v', "Print error code and message (default).", (uchar**) &verbose, @@ -73,58 +78,75 @@ {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; - -typedef struct ha_errors { +/* Error codes given by functions */ +struct ha_errors { + const char * const define_name; int errcode; - const char *msg; -} HA_ERRORS; - + const char * const msg; +}; -static HA_ERRORS ha_errlist[]= -{ - { 120,"Didn't find key on read or update" }, - { 121,"Duplicate key on write or update" }, - { 123,"Someone has changed the row since it was read (while the table was locked to prevent it)" }, - { 124,"Wrong index given to function" }, - { 126,"Index file is crashed" }, - { 127,"Record-file is crashed" }, - { 128,"Out of memory" }, - { 130,"Incorrect file format" }, - { 131,"Command not supported by database" }, - { 132,"Old database file" }, - { 133,"No record read before update" }, - { 134,"Record was already deleted (or record file crashed)" }, - { 135,"No more room in record file" }, - { 136,"No more room in index file" }, - { 137,"No more records (read after end of file)" }, - { 138,"Unsupported extension used for table" }, - { 139,"Too big row"}, - { 140,"Wrong create options"}, - { 141,"Duplicate unique key or constraint on write or update"}, - { 142,"Unknown character set used"}, - { 143,"Conflicting table definitions in sub-tables of MERGE table"}, - { 144,"Table is crashed and last repair failed"}, - { 145,"Table was marked as crashed and should be repaired"}, - { 146,"Lock timed out; Retry transaction"}, - { 147,"Lock table is full; Restart program with a larger locktable"}, - { 148,"Updates are not allowed under a read only transactions"}, - { 149,"Lock deadlock; Retry transaction"}, - { 150,"Foreign key constraint is incorrectly formed"}, - { 151,"Cannot add a child row"}, - { 152,"Cannot delete a parent row"}, - { -30999, "DB_INCOMPLETE: Sync didn't finish"}, - { -30998, "DB_KEYEMPTY: Key/data deleted or never created"}, - { -30997, "DB_KEYEXIST: The key/data pair already exists"}, - { -30996, "DB_LOCK_DEADLOCK: Deadlock"}, - { -30995, "DB_LOCK_NOTGRANTED: Lock unavailable"}, - { -30994, "DB_NOSERVER: Server panic return"}, - { -30993, "DB_NOSERVER_HOME: Bad home sent to server"}, - { -30992, "DB_NOSERVER_ID: Bad ID sent to server"}, - { -30991, "DB_NOTFOUND: Key/data pair not found (EOF)"}, - { -30990, "DB_OLD_VERSION: Out-of-date version"}, - { -30989, "DB_RUNRECOVERY: Panic return"}, - { -30988, "DB_VERIFY_BAD: Verify failed; bad format"}, - { 0,NullS }, +static struct ha_errors ha_errlist[] = { + { "", -30999, "DB_INCOMPLETE: Sync didn't finish" }, + { "", -30998, "DB_KEYEMPTY: Key/data deleted or never created" }, + { "", -30997, "DB_KEYEXIST: The key/data pair already exists" }, + { "", -30996, "DB_LOCK_DEADLOCK: Deadlock" }, + { "", -30995, "DB_LOCK_NOTGRANTED: Lock unavailable" }, + { "", -30994, "DB_NOSERVER: Server panic return" }, + { "", -30993, "DB_NOSERVER_HOME: Bad home sent to server" }, + { "", -30992, "DB_NOSERVER_ID: Bad ID sent to server" }, + { "", -30991, "DB_NOTFOUND: Key/data pair not found (EOF)" }, + { "", -30990, "DB_OLD_VERSION: Out-of-date version" }, + { "", -30989, "DB_RUNRECOVERY: Panic return" }, + { "", -30988, "DB_VERIFY_BAD: Verify failed; bad format" }, + { "HA_ERR_KEY_NOT_FOUND", 120, "Didn't find key on read or update" }, + { "HA_ERR_FOUND_DUPP_KEY", 121, "Duplicate key on write or update" }, + { "HA_ERR_RECORD_CHANGED", 123, "Someone has changed the row since it was read (while the table was locked to prevent such)" }, + { "HA_ERR_WRONG_INDEX", 124, "Wrong index given to function" }, + { "HA_ERR_CRASHED", 126, "Indexfile is crashed" }, + { "HA_ERR_WRONG_IN_RECORD", 127, "Record-file is crashed" }, + { "HA_ERR_OUT_OF_MEM", 128, "Out of memory" }, + { "HA_ERR_NOT_A_TABLE", 130, "Incorrect file format" }, + { "HA_ERR_WRONG_COMMAND", 131, "Command not supported" }, + { "HA_ERR_OLD_FILE", 132, "Old database file" }, + { "HA_ERR_NO_ACTIVE_RECORD", 133, "No record read before update" }, + { "HA_ERR_RECORD_DELETED", 134, "Record was already deleted (or record file crashed)" }, + { "HA_ERR_RECORD_FILE_FULL", 135, "No more room in record file" }, + { "HA_ERR_INDEX_FILE_FULL", 136, "No more room in index file" }, + { "HA_ERR_END_OF_FILE", 137, "No more records (read after end of file)" }, + { "HA_ERR_UNSUPPORTED", 138, "Unsupported extension used for table" }, + { "HA_ERR_TO_BIG_ROW", 139, "Too big row" }, + { "HA_WRONG_CREATE_OPTION", 140, "Wrong create option" }, + { "HA_ERR_FOUND_DUPP_UNIQUE", 141, "Duplicate unique key or constraint on write or update" }, + { "HA_ERR_UNKNOWN_CHARSET", 142, "Unknown character-set used" }, + { "HA_ERR_WRONG_MRG_TABLE_DEF", 143, "conflicting table definitions in sub-tables of Merge table" }, + { "HA_ERR_CRASHED_ON_REPAIR", 144, "Table is marked as crashed and the last repair failed" }, + { "HA_ERR_CRASHED_ON_USAGE", 145, "Table is marked as crashed and should be repaired" }, + { "HA_ERR_LOCK_WAIT_TIMEOUT", 146, "Lock timed out; retry transaction" }, + { "HA_ERR_LOCK_TABLE_FULL", 147, "Lock table is full; restart program with a larger lock table" }, + { "HA_ERR_READ_ONLY_TRANSACTION", 148, "Updates not allowed under read-only transactions" }, + { "HA_ERR_LOCK_DEADLOCK", 149, "Lock deadlock; retry transaction" }, + { "HA_ERR_CANNOT_ADD_FOREIGN", 150, "Foreign key constraint is incorrectly formed" }, + { "HA_ERR_NO_REFERENCED_ROW", 151, "Cannot add a child row" }, + { "HA_ERR_ROW_IS_REFERENCED", 152, "Cannot delete a parent row" }, + { "HA_ERR_NO_SAVEPOINT", 153, "No savepoint with that name" }, + { "HA_ERR_NON_UNIQUE_BLOCK_SIZE", 154, "Non unique key block size" }, + { "HA_ERR_NO_SUCH_TABLE", 155, "The table does not exist in engine" }, + { "HA_ERR_TABLE_EXIST", 156, "The table existed in storage engine" }, + { "HA_ERR_NO_CONNECTION", 157, "Could not connect to storage engine" }, + { "HA_ERR_NULL_IN_SPATIAL", 158, "NULLs are not supported in spatial index" }, + { "HA_ERR_TABLE_DEF_CHANGED", 159, "The table changed in storage engine" }, + { "HA_ERR_NO_PARTITION_FOUND", 160, "There's no partition in table for given value" }, + { "HA_ERR_RBR_LOGGING_FAILED", 161, "Row-based binlogging of row failed" }, + { "HA_ERR_DROP_INDEX_FK", 162, "Index needed in foreign key constr" }, + { "HA_ERR_FOREIGN_DUPLICATE_KEY", 163, "Upholding foreign key constraints would lead to a duplicate key error in some other table" }, + { "HA_ERR_TABLE_NEEDS_UPGRADE", 164, "The table changed in storage engine" }, + { "HA_ERR_TABLE_READONLY", 165, "The table is not writable" }, + { "HA_ERR_AUTOINC_READ_FAILED", 166, "Failed to get next autoinc value" }, + { "HA_ERR_AUTOINC_ERANGE", 167, "Failed to set row autoinc value" }, + { "HA_ERR_GENERIC", 168, "Generic error" }, + { "HA_ERR_RECORD_IS_THE_SAME", 169, "Row not actually updated; new values same as the old values" }, + { "HA_ERR_LOGGING_IMPOSSIBLE", 170, "It is not possible to log this statement" } + { NULL, 0, NullS }, }; @@ -157,7 +179,7 @@ { switch (optid) { case 's': - verbose=0; + verbose= 0; break; case 'V': print_version(); @@ -180,7 +202,7 @@ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) exit(ho_error); - if (!*argc && !print_all_codes) + if (!*argc && !print_all_codes && !print_nonnegative_codes_as_cpp_defines) { usage(); return 1; @@ -191,9 +213,9 @@ static const char *get_ha_error_msg(int code) { - HA_ERRORS *ha_err_ptr; + struct ha_errors *ha_err_ptr; - for (ha_err_ptr=ha_errlist ; ha_err_ptr->errcode ;ha_err_ptr++) + for (ha_err_ptr= ha_errlist ; ha_err_ptr->errcode != 0; ha_err_ptr++) if (ha_err_ptr->errcode == code) return ha_err_ptr->msg; return NullS; @@ -207,26 +229,57 @@ char *unknown_error = 0; MY_INIT(argv[0]); - if (get_options(&argc,&argv)) + if (get_options(&argc, &argv)) exit(1); error=0; #ifdef HAVE_SYS_ERRLIST if (print_all_codes) { - HA_ERRORS *ha_err_ptr; - for (code=1 ; code < sys_nerr ; code++) + struct ha_errors *ha_err_ptr; + for (code= 1; code < sys_nerr; code++) { if (sys_errlist[code][0]) { /* Skip if no error-text */ printf("%3d = %s\n",code,sys_errlist[code]); } } - for (ha_err_ptr=ha_errlist ; ha_err_ptr->errcode ;ha_err_ptr++) + for (ha_err_ptr= ha_errlist; ha_err_ptr->errcode != 0; ha_err_ptr++) printf("%3d = %s\n",ha_err_ptr->errcode,ha_err_ptr->msg); } else #endif + if (print_nonnegative_codes_as_cpp_defines) + { + struct ha_errors *ha_err_ptr= ha_errlist; + int min_positive_code, max_code; + + printf("/* Th" "is fi" "le is ge" "nerated from per" "ror. */\n"); + printf("/* Do n" "ot ed" "it. */\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + printf("#ifndef _generated_perror_headers\n"); + printf("#define _generated_perror_headers\n"); + min_positive_code= max_code= ha_errlist->errcode; + for (ha_err_ptr= ha_errlist; ha_err_ptr->errcode != 0; ha_err_ptr++) + { + if (ha_err_ptr->errcode < 0) + continue; /* skip negative */ + + printf("#define %s %d\n", ha_err_ptr->define_name, ha_err_ptr->errcode); + + if (ha_err_ptr->errcode > max_code) + max_code= ha_err_ptr->errcode; + if ((min_positive_code <= 0) && (ha_err_ptr->errcode > 0)) + min_positive_code= ha_err_ptr->errcode; /* recover from setting min to negative. */ + if (ha_err_ptr->errcode < min_positive_code) + min_positive_code= ha_err_ptr->errcode; + } + + printf("#define %s %d\n", "HA_ERR_FIRST", min_positive_code); + printf("#define %s %d\n", "HA_ERR_LAST", max_code); + printf("#define %s %d\n", "HA_ERR_ERRORS", (max_code - min_positive_code + 1)); + printf("#endif /* _generated_perror_headers */\n"); + } + else { /* On some system, like NETWARE, strerror(unknown_error) returns a