예제 #1
0
bool OdbcCommand::Execute(const tstring & szSQL)
{
	if (!Open())
		return false;

#ifdef _DEBUG
	OutputDebugString((szSQL + _T("\n")).c_str());
#endif

	if (!BindParameters())
		return false;

	if (!SQL_SUCCEEDED(SQLExecDirect(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length())))
	{
		if (m_odbcConnection != NULL)
			m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute statement."));
		else
			m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);

		Close();
		return false;
	}

	if (!MoveNext())
		MoveNextSet();

	return true;
}
예제 #2
0
bool OdbcCommand::Execute(const tstring & szSQL)
{
	if (!Open())
		return false;

#ifdef USE_SQL_TRACE
	TRACE((szSQL + _T("\n")).c_str());
#endif

	if (!BindParameters())
		return false;

	SQLRETURN result = SQLExecDirect(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length());
	if (!(result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO || result == SQL_NO_DATA))
	{
		if (m_odbcConnection != nullptr)
			m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute statement."));
		else
			m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);

		Close();
		return false;
	}

	if (!MoveNext())
		MoveNextSet();

	return true;
}
예제 #3
0
bool OdbcCommand::Prepare(const tstring & szSQL)
{
	if (!Open())
		return false;

#ifdef USE_SQL_TRACE
	TRACE((szSQL + _T("\n")).c_str());
#endif

	if (!SQL_SUCCEEDED(SQLPrepare(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length())))
	{
		if (m_odbcConnection != nullptr)
			m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, _T("SQLPrepare"), _T("Failed to prepare statement."));
		else
			m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);

		Close();
		return false;
	}

	if (!BindParameters())
		return false;

	SQLRETURN result = SQLExecute(m_hStmt);
	if (!(result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO || result == SQL_NO_DATA))
	{
		if (m_odbcConnection != nullptr)
			m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute prepared statement."));
		else
			m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);

		Close();
		return false;
	}

	// If there's no rows to move through, skip to the next result set.
	if (!MoveNext())
		MoveNextSet();

	ClearParameters();
	return true;
}
예제 #4
0
bool OdbcCommand::Prepare(const tstring & szSQL)
{
	if (!Open())
		return false;

#ifdef _DEBUG
	OutputDebugString((szSQL + _T("\n")).c_str());
#endif

	if (!SQL_SUCCEEDED(SQLPrepare(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length())))
	{
		if (m_odbcConnection != NULL)
			m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, _T("SQLPrepare"), _T("Failed to prepare statement."));
		else
			m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);

		Close();
		return false;
	}

	if (!BindParameters())
		return false;

	if (!SQL_SUCCEEDED(SQLExecute(m_hStmt)))
	{
		if (m_odbcConnection != NULL)
			m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute prepared statement."));
		else
			m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt);

		Close();
		return false;
	}

	// If there's no rows to move through, skip to the next result set.
	if (!MoveNext())
		MoveNextSet();

	ClearParameters();
	return true;
}