/* 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; version 2 of the License. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ /** * @file SQLColAttributeTest2.cpp */ #include using namespace std; #define MAXIMUM_MESSAGE_LENGTH_Test2 200 #define BufferLengthTest2 156 SQLHSTMT ColAtt_hstmtTest2; SQLHSTMT ColAtt_hdbcTest2; SQLHENV ColAtt_henvTest2; SQLHDESC ColAtt_hdescTest2; SQLCHAR CharacterAttributePtrTest2; SQLINTEGER NumericAttributePtrTest2; SQLSMALLINT StringLengthPtrTest2; SQLRETURN ColAtt_retTest2; void ColAtt_DisplayErrorTest2(SQLSMALLINT ColAttTest2_HandleType, SQLHSTMT ColAttTest2_InputHandle); /** * Test returning descriptor information * * Test: * -# Call SQLColAttribute without preceeding SQLExecute * -# Let TYPE is 'ITEM' in Table 20, FieldIdentifer is zero * -# Let TYPE is 'ITEM' in Table 20, ColumnNumber is less than one * -# FieldIdentifer is not one of the code valuess in Table 20 * -# Let TYPE is 'ITEM' in Table 20, ColumnNumber is greater than 1044 * * @return Zero, if test succeeded */ int SQLColAttributeTest2() { ndbout << endl << "Start SQLColAttribute Testing2" << endl; SQLCHAR SQLStmt [120]; //******************************************************************* //** Test ** //** ** //** hstmt ** //** Prepare a statement without executing the statement ** //** ** //** Intended result: table Customer should not have new row ** //******************************************************************* //************************************ //** Allocate An Environment Handle ** //************************************ ColAtt_retTest2 = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &ColAtt_henvTest2); if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO) ndbout << "Allocated an environment Handle!" << endl; //********************************************* //** Set the ODBC application Version to 3.x ** //********************************************* ColAtt_retTest2 = SQLSetEnvAttr(ColAtt_henvTest2, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO) ndbout << "Set the ODBC application Version to 2.x!" << endl; //********************************** //** Allocate A Connection Handle ** //********************************** ColAtt_retTest2 = SQLAllocHandle(SQL_HANDLE_DBC, ColAtt_henvTest2, &ColAtt_hdbcTest2); if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO) ndbout << "Allocated a connection Handle!" << endl; // ******************* // ** Connect to DB ** // ******************* ColAtt_retTest2 = SQLConnect(ColAtt_hdbcTest2, (SQLCHAR *) connectString(), SQL_NTS, (SQLCHAR *) "", SQL_NTS, (SQLCHAR *) "", SQL_NTS); if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO) ndbout << "Connected to DB : OK!" << endl; else { ndbout << "Failure to Connect DB!" << endl; return NDBT_FAILED; } //******************************* //** Allocate statement handle ** //******************************* ColAtt_retTest2 = SQLAllocHandle(SQL_HANDLE_STMT, ColAtt_hdbcTest2, &ColAtt_hstmtTest2); if(ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == 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_retTest2 = SQLPrepare(ColAtt_hstmtTest2, SQLStmt, SQL_NTS); if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO) { //************************************************************** //** FieldIdentifer is not one of the code valuess in Table 20, //** "Codes used for descriptor fields" //************************************************************** ColAtt_retTest2 = SQLColAttribute(ColAtt_hstmtTest2, 2, 9999, &CharacterAttributePtrTest2, BufferLengthTest2, &StringLengthPtrTest2, &NumericAttributePtrTest2); if (ColAtt_retTest2 == SQL_ERROR || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO) { ndbout << endl << "FieldIdentifer is not one of the" << endl; ndbout << "code valuess in Table 20, Codes used for" << endl; ndbout << "descriptor fields" <