コード例 #1
0
ファイル: query.cpp プロジェクト: ledusledus/meos
void
Query::proc(SQLQueryParms& p)
{
	sbuffer_.str("");

	for (std::vector<SQLParseElement>::iterator i = parse_elems_.begin();
			i != parse_elems_.end(); ++i) {
		MYSQLPP_QUERY_THISPTR << i->before;
		int num = i->num;
		if (num >= 0) {
			SQLQueryParms* c;
			if (size_t(num) < p.size()) {
				c = &p;
			}
			else if (size_t(num) < def.size()) {
				c = &def;
			}
			else {
				*this << " ERROR";
				throw BadParamCount(
						"Not enough parameters to fill the template.");
			}

			SQLString& param = (*c)[num];
			SQLString* ss = pprepare(i->option, param, c->bound());
			MYSQLPP_QUERY_THISPTR << *ss;
			if (ss != &param) {
				// pprepare() returned a new string object instead of
				// updating param in place, so we need to delete it.
				delete ss;
			}
		}
	}
}
コード例 #2
0
ファイル: SQLCode.cpp プロジェクト: shenglonglin2000/MT
void  SQLCode::_GetSQLFormat(const std::string& strSQLKey, SQLStatement& strSQLFormats)
{
	ThreadGuard guard(m_threadLock); // avoid threads racing
	TA_ASSERT(NULL != m_pSqlFileHelper, "sql file helper handler is null.");
	m_pSqlFileHelper->getSQLString(strSQLKey, strSQLFormats);

	if (strSQLFormats.strCommon.empty() && strSQLFormats.strMySQL.empty() && strSQLFormats.strSqlite.empty())
	{
		TA_THROW(BadParamCount("Cannot find the SQL statement in the hash-table"));	
	}
}
コード例 #3
0
ファイル: SQLCode.cpp プロジェクト: shenglonglin2000/MT
void SQLCode::buildSQLStatement(SQLVarParms& varParms, SQLStatement& rSqlStatement)
{
	FUNCTION_ENTRY("SQLCode::_ConstructSQLStatement()");
	std::string strSQLKey;
	SQLStatement SQLFormats;
	int nDbType = 0;
	size_t uiTotalSQLSize = 0;	

	try
	{
		size_t uVarCount = varParms.size();
		if (uVarCount < defMINPARAMSIZE)
			TA_THROW(BadParamCount("the PrepareStatement parameter count error"));

		_GetDbTypeAndSQLKey(varParms, strSQLKey);
		_GetSQLFormat(strSQLKey, SQLFormats);
		//_GetSQLID(strSQLKey, rSqlStatement);

		_BuildNormalSQL(varParms, SQLFormats, rSqlStatement);
		_PrintSQL(strSQLKey, rSqlStatement);			
	}
	catch (BadParamCount* e)
	{
		SQLCodeException SQLException(e->what());
		throw SQLException;
	}
	catch (BadIndex* e)
	{
		SQLCodeException SQLException(e->what());
		throw SQLException;
	}
	catch(DbTypeNotSupported* e)
	{
		SQLCodeException SQLException(e->what());
		throw SQLException;
	}
	catch (...)
	{
		SQLCodeException SQLException("Unknown SQLCode exception");
		throw SQLException;
	}

	FUNCTION_EXIT;
}
コード例 #4
0
ファイル: SQLCode.cpp プロジェクト: shenglonglin2000/MT
void  SQLCode::_BuildNormalSQL(const SQLVarParms& varParms, SQLStatement& rSQLFormats, SQLStatement& rSqlStatement)
{
	if (!rSQLFormats.strCommon.empty())
	{
		size_t uiTotalSQLSize = _GetSQLSize(varParms, rSQLFormats.strCommon);
		if ( uiTotalSQLSize > MAX_SQLSTRING_LEN )
		{
			_BuildLargeSQL(varParms, uiTotalSQLSize, rSQLFormats.strCommon, rSqlStatement.strCommon);
		}
		else
		{
			_BuildSQL(varParms, rSQLFormats.strCommon, rSqlStatement.strCommon);
		}
	}
	else
	{
		if (rSQLFormats.strMySQL.empty() || rSQLFormats.strSqlite.empty())
			TA_THROW(BadParamCount("The MySQL or Oracle SQL Format is empty"));

		// build MySQL SQL statement
		size_t uiTotalSQLSize = _GetSQLSize(varParms, rSQLFormats.strMySQL, enumMySQL_SQL);
		if ( uiTotalSQLSize > MAX_SQLSTRING_LEN )
		{
			_BuildLargeSQL(varParms, uiTotalSQLSize, rSQLFormats.strMySQL, rSqlStatement.strMySQL, enumMySQL_SQL);
		}
		else
		{
			_BuildSQL(varParms, rSQLFormats.strMySQL, rSqlStatement.strMySQL, enumMySQL_SQL);
		}
		
		// build Oracle SQL Statement
		uiTotalSQLSize = _GetSQLSize(varParms, rSQLFormats.strSqlite, enumOracle_SQL);
		if ( uiTotalSQLSize > MAX_SQLSTRING_LEN )
		{
			_BuildLargeSQL(varParms, uiTotalSQLSize, rSQLFormats.strSqlite, rSqlStatement.strSqlite, enumOracle_SQL);
		}
		else
		{
			_BuildSQL(varParms, rSQLFormats.strSqlite, rSqlStatement.strSqlite, enumOracle_SQL);
		}
	}	

}