#include #include #include #include #include #define CHECK_ODBC_RES(exp) rc = exp; if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) throw rc #define CHECK_ODBC_RES_OK(exp) rc = exp; if(rc != SQL_SUCCESS) throw rc void main() { //MySQL SQLWCHAR * pServer = (SQLWCHAR*)L"MySQLlocal"; SQLWCHAR * pUser = (SQLWCHAR*)L"rnddb6"; SQLWCHAR * pPassword = (SQLWCHAR*)L"rnddb6"; SQLWCHAR * pCatalog = (SQLWCHAR*)L"rnddb6"; SQLWCHAR * pSchema = (SQLWCHAR*)L""; SQLWCHAR * pTable = (SQLWCHAR*)L"t_length"; SQLRETURN rc; SQLHANDLE hEnv = NULL; SQLHANDLE hDBC = NULL; SQLHANDLE hSTMS = NULL; SQLSMALLINT nCols; SQLINTEGER nLen; int i; int iAttr; try { CHECK_ODBC_RES_OK(::SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&hEnv)); CHECK_ODBC_RES_OK(::SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC2,0)); CHECK_ODBC_RES_OK(::SQLAllocHandle(SQL_HANDLE_DBC,hEnv,&hDBC)); CHECK_ODBC_RES(::SQLConnectW(hDBC,pServer,SQL_NTS,pUser,SQL_NTS,pPassword,SQL_NTS)); CHECK_ODBC_RES_OK(::SQLAllocHandle(SQL_HANDLE_STMT,hDBC,&hSTMS)); CHECK_ODBC_RES_OK(SQLColumnsW(hSTMS, pCatalog, ((pCatalog) ? SQL_NTS :0), pSchema, ((pSchema) ? SQL_NTS :0), pTable, ((pTable) ? SQL_NTS :0), NULL, 0)); CHECK_ODBC_RES_OK(::SQLNumResultCols(hSTMS, &nCols));//SQL_SUCCESS_WITH_INFO SQLSMALLINT pType[100]; char pBuf[50][1000]; short pShort[50]; int pInt[50]; SQLINTEGER cbLen[100]; cout <<"Col Name:"<=0) cout<< pBuf[i]<<'#'; else cout<<'#'; } else if(pType[i] ==SQL_SMALLINT) { cout<