HRESULT CDBStepNC::InsertRow(CString table, CStringVector & columns, CStringVector & values) { CCommand< CDynamicStringAccessor > sqlInsertCommand; int i; CString tszSQL; HRESULT hr; if(values.size() != columns.size()) return E_INVALIDARG; if(values.size() == 0 || columns.size()==0) return E_INVALIDARG; tszSQL.Format("INSERT INTO %s (", table); for(i=0; i<columns.size(); i++) { if(i>0) tszSQL+=" ,"; tszSQL.AppendFormat("%s", columns[i]); } tszSQL.AppendFormat(") VALUES ("); for(i=0; i<values.size(); i++) { if(i>0) tszSQL+=" ,"; tszSQL.AppendFormat("'%s'", values[i]); } tszSQL.AppendFormat(")"); hr = sqlInsertCommand.Open( m_session, tszSQL ); return hr; }
void CDBStepNC::ExecuteSql(CString tszSQL) { HRESULT hr; try { CCommand<CDynamicAccessor, CRowset> commandInsert; //TCHAR tszSQL[] = _bstr_t(SQLCommandString); //hr = m_session.StartTransaction(); if(FAILED(hr = commandInsert.Open(m_session, (LPCTSTR) tszSQL, NULL , NULL, DBGUID_DBSQL, false))) DebugBreak(); //if(FAILED(hr = m_session.Commit())) // DebugBreak(); //DatabaseConnection->BeginTrans(); // SQLCommand->ActiveConnection = DatabaseConnection; // SQLCommand->CommandText = _bstr_t(SQLCommandString); // SQLCommand->Execute(NULL, NULL, adCmdText); } catch(_com_error& e) { ATLTRACE("com error: %d - %s\n", e.Error(), (const char*)e.Description()); Close(); //DatabaseConnection->RollbackTrans(); } // DatabaseConnection->Commit(); OutputDebugString("ExecuteSql Succeeded\n"); }