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/SQLColAttributeTest3.cpp | 275 ++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 ndb/test/odbc/client/SQLColAttributeTest3.cpp (limited to 'ndb/test/odbc/client/SQLColAttributeTest3.cpp') diff --git a/ndb/test/odbc/client/SQLColAttributeTest3.cpp b/ndb/test/odbc/client/SQLColAttributeTest3.cpp new file mode 100644 index 00000000000..f8817565711 --- /dev/null +++ b/ndb/test/odbc/client/SQLColAttributeTest3.cpp @@ -0,0 +1,275 @@ +/* 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 SQLColAttributeTest3.cpp + */ + +#include +using namespace std; + +#define MAXIMUM_MESSAGE_LENGTH_Test3 200 +#define BufferLengthTest3 156 + +SQLHSTMT ColAtt_hstmtTest3; +SQLHSTMT ColAtt_hdbcTest3; +SQLHENV ColAtt_henvTest3; +SQLHDESC ColAtt_hdescTest3; + +SQLCHAR TypeName[18]; +SQLSMALLINT TypeNameLen; + +SQLRETURN ColAtt_retTest3; + +void ColAtt_DisplayErrorTest3(SQLSMALLINT ColAttTest3_HandleType, + SQLHSTMT ColAttTest3_InputHandle); + +/** + * Test returning descriptor information + * + * Test: + * -# Print out column name without executing statement + * + * @return Zero, if test succeeded + */ + +int SQLColAttributeTest3() +{ + ndbout << endl << "Start SQLColAttribute Testing3" << endl; + + SQLCHAR SQLStmt [120]; + + //******************************************************************** + //** Test 3: ** + //** ** + //** Prepare a statement without executing the statement ** + //** We want to print out the Type Name of each column in the table ** + //** Customers ** + //** ** + //** Intended result: Only display column name, but there is no new ** + //** row in table Customers ** + //******************************************************************** + + //************************************ + //** Allocate An Environment Handle ** + //************************************ + ColAtt_retTest3 = SQLAllocHandle(SQL_HANDLE_ENV, + SQL_NULL_HANDLE, + &ColAtt_henvTest3); + + if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO) + ndbout << "Allocated an environment Handle!" << endl; + + //********************************************* + //** Set the ODBC application Version to 3.x ** + //********************************************* + ColAtt_retTest3 = SQLSetEnvAttr(ColAtt_henvTest3, + SQL_ATTR_ODBC_VERSION, + (SQLPOINTER) SQL_OV_ODBC3, + SQL_IS_UINTEGER); + + if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO) + ndbout << "Set the ODBC application Version to 3.x!" << endl; + + //********************************** + //** Allocate A Connection Handle ** + //********************************** + + ColAtt_retTest3 = SQLAllocHandle(SQL_HANDLE_DBC, + ColAtt_henvTest3, + &ColAtt_hdbcTest3); + + if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO) + ndbout << "Allocated a connection Handle!" << endl; + + // ******************* + // ** Connect to DB ** + // ******************* + ColAtt_retTest3 = SQLConnect(ColAtt_hdbcTest3, + (SQLCHAR *) connectString(), + SQL_NTS, + (SQLCHAR *) "", + SQL_NTS, + (SQLCHAR *) "", + SQL_NTS); + + if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO) + ndbout << "Connected to DB : OK!" << endl; + else + { + ndbout << "Failure to Connect DB!" << endl; + return NDBT_FAILED; + } + + //******************************* + //** Allocate statement handle ** + //******************************* + + ColAtt_retTest3 = SQLAllocHandle(SQL_HANDLE_STMT, + ColAtt_hdbcTest3, + &ColAtt_hstmtTest3); + if(ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO) + ndbout << "Allocated a statement handle!" << endl; + + //************************ + //** Define a statement ** + //************************ + + /* + strcpy((char *) SQLStmt, + "DELETE FROM Customers WHERE CustID = 6"); + */ + + strcpy((char *) SQLStmt, + "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (6, 'Jan', 'LM vag 8', '969696')"); + + /* + strcpy((char *) SQLStmt, + "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (?, ?, ?, ?)"); + */ + + //***************************** + //** Prepare SQL statement ** + //***************************** + ColAtt_retTest3 = SQLPrepare(ColAtt_hstmtTest3, + SQLStmt, + SQL_NTS); + + if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO) + { + //************************************ + //** Display the name of column one ** + //************************************ + ColAtt_retTest3 = SQLColAttribute(ColAtt_hstmtTest3, + 1, + SQL_COLUMN_TYPE_NAME, + TypeName, + sizeof(TypeName), + &TypeNameLen, + NULL); + + if (ColAtt_retTest3 == SQL_ERROR || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO) + { + ndbout << endl << "ColAtt_retTest3 = " << ColAtt_retTest3 << endl; + ndbout << endl << "Name of column 1 is:" + << (char *)TypeName <