1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/* Copyright (c) 2003, 2005 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
/**
* @file SQLExecuteTest.cpp
*/
#include <common.hpp>
#define ESQL_MAXIMUM_MESSAGE_LENGTH 200
using namespace std;
SQLHDBC Ehdbc;
SQLHSTMT Ehstmt;
SQLHENV Ehenv;
SQLHDESC Ehdesc;
void Execute_DisplayError(SQLSMALLINT EHandleType,
SQLHSTMT EInputHandle);
/**
* Test to execute a SQL statement in a data result set
*
* Tests:
* -# Test1 There is no executed statement
* @return Zero, if test succeeded
*/
int SQLExecuteTest()
{
SQLRETURN retcode;
/* hstmt */
retcode = SQLExecute(Ehstmt);
if (retcode == SQL_INVALID_HANDLE)
ndbout << "Handle Type is SQL_HANDLE_STMT, but SQL_INVALID_HANDLE" << endl;
ndbout << "still appeared. Please check programm" << endl;
if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
Execute_DisplayError(SQL_HANDLE_STMT, Ehstmt);
/* henv */
retcode = SQLExecute(Ehenv);
if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
ndbout << "Handle Type is SQL_HANDLE_ENV, but SQL_SUCCESS_WITH_INFO"
<< "still appeared. Please check programm" << endl;
// Execute_DisplayError(SQL_HANDLE_ENV, Ehenv);
/* hdbc */
retcode = SQLExecute(Ehdbc);
if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
ndbout << "Handle Type is SQL_HANDLE_DBC, but SQL_SUCCESS_WITH_INFO"
<<"still appeared. Please check programm" << endl;
// Execute_DisplayError(SQL_HANDLE_DBC, Ehdbc);
/* hdesc */
retcode = SQLExecute(Ehdesc);
if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
ndbout << "Handle Type is SQL_HANDLE_DESC, but SQL_SUCCESS_WITH_INFO"
<< "still appeared. Please check programm" << endl;
// Execute_DisplayError(SQL_HANDLE_DESC, Ehdesc);
return NDBT_OK;
}
void Execute_DisplayError(SQLSMALLINT EHandleType,
SQLHSTMT EInputHandle)
{
SQLCHAR Sqlstate[5];
SQLINTEGER NativeError;
SQLSMALLINT i, MsgLen;
SQLCHAR Msg[ESQL_MAXIMUM_MESSAGE_LENGTH];
SQLRETURN SQLSTATEs;
i = 1;
ndbout << "-------------------------------------------------" << endl;
ndbout << "Error diagnostics:" << endl;
while ((SQLSTATEs = SQLGetDiagRec(EHandleType,
EInputHandle,
i,
Sqlstate,
&NativeError,
Msg,
sizeof(Msg),
&MsgLen))
!= SQL_NO_DATA)
{
ndbout << "the HandleType is:" << EHandleType << endl;
ndbout << "the InputHandle is :" << EInputHandle << endl;
ndbout << "the Msg is :" << (char *)Msg << endl;
ndbout << "the output state is:" << (char *)Sqlstate << endl;
i ++;
break;
}
ndbout << "-------------------------------------------------" << endl;
}
|