1 /* Copyright (c) 2003, 2005 MySQL AB
2    Use is subject to license terms
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
16 
17 #include <common.h>
18 
19 using namespace std;
20 
21 #define NAME_LEN 50
22 #define PHONE_LEN 10
23 #define SALES_PERSON_LEN 10
24 #define STATUS_LEN 6
25 #define SQL_MAXIMUM_MESSAGE_LENGTH 200
26 
27 SQLHSTMT    hstmt;
28 SQLHDESC    hdesc;
29 
30 SQLSMALLINT RecNumber;
31 SQLCHAR     szSalesPerson[SALES_PERSON_LEN];
32 
33 SQLCHAR     Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
34 SQLINTEGER  NativeError;
35 SQLRETURN   retcode, SQLSTATEs;
36 
37 SQLCHAR     Name;
38 SQLINTEGER  LengthPtr;
39 SQLSMALLINT SGDR_StringLengthPtr, TypePtr, SubTypePtr, PrecisionPtr, ScalePtr, NullablePtr;
40 
41 SQLSMALLINT i, MsgLen;
42 
43 void SQLGetDescRec_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
44 
SQLGetDescRecTest()45 int SQLGetDescRecTest()
46 {
47 
48   /* hstmt */
49   // SQLPrepare a statement to select rows from the ORDERS Table. We can create the table and inside rows in
50   // NDB by another program TestDirectSQL. In this test program(SQLGetDescRecTest),we only have three rows in
51   // table ORDERS
52 
53 /* Prepare the SQL statement with parameter markers. */
54 retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS)", SQL_NTS);
55 
56 /* SELECT OrderID, CustID, OpenDate, SalesPerson from Table ORDERS */
57 
58 if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
59 
60   /* RecoderNumber is less than 1 */
61 retcode = SQLGetDescRec(hdesc, -1, &Name, sizeof(Name), &SGDR_StringLengthPtr, &TypePtr, &SubTypePtr, &LengthPtr, &PrecisionPtr, &ScalePtr, &NullablePtr);
62 if  (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
63    SQLGetDescRec_DisplayError(SQL_HANDLE_DESC, hdesc);
64 
65   /* RecoderNumber is greater than N, N be the value of the COUNT field of D, D be the allocated CLI */
66   /* descriptor area identified by DescriptorHandle */
67 retcode = SQLGetDescRec(hdesc, 4, &Name, sizeof(Name), &SGDR_StringLengthPtr, &TypePtr, &SubTypePtr, &LengthPtr, &PrecisionPtr, &ScalePtr, &NullablePtr);
68 if  (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
69    SQLGetDescRec_DisplayError(SQL_HANDLE_DESC, hdesc);
70 
71 }
72 
73   return 0;
74 
75  }
76 
77 
SQLGetDescRec_DisplayError(SQLSMALLINT HandleType,SQLHDESC InputHandle)78 void SQLGetDescRec_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle)
79 {
80      i = 1;
81      while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
82              Sqlstate, &NativeError, Msg, sizeof(Msg),
83              &MsgLen)) != SQL_NO_DATA)                   {
84 
85      ndbout << "the HandleType is:" << HandleType << endl;
86      ndbout << "the InputHandle is :" << InputHandle << endl;
87      ndbout << "the output state is:" << (char *)Sqlstate << endl;
88 
89      i ++;
90                                                          }
91 
92 }
93 
94 
95 
96