A CRecordset Problem.
-
I use Teradata database. Teradata has a SQL Statement :show table mytable; This statement can return the definition of mytable. But CRecordset class cann't run this SQL. CDatabase can do it,but CDatabase.ExecuteSQL function has no return . strSQL = "Show table mytable;"; set.Open(CRecordset::forwardOnly,(LPCTSTR)strSQL,CRecordset::none);//Error ! database.ExecuteSQL(strSQL);//OK,but how can I get the result? How can I run this SQL and get the result? Thanks.
-
I use Teradata database. Teradata has a SQL Statement :show table mytable; This statement can return the definition of mytable. But CRecordset class cann't run this SQL. CDatabase can do it,but CDatabase.ExecuteSQL function has no return . strSQL = "Show table mytable;"; set.Open(CRecordset::forwardOnly,(LPCTSTR)strSQL,CRecordset::none);//Error ! database.ExecuteSQL(strSQL);//OK,but how can I get the result? How can I run this SQL and get the result? Thanks.
willyfu wrote: How can I run this SQL and get the result? Getting the results from a stored procedure is not that difficult. One way of doing it is shown in MSDN article Q183001. Here is another. Here is a helpful discussion.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
willyfu wrote: How can I run this SQL and get the result? Getting the results from a stored procedure is not that difficult. One way of doing it is shown in MSDN article Q183001. Here is another. Here is a helpful discussion.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
finally,I found the ODBC API solution. CString strSQL; SQLLEN nRecCount,nFieldLen; strSQL.Format("Show table mytable;"); CRecordset set(&database);//Create a CRecordset object SQLExecDirect(set.m_hstmt,(SQLCHAR*)strSQL.GetBuffer(strSQL.GetLength()),strSQL.GetLength()); SQLRowCount(set.m_hstmt,&nRecCount); for(int n = 0;n < nRecCount; n++) { SQLFetch(set.m_hstmt); SQLGetData(set.m_hstmt,1,1,str1.GetBuffer(32000),32000,&nFieldLen); str1.ReleaseBuffer(); } that's all.
-
finally,I found the ODBC API solution. CString strSQL; SQLLEN nRecCount,nFieldLen; strSQL.Format("Show table mytable;"); CRecordset set(&database);//Create a CRecordset object SQLExecDirect(set.m_hstmt,(SQLCHAR*)strSQL.GetBuffer(strSQL.GetLength()),strSQL.GetLength()); SQLRowCount(set.m_hstmt,&nRecCount); for(int n = 0;n < nRecCount; n++) { SQLFetch(set.m_hstmt); SQLGetData(set.m_hstmt,1,1,str1.GetBuffer(32000),32000,&nFieldLen); str1.ReleaseBuffer(); } that's all.
While it may work, this is a very odd use of a
CString
object. I'm curious why you are using aCRecordset
object if all you need access to is itsm_hstmt
member.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow