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

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.h"
  14. using namespace std;
  15. #define SQL_MAXIMUM_MESSAGE_LENGTH 200
  16. SQLHDBC     hdbc;
  17. SQLHSTMT    hstmt;
  18. SQLHENV     henv;
  19. SQLHDESC    hdesc;
  20. SQLRETURN   retcode, SQLSTATEs;
  21. SQLCHAR Sqlstate[5];
  22. SQLINTEGER    NativeError;
  23. SQLSMALLINT   i, MsgLen;
  24. long        strangehandle;
  25. void handle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
  26. void handle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle);
  27. void handle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle);
  28. void handle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle);
  29. //void handle_deal_with_int(SQLSMALLINT HandleType, long InputHandle);
  30.         
  31. void DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle);
  32. void DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle);
  33. void DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle);
  34. void DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle);
  35. //void DisplayError_int(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, int InputHandle);
  36. int SQLAllocHandleTest()
  37. {
  38. strangehandle = 6;
  39. /*Allocate environment handle */
  40. //retcode = SQLFreeHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE);
  41. /* ENV */ 
  42. ndbout << endl;
  43. ndbout << "The HandleType: Allocate Environment handle" << endl;
  44. ndbout << endl;
  45. handle_deal_with_HENV(SQL_HANDLE_ENV, SQL_NULL_HANDLE);
  46.           
  47. handle_deal_with_HENV(SQL_HANDLE_ENV, henv);
  48.       
  49. handle_deal_with_HDBC(SQL_HANDLE_ENV, hdbc);
  50.  
  51. handle_deal_with_HSTMT(SQL_HANDLE_ENV, hstmt);
  52.             
  53. handle_deal_with_HDESC(SQL_HANDLE_ENV, hdesc);
  54.      
  55. //handle_deal_with_int(SQL_HANDLE_ENV, strangehandle);
  56.         
  57. /* DBC */
  58. ndbout << endl;
  59. ndbout << "The HandleType: Allocate Connection handle" << endl;
  60. ndbout << endl;
  61. handle_deal_with_HDBC(SQL_HANDLE_DBC, SQL_NULL_HANDLE);
  62.           
  63. handle_deal_with_HENV(SQL_HANDLE_DBC, henv);
  64.                            
  65. handle_deal_with_HDBC(SQL_HANDLE_DBC, hdbc);
  66. handle_deal_with_HSTMT(SQL_HANDLE_DBC, hstmt);
  67.            
  68. handle_deal_with_HDESC(SQL_HANDLE_DBC, hdesc);
  69.      
  70. //handle_deal_with_int(SQL_HANDLE_DBC, strangehandle);
  71.          
  72. /* STMT */
  73. ndbout << endl;
  74. ndbout << "The HandleType: Allocate Statement handle" << endl;
  75. ndbout << endl;
  76. handle_deal_with_HSTMT(SQL_HANDLE_STMT, SQL_NULL_HANDLE);
  77.           
  78. handle_deal_with_HENV(SQL_HANDLE_STMT, henv);
  79.                            
  80. handle_deal_with_HDBC(SQL_HANDLE_STMT, hdbc);
  81. handle_deal_with_HSTMT(SQL_HANDLE_STMT, hstmt);
  82.            
  83. handle_deal_with_HDESC(SQL_HANDLE_STMT, hdesc);
  84.      
  85. //handle_deal_with_int(SQL_HANDLE_STMT, strangehandle);
  86.         
  87. /* DESC */
  88. ndbout << endl;
  89. ndbout << "The HandType: Allocate Descriptor handle" << endl;
  90. ndbout << endl;
  91. handle_deal_with_HDESC(SQL_HANDLE_DESC, SQL_NULL_HANDLE);
  92.           
  93. handle_deal_with_HENV(SQL_HANDLE_DESC, henv);
  94.                          
  95. handle_deal_with_HDBC(SQL_HANDLE_DESC, hdbc);
  96. handle_deal_with_HSTMT(SQL_HANDLE_DESC, hstmt);
  97.            
  98. handle_deal_with_HDESC(SQL_HANDLE_DESC, hdesc);
  99.  
  100. //handle_deal_with_int(SQL_HANDLE_DESC, strangehandle);
  101.     
  102.                               
  103. /* strangehandle */
  104. ndbout << endl;
  105. ndbout << "The HandType: strangehandle" << endl;
  106. ndbout << endl;
  107. //handle_deal_with_int(strangehandle, SQL_NULL_HANDLE);
  108. handle_deal_with_HENV(strangehandle, henv);
  109.                            
  110. handle_deal_with_HDBC(strangehandle, hdbc);
  111. handle_deal_with_HSTMT(strangehandle, hstmt);
  112.            
  113. handle_deal_with_HDESC(strangehandle, hdesc);
  114.      
  115. // handle_deal_with_int(strangehandle, strangehandle);
  116. return 0;
  117. }        
  118. void handle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle) 
  119. {
  120.      SQLCHAR     Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
  121.      retcode = SQLAllocHandle(HandleType, InputHandle, &hdbc);
  122.      ndbout << "the HandleType is : " << HandleType << endl;
  123.  
  124.      ndbout << "the InputHandle is SQLHDBC:" << InputHandle << endl;
  125.      ndbout << "return &hdbc: " << (long)&hdbc << endl;
  126.      ndbout << "the retcode state is:" << retcode << endl;
  127.      ndbout << endl;
  128.      /*
  129.      if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
  130.      i = 1;
  131.      while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i, 
  132.              Sqlstate, &NativeError, Msg, sizeof(Msg), 
  133.              &MsgLen)) != SQL_NO_DATA)                   {
  134.      DisplayError_HDBC(Sqlstate, HandleType, InputHandle);
  135.      i ++;
  136.                                                          }
  137.                                                                    }
  138.     */
  139.  }
  140. void handle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle) 
  141. {
  142.      SQLCHAR     Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
  143.      retcode = SQLAllocHandle(HandleType, InputHandle, &hstmt);
  144.      ndbout << "the HandleType is : " << HandleType << endl;
  145.       
  146.      ndbout << "the InputHandle is SQLHSTMT:" << InputHandle << endl;
  147.      ndbout << "return &hstmt: " << (long)&hstmt << endl;
  148.      ndbout << "the output retcode is:" << retcode << endl;
  149.      ndbout << endl;
  150.      /*
  151.      if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
  152.      i = 1;
  153.      while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i, 
  154.              Sqlstate, &NativeError, Msg, sizeof(Msg), 
  155.              &MsgLen)) != SQL_NO_DATA)                   {
  156.      DisplayError_HSTMT(Sqlstate, HandleType, InputHandle);
  157.      i ++;
  158.                                                          }
  159.                                                                    }
  160.      */
  161.  }
  162. void handle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle) 
  163. {
  164.      SQLCHAR     Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
  165.      retcode = SQLAllocHandle(HandleType, InputHandle, &henv);
  166.      ndbout << "the HandleType is : " << HandleType << endl;
  167.      ndbout << "the InputHandle is SQLHENV:" << InputHandle << endl;
  168.      ndbout << "return &henv: " << (long)&henv << endl;
  169.      ndbout << "the output retcode is:" << retcode << endl;
  170.      ndbout << endl;
  171.      /*
  172.      if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
  173.      i = 1;
  174.      while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i, 
  175.              Sqlstate, &NativeError, Msg, sizeof(Msg), 
  176.              &MsgLen)) != SQL_NO_DATA)                   {
  177.      DisplayError_HENV(Sqlstate, HandleType, InputHandle);
  178.      i ++;
  179.                                                          }
  180.                                                                    }
  181.      */
  182.  }
  183. void handle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle) 
  184. {
  185.      SQLCHAR     Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
  186.      retcode = SQLAllocHandle(HandleType, InputHandle, &hdesc);
  187.      
  188.      ndbout << "the HandleType is : " << HandleType << endl;
  189.      ndbout << "the InputHandle is SQLHDESC:" << InputHandle << endl;
  190.      ndbout << "return &hdesc: " << (long)&hdesc << endl;
  191.      ndbout << "the output retcode is:" << retcode << endl;  
  192.      ndbout << endl;
  193.      /*
  194.      if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
  195.      i = 1;
  196.      while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i, 
  197.              Sqlstate, &NativeError, Msg, sizeof(Msg), 
  198.              &MsgLen)) != SQL_NO_DATA)                   {
  199.      DisplayError_HDESC(Sqlstate, HandleType, InputHandle);
  200.      i ++;
  201.                                                          }
  202.                                                                    }
  203.      */
  204.  }
  205. //void handle_deal_with_int(SQLSMALLINT HandleType, long InputHandle) 
  206. //{
  207. //     SQLCHAR     Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
  208. //     retcode = SQLAllocHandle(HandleType, InputHandle, &InputHandle); 
  209. //
  210. //     ndbout << "the HandleType is: " << HandleType << endl;
  211. //
  212. //     ndbout << "the InputHandle is stranghandle:" << InputHandle << endl;
  213. //
  214. //     ndbout << "return &InputHandle: " << (long)&InputHandle << endl;
  215. //     ndbout << "the output retcode is:" << retcode << endl;  
  216. //     ndbout << endl; 
  217. //     /*
  218. //     if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
  219. //     i = 1;
  220. //     while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i, 
  221. //             Sqlstate, &NativeError, Msg, sizeof(Msg), 
  222. //             &MsgLen)) != SQL_NO_DATA)                   {
  223. //
  224. //     DisplayError_int(Sqlstate, HandleType, InputHandle);
  225. //
  226. //     i ++;
  227. //                                                         }
  228. //                                                                   }
  229. //     */
  230. // }
  231. void DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle)
  232. {
  233.      ndbout << "the HandleType is:" << HandleType << endl;
  234.      ndbout << "the InputHandle is :" << InputHandle << endl;
  235.      ndbout << "the output state is:" << (char *)Sqlstate << endl;  
  236. }
  237. void DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle)
  238. {
  239.      ndbout << "the HandleType is:" << HandleType << endl;
  240.      ndbout << "the InputHandle is :" << InputHandle << endl;
  241.      ndbout << "the output state is:" << (char *)Sqlstate << endl;
  242. }
  243. void DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle)
  244. {
  245.      ndbout << "the HandleType is:" << HandleType << endl;
  246.      ndbout << "the InputHandle is :" << InputHandle << endl;
  247.      ndbout << "the output state is:" << (char *)Sqlstate << endl;
  248. }
  249. void DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle)
  250. {
  251.      ndbout << "the HandleType is:" << HandleType << endl;
  252.      ndbout << "the InputHandle is :" << InputHandle << endl;
  253.      ndbout << "the output state is:" << (char *)Sqlstate << endl;
  254. }
  255. //void DisplayError_int(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, int InputHandle)
  256. //{
  257. //     ndbout << "the HandleType is:" << HandleType << endl;
  258. //     ndbout << "the InputHandle is :" << InputHandle << endl;
  259. //     ndbout << "the output state is:" << (char *)Sqlstate << endl;
  260. //}