All pastes #393783 Raw Edit

version B

public cpp v1 · immutable
·published 2007-03-13 21:05 UTC
rendered paste body
HENV hEnv;HDBC hDbc;RETCODE rc;int iOut;char strOut[256];char szDSN[256] = "driver={Microsoft Access Driver (*.mdb)};dbq=[c:\\eckstore.mdb];";std::ostringstream os; struct DBRESULTS{	std::string pf_id;	std::string name;	std::string name2;	std::string description;	int list_price;	std::string image_file;	int image_width;	int image_height;	int dept_id;	std::string active_flag;	std::string dropship;	std::string keywords;	std::string searchstring;	std::string alt_flag;	std::string rel_flag;};	int dbinit(){        rc = SQLAllocEnv(&hEnv);        rc = SQLAllocConnect(hEnv, &hDbc);        rc = SQLDriverConnect(hDbc, NULL, (unsigned char*)szDSN, SQL_NTS, (unsigned char*)strOut, 255, (SQLSMALLINT*)&iOut, SQL_DRIVER_NOPROMPT);        return 0;} void dbclose(){        rc = SQLDisconnect(hDbc);        rc = SQLFreeEnv(hEnv);} std::string dbquery(const char* query){        int ival;        char chval[255] = "";        int ret1;        int ret2;        HSTMT hStmt;		DBRESULTS product_record;                                                        rc = SQLAllocStmt(hDbc,&hStmt);        rc = SQLPrepare(hStmt,(unsigned char*)query, SQL_NTS);//1		rc = SQLBindCol(hStmt, 1, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.pf_id = chval;		rc = SQLBindCol(hStmt, 2, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.name = chval;		rc = SQLBindCol(hStmt, 3, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.name2 = chval;		rc = SQLBindCol(hStmt, 4, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.description = chval;        rc = SQLBindCol(hStmt, 5, SQL_C_ULONG, &ival, 4, (SQLINTEGER*)&ret1);		product_record.list_price = ival;		rc = SQLBindCol(hStmt, 6, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.image_file = chval;		rc = SQLBindCol(hStmt, 7, SQL_C_ULONG, &ival, 4, (SQLINTEGER*)&ret1);		product_record.image_width = ival;		rc = SQLBindCol(hStmt, 8, SQL_C_ULONG, &ival, 4, (SQLINTEGER*)&ret1);		product_record.image_height = ival;		rc = SQLBindCol(hStmt, 9, SQL_C_ULONG, &ival, 4, (SQLINTEGER*)&ret1);		product_record.dept_id = ival;		rc = SQLBindCol(hStmt, 10, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.active_flag = chval;		rc = SQLBindCol(hStmt, 11, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.dropship = chval;		rc = SQLBindCol(hStmt, 12, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.keywords = chval;		rc = SQLBindCol(hStmt, 13, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.searchstring = chval;		rc = SQLBindCol(hStmt, 14, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.alt_flag = chval;		rc = SQLBindCol(hStmt, 15, SQL_C_CHAR, chval, 255, (SQLINTEGER*)&ret1);		product_record.rel_flag = chval;		        rc = SQLExecute(hStmt);        rc = SQLFetch(hStmt);         if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)        {                MessageBox(NULL, "Oops", "Error", MB_ICONEXCLAMATION | MB_OK);                return "Error with your SQL statement.";        }         os.clear();		os << product_record.pf_id << " || "			<< product_record.name << " || "			<< product_record.name2 << " || "			<< product_record.description << " || "			<< product_record.list_price << " || "			<< product_record.image_file << " || "			<< product_record.image_width << " || "			<< product_record.image_height << " || "			<< product_record.dropship;        MessageBox(NULL, os.str().c_str(), "Result", 0 );        rc=SQLFreeStmt(hStmt, SQL_DROP);         return os.str();}