1
/* Copyright (C) 2003 MySQL AB
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
17
* @file SQLGetDiagRecSimpleTest.cpp
28
SQLRETURN GDS_retcode, GDS_RETURN;
30
#define GDS_SQL_MAXIMUM_MESSAGE_LENGTH 255
31
SQLCHAR GDS_Sqlstate[5];
33
SQLINTEGER GDS_NativeError;
34
SQLSMALLINT GDS_i = 1, GDS_MsgLen;
35
SQLCHAR GDS_Msg[GDS_SQL_MAXIMUM_MESSAGE_LENGTH], GDS_ConnectIn[30];
38
* Test SQLGetDiagRec return value
40
* -#Simply test Msg when return is SQL_NO_DATA
41
* -#Simply test Msg when return is SQL_SUCCESS
42
* -#Simply test Msg when return is SQL_SUCCESS_WITH_INFO
43
* -#Simply test Msg when return is SQL_INVALID_HANDLE
44
* -#Simply test Msg when return is SQL_ERROR
46
* @return Zero, if test succeeded
49
int SQLGetDiagRecSimpleTest()
51
ndbout << endl << "Start SQLGetDiagRec Simple Testing" << endl;
53
//************************************
54
//** Allocate An Environment Handle **
55
//************************************
57
GDS_retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &GDS_henv);
58
if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
59
ndbout << "Allocated An Environment Handle!" << endl;
61
//*********************************************
62
//** Set the ODBC application Version to 3.x **
63
//*********************************************
65
GDS_retcode = SQLSetEnvAttr(GDS_henv,
66
SQL_ATTR_ODBC_VERSION,
67
(SQLPOINTER) SQL_OV_ODBC3,
70
if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
71
ndbout << "Set the ODBC application Version to 3.x!" << endl;
73
//**********************************
74
//** Allocate A Connection Handle **
75
//**********************************
77
GDS_retcode = SQLAllocHandle(SQL_HANDLE_DBC, GDS_henv, &GDS_hdbc);
79
if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
80
ndbout << "Allocated A Connection Handle!" << endl;
82
// *******************
83
// ** Connect to DB **
84
// *******************
86
GDS_retcode = SQLConnect(GDS_hdbc,
87
(SQLCHAR *) connectString(),
94
if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO){
95
ndbout << "Success connection to DB!" << endl;
96
ndbout << "GDS_retcode = " << GDS_retcode << endl;
97
ndbout << "SQL_SUCCESS = " << SQL_SUCCESS << endl;
98
ndbout << "SQL_SUCCESS_WITH_INFO = " << SQL_SUCCESS_WITH_INFO << endl;}
102
ndbout << "-------------------------------------------------" << endl;
103
ndbout << "Error diagnostics:" << endl;
105
if (GDS_retcode != SQL_SUCCESS || GDS_retcode != SQL_SUCCESS_WITH_INFO){
106
ndbout << "GDS_retcode = " << GDS_retcode << endl;
107
ndbout << "SQL_SUCCESS = " << SQL_SUCCESS << endl;
108
ndbout << "SQL_SUCCESS_WITH_INFO = " << SQL_SUCCESS_WITH_INFO << endl;
110
GDS_RETURN = SQLGetDiagRec(SQL_HANDLE_DBC,
119
if (GDS_RETURN == SQL_NO_DATA){
120
ndbout << "GDS_SQLSTATES = SQL_NO_DATA" << endl;
121
ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
122
ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
123
ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
124
ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
126
else if (GDS_RETURN == SQL_SUCCESS){
127
ndbout << "GDS_SQLSTATES = SQL_SUCCESS" << endl;
128
ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
129
ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
130
ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
131
ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
133
else if (GDS_RETURN == SQL_SUCCESS_WITH_INFO){
134
ndbout << "GDS_SQLSTATES = SQL_SUCCESS_WITH_INFO" << endl;
135
ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
136
ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
137
ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
138
ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
140
else if (GDS_RETURN == SQL_INVALID_HANDLE){
141
ndbout << "GDS_SQLSTATES = SQL_INVALID_HANDLE" << endl;
142
ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
143
ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
144
ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
145
ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
148
ndbout << "GDS_RETURN = SQL_ERROR" << endl;
149
ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
150
ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
151
ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
152
ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;
155
ndbout << "-------------------------------------------------" << endl;
160
SQLDisconnect(GDS_hdbc);
161
SQLFreeHandle(SQL_HANDLE_STMT, GDS_hstmt);
162
SQLFreeHandle(SQL_HANDLE_DBC, GDS_hdbc);
163
SQLFreeHandle(SQL_HANDLE_ENV, GDS_henv);