Sqlstate.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include <common/common.hpp>
  14. // Initialize Sqlstate records statically.
  15. // They are not used by other static initializers.
  16. #define make_Sqlstate(state, code) 
  17. const Sqlstate Sqlstate::_##state(#state, code)
  18. make_Sqlstate(00000, SQL_SUCCESS);
  19. make_Sqlstate(01004, SQL_SUCCESS_WITH_INFO);
  20. make_Sqlstate(01S02, SQL_SUCCESS_WITH_INFO);
  21. make_Sqlstate(07009, SQL_ERROR);
  22. make_Sqlstate(08003, SQL_ERROR);
  23. make_Sqlstate(21S01, SQL_ERROR);
  24. make_Sqlstate(22001, SQL_ERROR);
  25. make_Sqlstate(22002, SQL_ERROR);
  26. make_Sqlstate(22003, SQL_ERROR);
  27. make_Sqlstate(22005, SQL_ERROR);
  28. make_Sqlstate(22008, SQL_ERROR);
  29. make_Sqlstate(22012, SQL_ERROR);
  30. make_Sqlstate(24000, SQL_ERROR);
  31. make_Sqlstate(25000, SQL_ERROR);
  32. make_Sqlstate(42000, SQL_ERROR);
  33. make_Sqlstate(42S02, SQL_ERROR);
  34. make_Sqlstate(42S22, SQL_ERROR);
  35. make_Sqlstate(HY004, SQL_ERROR);
  36. make_Sqlstate(HY009, SQL_ERROR);
  37. make_Sqlstate(HY010, SQL_ERROR);
  38. make_Sqlstate(HY011, SQL_ERROR);
  39. make_Sqlstate(HY012, SQL_ERROR);
  40. make_Sqlstate(HY014, SQL_ERROR);
  41. make_Sqlstate(HY019, SQL_ERROR);
  42. make_Sqlstate(HY024, SQL_ERROR);
  43. make_Sqlstate(HY090, SQL_ERROR);
  44. make_Sqlstate(HY091, SQL_ERROR);
  45. make_Sqlstate(HY092, SQL_ERROR);
  46. make_Sqlstate(HY095, SQL_ERROR);
  47. make_Sqlstate(HY096, SQL_ERROR);
  48. make_Sqlstate(HYC00, SQL_ERROR);
  49. make_Sqlstate(HYT00, SQL_ERROR);
  50. make_Sqlstate(IM000, SQL_ERROR); // consider all to be errors for now
  51. make_Sqlstate(IM001, SQL_ERROR);
  52. make_Sqlstate(IM999, SQL_ERROR);
  53. SQLRETURN
  54. Sqlstate::getCode(SQLRETURN code) const
  55. {
  56.     int codes[2];
  57.     int ranks[2];
  58.     codes[0] = code;
  59.     codes[1] = m_code;
  60.     for (int i = 0; i < 2; i++) {
  61. switch (codes[i]) {
  62. case SQL_SUCCESS:
  63.     ranks[i] = 0;
  64.     break;
  65. case SQL_SUCCESS_WITH_INFO:
  66.     ranks[i] = 1;
  67.     break;
  68. case SQL_NO_DATA:
  69.     ranks[i] = 2;
  70.     break;
  71. case SQL_NEED_DATA:
  72.     ranks[i] = 3;
  73.     break;
  74. case SQL_ERROR:
  75.     ranks[i] = 9;
  76.     break;
  77. default:
  78.     ctx_assert(false);
  79.     ranks[i] = 9;
  80. }
  81.     }
  82.     if (ranks[0] < ranks[1])
  83. code = m_code;
  84.     return code;
  85. }