/* 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 <