~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to storage/ndb/test/odbc/client/SQLGetInfoTest.cpp

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
 /**
 
17
 * @file SQLGetInfoTest.cpp
 
18
 */
 
19
 
 
20
#include <common.hpp>
 
21
 
 
22
using namespace std;
 
23
 
 
24
SQLHDBC     GI_hdbc;
 
25
SQLHSTMT    GI_hstmt;
 
26
SQLHENV     GI_henv;
 
27
 
 
28
#define GI_MESSAGE_LENGTH 200
 
29
 
 
30
SQLCHAR   Msg[GI_MESSAGE_LENGTH];
 
31
       
 
32
void SQLGetInfoTest_DisplayError(SQLSMALLINT GI_HandleType, 
 
33
                                 SQLHDBC GI_InputHandle);
 
34
 
 
35
/** 
 
36
 * Test to retrieve general information about the driver and
 
37
 * the data source an application is currently connected to.
 
38
 *
 
39
 * Tests:
 
40
 * -# Test The value of FunctionId is not in table 27
 
41
 * @return Zero, if test succeeded
 
42
 */
 
43
 
 
44
int SQLGetInfoTest()
 
45
{
 
46
  SQLRETURN retcode;
 
47
  SQLINTEGER    InfoValuePtr;
 
48
  SQLSMALLINT   SLPStringLengthPtr;
 
49
 
 
50
  ndbout << endl << "Start SQLGetInfo Testing" << endl;
 
51
 
 
52
  //******************************************************
 
53
  //** The value of FunctionId is not in Table 27, then **
 
54
  //** an exception condition is raised                 **
 
55
  //******************************************************
 
56
 
 
57
  //************************************
 
58
  //** Allocate An Environment Handle **
 
59
  //************************************
 
60
  retcode = SQLAllocHandle(SQL_HANDLE_ENV, 
 
61
                           SQL_NULL_HANDLE, 
 
62
                           &GI_henv);
 
63
  
 
64
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
 
65
    ndbout << "Allocated an environment Handle!" << endl;
 
66
  
 
67
  //*********************************************
 
68
  //** Set the ODBC application Version to 3.x **
 
69
  //*********************************************
 
70
  retcode = SQLSetEnvAttr(GI_henv, 
 
71
                          SQL_ATTR_ODBC_VERSION, 
 
72
                          (SQLPOINTER) SQL_OV_ODBC3, 
 
73
                          SQL_IS_UINTEGER);
 
74
  
 
75
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
 
76
    ndbout << "Set the ODBC application Version to 3.x!" << endl;
 
77
 
 
78
  //**********************************
 
79
  //** Allocate A Connection Handle **
 
80
  //**********************************
 
81
 
 
82
  retcode = SQLAllocHandle(SQL_HANDLE_DBC, 
 
83
                           GI_henv, 
 
84
                           &GI_hdbc);
 
85
 
 
86
  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
 
87
    ndbout << "Allocated a connection Handle!" << endl;
 
88
  
 
89
  // *******************
 
90
  // ** Connect to DB **
 
91
  // *******************
 
92
  retcode = SQLConnect(GI_hdbc, 
 
93
                       (SQLCHAR *) connectString(), 
 
94
                       SQL_NTS, 
 
95
                       (SQLCHAR *) "", 
 
96
                       SQL_NTS, 
 
97
                       (SQLCHAR *) "", 
 
98
                       SQL_NTS);
 
99
  
 
100
 
 
101
  // **********************
 
102
  // ** GET INFO FROM DB **
 
103
  // *********************
 
104
 
 
105
  retcode = SQLGetInfo(GI_hdbc, 
 
106
                       SQL_DATABASE_NAME, 
 
107
                       &InfoValuePtr, 
 
108
                       sizeof(InfoValuePtr), 
 
109
                       &SLPStringLengthPtr);
 
110
 
 
111
  if (retcode == SQL_SUCCESS)
 
112
    ndbout << endl << "Database Name:" << InfoValuePtr << endl;
 
113
  else
 
114
    {
 
115
      ndbout << endl << "retcode = SQLGetInfo() = " << retcode <<endl;
 
116
      SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
 
117
    }
 
118
 
 
119
  retcode = SQLGetInfo(GI_hdbc, 
 
120
                       SQL_DRIVER_NAME, 
 
121
                       &InfoValuePtr, 
 
122
                       sizeof(InfoValuePtr), 
 
123
                       &SLPStringLengthPtr);
 
124
 
 
125
  if (retcode == SQL_SUCCESS)
 
126
    ndbout << endl << "Driver Name:" << InfoValuePtr << endl;
 
127
  else
 
128
    {
 
129
      ndbout << endl << "retcode = SQLGetInfo() = " << retcode <<endl;
 
130
      SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
 
131
    }
 
132
 
 
133
  // **************************
 
134
  // ** INPUT WRONG InfoType **
 
135
  // **************************
 
136
  retcode = SQLGetInfo(GI_hdbc, 
 
137
                       8888, 
 
138
                       &InfoValuePtr, 
 
139
                       sizeof(InfoValuePtr), 
 
140
                       &SLPStringLengthPtr);
 
141
 if (retcode == -2)
 
142
   {
 
143
     ndbout << endl <<"retcode = " << retcode << endl;
 
144
     ndbout << "System reported -2. Please check your test programme" 
 
145
            << " about the connectionhandle." << endl;
 
146
     SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
 
147
   }
 
148
  else if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
 
149
    {
 
150
      ndbout << endl << "retcode = " << retcode << endl;
 
151
      ndbout << "The information of InfoType is not in Table 28," 
 
152
             << " but SQLGetInfo() executeed succeddfully." 
 
153
             << " Check the function!" <<endl;
 
154
      SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
 
155
    }
 
156
 else if (retcode == SQL_ERROR)
 
157
    {
 
158
      ndbout << endl << "retcode = " << retcode << endl;
 
159
      ndbout << "Input a wrong InfoType. The system found the" 
 
160
             << " information of InfoType is not in Table 28." 
 
161
             << " Test successful!" << endl;
 
162
    }
 
163
  else 
 
164
    ndbout << endl;
 
165
  // *********************************
 
166
  // ** Disconnect and Free Handles **
 
167
  // *********************************  
 
168
  SQLDisconnect(GI_hdbc);
 
169
  SQLFreeHandle(SQL_HANDLE_STMT, GI_hstmt);
 
170
  SQLFreeHandle(SQL_HANDLE_DBC, GI_hdbc);
 
171
  SQLFreeHandle(SQL_HANDLE_ENV, GI_henv);
 
172
 
 
173
  return NDBT_OK;
 
174
 
 
175
 }
 
