~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
 
15
 
 
16
 /**
 
17
 * @file SQLGetDiagRecSimpleTest.cpp
 
18
 */
 
19
#include <common.hpp>
 
20
#include <string.h>
 
21
 
 
22
using namespace std;
 
23
 
 
24
SQLHDBC     GDS_hdbc;
 
25
SQLHSTMT    GDS_hstmt;
 
26
SQLHENV     GDS_henv;
 
27
SQLHDESC    GDS_hdesc;
 
28
SQLRETURN   GDS_retcode, GDS_RETURN;
 
29
 
 
30
#define GDS_SQL_MAXIMUM_MESSAGE_LENGTH 255
 
31
SQLCHAR GDS_Sqlstate[5];
 
32
 
 
33
SQLINTEGER    GDS_NativeError;
 
34
SQLSMALLINT   GDS_i = 1, GDS_MsgLen;
 
35
SQLCHAR   GDS_Msg[GDS_SQL_MAXIMUM_MESSAGE_LENGTH], GDS_ConnectIn[30];
 
36
 
 
37
/** 
 
38
 * Test SQLGetDiagRec return value
 
39
 *
 
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
 
45
 *
 
46
 * @return Zero, if test succeeded
 
47
 */
 
48
       
 
49
int SQLGetDiagRecSimpleTest()
 
50
{
 
51
     ndbout << endl << "Start SQLGetDiagRec Simple Testing" << endl;
 
52
 
 
53
  //************************************
 
54
  //** Allocate An Environment Handle **
 
55
  //************************************
 
56
 
 
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;
 
60
 
 
61
  //*********************************************
 
62
  //** Set the ODBC application Version to 3.x **
 
63
  //*********************************************
 
64
 
 
65
     GDS_retcode = SQLSetEnvAttr(GDS_henv, 
 
66
                                 SQL_ATTR_ODBC_VERSION, 
 
67
                                 (SQLPOINTER) SQL_OV_ODBC3, 
 
68
                                 SQL_IS_UINTEGER);
 
69
 
 
70
     if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
 
71
     ndbout << "Set the ODBC application Version to 3.x!" << endl;
 
72
 
 
73
  //**********************************
 
74
  //** Allocate A Connection Handle **
 
75
  //**********************************
 
76
 
 
77
     GDS_retcode = SQLAllocHandle(SQL_HANDLE_DBC, GDS_henv, &GDS_hdbc);
 
78
 
 
79
     if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
 
80
         ndbout << "Allocated A Connection Handle!" << endl;
 
81
 
 
82
  // *******************
 
83
  // ** Connect to DB **
 
84
  // *******************
 
85
 
 
86
    GDS_retcode = SQLConnect(GDS_hdbc, 
 
87
                            (SQLCHAR *) connectString(),
 
88
                            SQL_NTS, 
 
89
                            (SQLCHAR *) "", 
 
90
                            SQL_NTS, 
 
91
                            (SQLCHAR *) "", 
 
92
                            SQL_NTS);
 
93
 
 
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;}
 
99
 
 
100
       ndbout << endl;
 
101
 
 
102
     ndbout << "-------------------------------------------------" << endl;
 
103
     ndbout << "Error diagnostics:" << endl;
 
104
 
 
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;
 
109
 
 
110
     GDS_RETURN = SQLGetDiagRec(SQL_HANDLE_DBC, 
 
111
                                GDS_hdbc, 
 
112
                                GDS_i, 
 
113
                                GDS_Sqlstate, 
 
114
                                &GDS_NativeError, 
 
115
                                GDS_Msg, 
 
116
                                sizeof(GDS_Msg), 
 
117
                                &GDS_MsgLen);
 
118
 
 
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;}
 
125
 
 
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;}
 
132
 
 
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;}
 
139
 
 
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;}
 
146
 
 
147
     else{
 
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; 
 
153
     }
 
154
                                                                            }
 
155
  ndbout << "-------------------------------------------------" << endl;
 
156
 
 
157
  //******************
 
158
  //** Free Handles **
 
159
  //******************
 
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);
 
164
  return NDBT_OK;
 
165
 }
 
166