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

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. /**
  14.  * @file SQLColAttributeTest1.cpp
  15.  */
  16. #include <common.hpp>
  17. using namespace std;
  18. #define MAXIMUM_MESSAGE_LENGTH_Test1 200
  19. #define BufferLenghTest1 156
  20. SQLHSTMT    ColAtt_hstmtTest1;
  21. SQLHSTMT    ColAtt_hdbcTest1;
  22. SQLHENV     ColAtt_henvTest1;
  23. SQLHDESC    ColAtt_hdescTest1;
  24. SQLCHAR        CharacterAttributePtrTest1;
  25. SQLINTEGER     NumericAttributePtrTest1;
  26. SQLSMALLINT    StringLengthPtrTest1;
  27. SQLRETURN ColAtt_retTest1;
  28. void ColAtt_DisplayErrorTest1(SQLSMALLINT ColAtt_HandleType, 
  29.       SQLHSTMT ColAtt_InputHandle);
  30. /** 
  31.  * Test returning descriptor information
  32.  *
  33.  * Tests:
  34.  * -# Execute SQLColAttribute without prepared or executed statement
  35.  * 
  36.  * @return Zero, if test succeeded
  37.  */
  38. int SQLColAttributeTest1()
  39. {
  40.   ndbout << endl << "Start SQLColAttribute Testing1" << endl;
  41.   /********************************************************************
  42.    ** Test :                                                         **
  43.    **                                                                **
  44.    ** Checks to execute SQLColAttribute, when there is no            **
  45.    ** prepared or executed statement associated with StatementHandle **
  46.    **                                                                **
  47.    ** Intended result:CLI-specific condition-function sequence error **
  48.    ********************************************************************/
  49.   ColAtt_retTest1 = SQLColAttribute(ColAtt_hstmtTest1, 
  50.     1, 
  51.     SQL_DESC_AUTO_UNIQUE_VALUE, 
  52.     &CharacterAttributePtrTest1, 
  53.     BufferLenghTest1, 
  54.     &StringLengthPtrTest1, 
  55.     &NumericAttributePtrTest1);
  56.   if (ColAtt_retTest1 == SQL_ERROR)
  57.     {
  58.       ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
  59.       ndbout << endl << "There is no prepared or executed" << endl 
  60.      << " statement associated with StatementHandle" << endl;
  61.       ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
  62.     }
  63.   else if (ColAtt_retTest1 == SQL_SUCCESS_WITH_INFO)
  64.     {
  65.       ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
  66.       ndbout << endl << "There is no prepared or executed" << endl 
  67.      << " statement associated with StatementHandle" << endl;
  68.       ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
  69.     }
  70.   else if (ColAtt_retTest1 == SQL_SUCCESS)
  71.     {
  72.       ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
  73.       ndbout << endl << "There is no prepared or executed" << endl 
  74.      << " statement associated with StatementHandle" << endl;
  75.       ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
  76.     }
  77.   else if (ColAtt_retTest1 == -2)
  78.     {
  79.       ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
  80.       ndbout << endl << "There is no prepared or executed" << endl 
  81.      << " statement associated with StatementHandle" << endl;
  82.       ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
  83.     }
  84.   else 
  85.     {
  86.       ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
  87.       ndbout << endl << "There is no prepared or executed" << endl 
  88.      << " statement associated with StatementHandle" << endl;
  89.       ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
  90.     }
  91.   return NDBT_OK;
  92. }
  93. void ColAtt_DisplayErrorTest1(SQLSMALLINT ColAtt_HandleType, 
  94.       SQLHSTMT ColAtt_InputHandle)
  95. {
  96.   SQLSMALLINT ColAtt_i = 1;
  97.   SQLRETURN ColAtt_SQLSTATEs;
  98.   SQLCHAR ColAtt_Sqlstate[5];
  99.   SQLCHAR ColAtt_Msg[MAXIMUM_MESSAGE_LENGTH_Test1];
  100.   SQLSMALLINT ColAtt_MsgLen;
  101.   SQLINTEGER  ColAtt_NativeError;
  102.   ndbout << "-------------------------------------------------" << endl;
  103.   ndbout << "Error diagnostics:" << endl;
  104.   
  105.   while ((ColAtt_SQLSTATEs = SQLGetDiagRec(ColAtt_HandleType, 
  106.    ColAtt_InputHandle, 
  107.    ColAtt_i, 
  108.    ColAtt_Sqlstate, 
  109.    &ColAtt_NativeError, 
  110.    ColAtt_Msg, 
  111.    sizeof(ColAtt_Msg), 
  112.    &ColAtt_MsgLen)) 
  113.  != SQL_NO_DATA)                   
  114.     {
  115.       
  116.       ndbout << "the HandleType is:" << ColAtt_HandleType << endl;
  117.       ndbout << "the InputHandle is :" << (long)ColAtt_InputHandle << endl;
  118.       ndbout << "the ColAtt_Msg is: " << (char *) ColAtt_Msg << endl;
  119.       ndbout << "the output state is:" << (char *)ColAtt_Sqlstate << endl; 
  120.       
  121.       ColAtt_i ++;
  122.       break;
  123.     }
  124.   ndbout << "-------------------------------------------------" << endl;
  125. }