176
 
 
177
 
 
178
void SQLGetInfoTest_DisplayError(SQLSMALLINT GI_HandleType, 
 
179
                                 SQLHDBC GI_InputHandle)
 
180
{
 
181
  SQLRETURN   SQLSTATEs;
 
182
  SQLINTEGER    NativeError;
 
183
  SQLCHAR Sqlstate[50];
 
184
  SQLSMALLINT   i, MsgLen;
 
185
  i = 1;
 
186
  
 
187
  ndbout << "-------------------------------------------------" << endl;
 
188
  ndbout << "Error diagnostics:" << endl;
 
189
  
 
190
 
 
191
  while ((SQLSTATEs = SQLGetDiagRec(GI_HandleType, 
 
192
                                    GI_InputHandle, 
 
193
                                    i, 
 
194
                                    Sqlstate, 
 
195
                                    &NativeError, 
 
196
                                    Msg, 
 
197
                                    sizeof(Msg), 
 
198
                                    &MsgLen)) 
 
199
         != SQL_NO_DATA)                   
 
200
{
 
201
 
 
202
     ndbout << "the GI_HandleType is:" << GI_HandleType << endl;
 
203
     ndbout << "the GI_InputHandle is :" << (long)GI_InputHandle << endl;
 
204
     ndbout << "the Msg is :" << (char *) Msg << endl;
 
205
     ndbout << "the output state is:" << (char *)Sqlstate << endl; 
 
206
 
 
207
     i ++;
 
208
     break;
 
209
                                                         }
 
210
  ndbout << "-------------------------------------------------" << endl;
 
211
}
 
212
 
 
213
 
 
214