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 <NdbOut.hpp>
18 #include <sqlext.h>
19 #include <stdio.h>
20 
21 using namespace std;
22 
23 #define NAME_LEN 50
24 #define PHONE_LEN 10
25 #define SALES_PERSON_LEN 10
26 #define STATUS_LEN 6
27 #define SQL_MAXIMUM_MESSAGE_LENGTH 200
28 
29 SQLHSTMT    hstmt;
30 SQLHDESC    hdesc;
31 
32 SQLSMALLINT RecNumber;
33 SQLCHAR     szSalesPerson[SALES_PERSON_LEN];
34 
35 SQLCHAR     Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
36 SQLINTEGER  NativeError;
37 SQLRETURN retcode, SQLSTATEs;
38 
39 SQLCHAR     Name;
40 SQLINTEGER  LengthPtr;
41 
42 SQLSMALLINT i, MsgLen;
43 
44 SQLINTEGER  StringLengthPtr, IndicatorPtr;
45 SQLPOINTER  DataPtr;
46 
47 void SQLSetDescRecTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
48 
SQLSetDescRecTest()49 int SQLSetDescRecTest()
50 {
51 
52   /*  hstmt  */
53   // SQLPrepare a statement to select rows from the ORDERS Table. We can create the table and inside rows in
54   // NDB by program TestDirectSQL. In this test program(SQLSetDescRecTest),we only have three rows in
55   // table ORDERS
56 
57 /* Prepare the SQL statement with parameter markers. */
58 retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS)", SQL_NTS);
59 
60 /* SELECT OrderID, CustID, OpenDate, SalesPerson from Table ORDERS */
61 
62 if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
63 
64   /* RecoderNumber is less than 1 */
65 retcode = SQLSetDescRec(hdesc, -1, 1002, 1007, 1013, 1005, 1006, (void *)DataPtr, &StringLengthPtr, &IndicatorPtr);
66 if  (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
67    SQLSetDescRecTest_DisplayError(SQL_HANDLE_DESC, hdesc);
68 
69   /* RecoderNumber is greater than N, N be the value of the COUNT field of D, D be the allocated CLI */
70   /* descriptor area identified by DescriptorHandle */
71 retcode = SQLSetDescRec(hdesc, 4, 1002, 1007, 1013, 1005, 1006, (void *)DataPtr, &StringLengthPtr, &IndicatorPtr);
72 if  (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
73    SQLSetDescRecTest_DisplayError(SQL_HANDLE_DESC, hdesc);
74 
75 }
76 
77   return 0;
78 
79  }
80 
81 
SQLSetDescRecTest_DisplayError(SQLSMALLINT HandleType,SQLHDESC InputHandle)82 void SQLSetDescRecTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle)
83 {
84      i = 1;
85      while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
86              Sqlstate, &NativeError, Msg, sizeof(Msg),
87              &MsgLen)) != SQL_NO_DATA)                   {
88 
89      ndbout << "the HandleType is:" << HandleType << endl;
90      ndbout << "the InputHandle is :" << InputHandle << endl;
91      ndbout << "the output state is:" << (char *)Sqlstate << endl;
92 
93      i ++;
94                                                          }
95 
96 }
97 
98 
99 
100