Example #1
0
ref<Statement> Connection::CreateStatement()
{
    try
    {
		sql::Statement* stmt = m_impl->createStatement();
		return gc_new<Statement>(stmt);
    }
    catch (sql::SQLException& e)
    {
		m_rc->SetDamage(true);
		cdec_throw(MysqlException(e.getErrorCode(), e.getSQLState(), e.what()));
    }
}
Example #2
0
void Connection::Rollback()
{ 
	if (m_impl != NULL)
	{
		try
		{
			m_impl->rollback();
		}
		catch (sql::SQLException &e)
		{
			cdec_throw(MysqlException(e.getErrorCode(), e.getSQLState(), e.what()));
		}
	}
}
Example #3
0
void Connection::SetAutoCommit(bool flag)
{ 
	if (m_impl != NULL)
	{
		try
		{
			m_impl->setAutoCommit(flag);
		}
		catch (sql::SQLException &e)
		{
			cdec_throw(MysqlException(e.getErrorCode(), e.getSQLState(), e.what()));
		}
	}
}
Example #4
0
	Statement::Statement(MYSQL* conn, const string& sql)
	{
		m_conn = conn;
		m_stmt = mysql_stmt_init(m_conn);
		if(!m_stmt)
			throw(MysqlException(ERRORS,"mysql_stmt_init error"));
		m_state = STMT_INITED;
		m_binder = NULL;

		STMT_Throw(m_stmt,
				mysql_stmt_prepare(m_stmt, sql.data(), sql.size())
			);
		int pc = mysql_stmt_param_count(m_stmt);
		if (pc > 0)
			m_binder = new Binder(pc);
		m_state = STMT_COMPILED;
	}
Example #5
0
ref<PreparedStatement> Connection::CreatePreparedStatement(stringx sql)
{
	sql::SQLString sql_s = Strx2SqlStr(sql);
#ifdef ENABLE_MYSQL_DEBUG
	printf("[MYSQL] CreatePreparedStatement SQL: %s\n", sql_s.c_str());
#endif
    try
    {
		sql::PreparedStatement* sprstmt = m_impl->prepareStatement(sql_s);
		return gc_new<PreparedStatement>(sprstmt);
    }
    catch (sql::SQLException& e)
    {
#ifdef ENABLE_MYSQL_DEBUG
		puts("MYSQL Exception");
		printf("Message: %s\n", e.what());
		printf("State: %s\n", e.getSQLState().c_str());
#endif
		m_rc->SetDamage(true);
		cdec_throw(MysqlException(e.getErrorCode(), e.getSQLState(), e.what()));
    }
}
Example #6
0
	ResultSet* Statement::getResultSet()
	{
		if(m_state!=STMT_EXECUTED)
			throw(MysqlException(ERRORS,"statement has not been executed!"));
		return new ResultSet(m_stmt);
	}
Example #7
0
	void Statement::bindStrParam(unsigned i, const string& val)
	{
		if(m_binder==NULL)
			throw(MysqlException(ERRORS,"no param to bind"));
		m_binder->bind(i, val);
	}
Example #8
0
	void Statement::bindLongParam(unsigned i, long long val)
	{
		if(m_binder==NULL)
			throw(MysqlException(ERRORS,"no param to bind"));
		m_binder->bind(i, val);
	}