From 5b3aec2b904a2eb7478240dac2f56d8928fc2362 Mon Sep 17 00:00:00 2001 From: "magnus@neptunus.(none)" <> Date: Wed, 14 Apr 2004 10:53:21 +0200 Subject: Initial revision of NDB Cluster files --- ndb/test/odbc/client/SQLGetDataTest.cpp | 358 ++++++++++++++++++++++++++++++++ 1 file changed, 358 insertions(+) create mode 100644 ndb/test/odbc/client/SQLGetDataTest.cpp (limited to 'ndb/test/odbc/client/SQLGetDataTest.cpp') diff --git a/ndb/test/odbc/client/SQLGetDataTest.cpp b/ndb/test/odbc/client/SQLGetDataTest.cpp new file mode 100644 index 00000000000..9d958c6c953 --- /dev/null +++ b/ndb/test/odbc/client/SQLGetDataTest.cpp @@ -0,0 +1,358 @@ +/* Copyright (C) 2003 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; either version 2 of the License, or + (at your option) any later version. + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + /** + * @file SQLGetDataTest.cpp + */ + +#include +using namespace std; + +#define GD_MESSAGE_LENGTH 200 + +SQLHSTMT GD_hstmt; +SQLHENV GD_henv; +SQLHDBC GD_hdbc; +SQLHDESC GD_hdesc; + +void GetData_DisplayError(SQLSMALLINT GD_HandleType, SQLHSTMT GD_InputHandle); + +/** + * Test to retrieve data for a single unbound column + * in the current row of a result data set + * + * Tests: + * -# Test1 There is no fetched rowset associated with S + * -# Test2 column number is less than zero + * -# Test3 fetched rowset is empty + * @return Zero, if test succeeded + */ + +int SQLGetDataTest() +{ + SQLRETURN retcode; + SQLCHAR ColumnName; + SQLINTEGER CustID; + // SQLCHAR Name, Address, Phone; + SQLCHAR SQLStmt [120]; + SQLCHAR SQLStmt1 [120]; + + //************************************ + //** Allocate An Environment Handle ** + //************************************ + retcode = SQLAllocHandle(SQL_HANDLE_ENV, + SQL_NULL_HANDLE, + &GD_henv); + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + ndbout << "Allocated an environment Handle!" << endl; + + //********************************************* + //** Set the ODBC application Version to 3.x ** + //********************************************* + retcode = SQLSetEnvAttr(GD_henv, + SQL_ATTR_ODBC_VERSION, + (SQLPOINTER) SQL_OV_ODBC3, + SQL_IS_UINTEGER); + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + ndbout << "Set the ODBC application Version to 3.X!" << endl; + + //********************************** + //** Allocate A Connection Handle ** + //********************************** + + retcode = SQLAllocHandle(SQL_HANDLE_DBC, + GD_henv, + &GD_hdbc); + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + ndbout << "Allocated a connection Handle!" << endl; + + // ******************* + // ** Connect to DB ** + // ******************* + retcode = SQLConnect(GD_hdbc, + (SQLCHAR *) connectString(), + SQL_NTS, + (SQLCHAR *) "", + SQL_NTS, + (SQLCHAR *) "", + SQL_NTS); + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + ndbout << "Connected to DB : OK!" << endl; + else + { + ndbout << "Failure to Connect DB!" << endl; + return NDBT_FAILED; + } + + //******************************* + //** Allocate statement handle ** + //******************************* + + retcode = SQLAllocHandle(SQL_HANDLE_STMT, + GD_hdbc, + &GD_hstmt); + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + ndbout << "Allocated a statement handle!" << endl; + + //***************************** + //** Define SELECT statement ** + //***************************** + + strcpy((char *) SQLStmt, "SELECT * FROM Customers"); + + + //*********************************** + //** Prepare SELECT SQL statement ** + //*********************************** + + retcode = SQLPrepare(GD_hstmt, + SQLStmt, + SQL_NTS); + ndbout << endl << "Preparing SELECT, retcode = SQLprepare()= " + << retcode << endl; + + //********************************* + //** Execute prepared statement ** + //********************************* + + // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + //{ + + retcode = SQLExecute(GD_hstmt); + + ndbout << "Exexuting SELECT, retcode = SQLExecute()= " + << retcode << endl; + + // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + // { + + //***************************************************************** + //** Test1 ** + //** There is no fetched rowset associated with S(SQL-statement) ** + //***************************************************************** + + retcode = SQLGetData(GD_hstmt, + 1, + SQL_C_SLONG, + &CustID, + sizeof(CustID), + NULL); + ndbout << "retcode = SQLGetData()= " << retcode << endl; + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + { + ndbout << endl << "Test 1:" << endl; + ndbout << "There is no fetched rowset associated with SQL" + << " statement. But system reported SUCCESS or" + << " SUCCESS_WITH_INFO. Please check the function!" << endl; + GetData_DisplayError(SQL_HANDLE_STMT, GD_hstmt); + } + else if (retcode == SQL_ERROR) + { + ndbout << endl << "Test 1:" << endl; + ndbout << "There is no fetched rowset associated with SQL" + << " statement. The system reported ERROR " + << " The function is OK!" << endl; + } + else + ndbout << endl; + + //******************************* + //** Fetch Data from database ** + //******************************* + + retcode = SQLFetch(GD_hstmt); + + ndbout << endl + << "Fetching after Executing SELECT, retcode = SQLFetch()= " + << retcode << endl; + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + { + + //************************************** + //** Test2 ** + //** column number is less than zero ** + //************************************** + + retcode = SQLGetData(GD_hstmt, + 0, + SQL_C_ULONG, + &CustID, + sizeof(CustID), + NULL); + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + { + ndbout << "Test 2:" <<"Column number is less than zero" + << " The system reported SUCCESS or SUCCESS_WITH_INFO." + << " Check the function, please!" <