Beispiel #1
0
uint32_t maintain_plant(i_mysql_iface *p_mysql_conn, c_memcached *p_memcached, uint32_t user_id, uint32_t msg_type, char *p_request_body, uint32_t request_len)
{
    if (check_val_len(msg_type, request_len, sizeof(db_msg_maintain_req_t)) != 0)
    {
        return ERR_MSG_LEN;
    }

    db_msg_maintain_req_t *p_req = (db_msg_maintain_req_t*)p_request_body;

    MYSQL *p_conn = p_mysql_conn->get_conn();
    if (NULL == p_conn)
    {
        KCRIT_LOG(user_id, "get mysql conn failed.");
        return ERR_SQL_ERR;
    }
    if (mysql_autocommit(p_conn, false) != 0)
    {
        KCRIT_LOG(user_id, "close mysql_autocommit failed.");
        return ERR_SQL_ERR;
    }


     //sprintf(g_sql_str,"UPDATE db_monster_%d.t_plant_%d  SET growth = growth + %u, last_growth_value = growth + %u, last_growth_time = %u, maintain = %u, maintain_count = %u, last_reward_id = %u where user_id = %u and hole_id = %u;", DB_ID(user_id), TABLE_ID(user_id), p_req->add_growth, p_req->add_growth, p_req->add_growth_time, p_req->new_maintain_type, p_req->maintain_count, p_req->last_reward_id, user_id, p_req->hole_id);

    sprintf(g_sql_str,"UPDATE db_monster_%d.t_plant_%d  SET growth = growth + %u, last_growth_value = growth, last_growth_time = %u, maintain = %u, maintain_count = %u, last_reward_id = %u where user_id = %u and hole_id = %u;", DB_ID(user_id), TABLE_ID(user_id), p_req->add_growth, p_req->add_growth_time, p_req->new_maintain_type, p_req->maintain_count, p_req->last_reward_id, user_id, p_req->hole_id);
     KINFO_LOG(user_id, "%s", g_sql_str);


        if (p_mysql_conn->execsql(g_sql_str) < 0)
        {
            KCRIT_LOG(user_id, "sql exec failed(%s).", p_mysql_conn->get_last_errstr());
            mysql_rollback(p_conn);
            mysql_autocommit(p_conn, true);
            return ERR_SQL_ERR;
        }

    sprintf(g_sql_str, "INSERT INTO db_monster_%d.t_plant_reward_%d(user_id, hole_id, reward_id, reward_happy, reward_exp, reward_coins) VALUES(%u, %u, %u, %u, %u, %u) ON DUPLICATE KEY UPDATE reward_happy = %u, reward_exp = %u, reward_coins = %u;", DB_ID(user_id), TABLE_ID(user_id), user_id, p_req->hole_id, p_req->last_reward_id, p_req->reward_happy, p_req->reward_exp, p_req->reward_coins, p_req->reward_happy, p_req->reward_exp, p_req->reward_coins);

    KINFO_LOG(user_id, "%s", g_sql_str);
        if (p_mysql_conn->execsql(g_sql_str) < 0)
        {
            KCRIT_LOG(user_id, "sql exec failed(%s).", p_mysql_conn->get_last_errstr());
            mysql_rollback(p_conn);
            mysql_autocommit(p_conn, true);
            return ERR_SQL_ERR;
        }

    // 结束事务
    if (mysql_commit(p_conn) != 0)
    {
        KCRIT_LOG(user_id, "mysql_commit() failed.");
        mysql_rollback(p_conn);
        mysql_autocommit(p_conn, true);
        return ERR_SQL_ERR;
    }

    mysql_autocommit(p_conn, true);
    return 0;
}
Beispiel #2
0
uint32_t get_open_act_reward(i_mysql_iface *p_mysql_conn, c_memcached *p_memcached, uint32_t user_id, uint32_t msg_type, char *p_request_body, uint32_t request_len)
{
    if(check_val_len(msg_type, request_len, sizeof(db_msg_get_open_reward_t)))
    {
        return ERR_MSG_LEN;
    }

    db_msg_get_open_reward_t *p_body = (db_msg_get_open_reward_t*)p_request_body;

    sprintf(g_sql_str, "update db_monster_%d.t_activity_%d set flag = 1 where user_id = %u and activity_id = %u and reward_id = %u;", DB_ID(user_id), TABLE_ID(user_id),  user_id, p_body->act_id, p_body->reward_id);

    KINFO_LOG(user_id, "get open reward:%s", g_sql_str);
    MYSQL *p_conn = p_mysql_conn->get_conn();
    if (NULL == p_conn)
    {
        KCRIT_LOG(user_id, "get mysql conn failed.");
        return ERR_SQL_ERR;
    }

    if (mysql_autocommit(p_conn, false) != 0)
    {
        KCRIT_LOG(user_id, "close mysql_autocommit failed.");
        return ERR_SQL_ERR;
    }

    if (p_mysql_conn->execsql(g_sql_str) < 0)
    {
        KCRIT_LOG(user_id, "[msg:%u]sql exec failed(%s).", msg_type, p_mysql_conn->get_last_errstr());
        mysql_autocommit(p_conn, true);
        return ERR_SQL_ERR;
    }


    sprintf(g_sql_str, "INSERT INTO db_monster_%d.t_stuff_%d(user_id, stuff_id, stuff_num) values(%u, %u, %u) ON DUPLICATE KEY UPDATE stuff_num = stuff_num + %u;", DB_ID(user_id), TABLE_ID(user_id), user_id, p_body->reward_id, p_body->reward_num, p_body->reward_num);


        KINFO_LOG(user_id, "open act_reward:%s", g_sql_str);
        if (p_mysql_conn->execsql(g_sql_str) < 0)
            {
                KCRIT_LOG(user_id, "[msg:%u]sql exec failed(%s).", msg_type, p_mysql_conn->get_last_errstr());
                mysql_rollback(p_conn);
                mysql_autocommit(p_conn, true);
                return ERR_SQL_ERR;
            }
    // 结束事务
    if (mysql_commit(p_conn) != 0)
    {
        KCRIT_LOG(user_id, "mysql_commit() failed.");
        mysql_rollback(p_conn);
        mysql_autocommit(p_conn, true);
        return ERR_SQL_ERR;
    }

    mysql_autocommit(p_conn, true);

    g_pack.pack(p_request_body, request_len);

    return 0;
}
Beispiel #3
0
uint32_t add_plant(i_mysql_iface *p_mysql_conn, c_memcached *p_memcached, uint32_t user_id, uint32_t msg_type, char *p_request_body, uint32_t request_len)
{
    if (check_val_len(msg_type, request_len, sizeof(db_msg_add_plant_req_t)) != 0)
    {
        return ERR_MSG_LEN;
    }

    db_msg_add_plant_req_t *p_req = (db_msg_add_plant_req_t *)p_request_body;

    KINFO_LOG(user_id, "[add plant]plant id:%u, hole id:%u, color:%u", p_req->plant_id, p_req->hole_id, p_req->color);

    snprintf(g_sql_str, sizeof(g_sql_str), "UPDATE db_monster_%d.t_plant_%d set plant_id = %u, color = %u, last_extra_growth_time = %u, last_growth_time= %u, maintain = %u, next_maintain_time = %u where user_id = %u and hole_id = %u;", DB_ID(user_id), TABLE_ID(user_id), p_req->plant_id, p_req->color, p_req->last_extra_growth_time, p_req->last_grown_time, p_req->maintain, p_req->maintain_time,  user_id, p_req->hole_id);

    MYSQL *p_conn = p_mysql_conn->get_conn();
    if (NULL == p_conn)
    {
        KCRIT_LOG(user_id, "get mysql conn failed.");
        return ERR_SQL_ERR;
    }
    if (mysql_autocommit(p_conn, false) != 0)
    {
        KCRIT_LOG(user_id, "close mysql_autocommit failed.");
        return ERR_SQL_ERR;
    }

    if (p_mysql_conn->execsql(g_sql_str) < 0)
    {
        KCRIT_LOG(user_id, "sql exec failed(%s).", p_mysql_conn->get_last_errstr());
    	mysql_autocommit(p_conn, true);
        return ERR_SQL_ERR;
    }

    //将种子数量减1
    snprintf(g_sql_str, sizeof(g_sql_str), "UPDATE db_monster_%d.t_stuff_%d SET stuff_num = stuff_num - 1 WHERE user_id = %u AND stuff_id = %u and stuff_num > 0", DB_ID(user_id), TABLE_ID(user_id), user_id, p_req->plant_id);
    KINFO_LOG(user_id, "desc seed:%s", g_sql_str);

    if (p_mysql_conn->execsql(g_sql_str) < 0)
    {
        KCRIT_LOG(user_id, "sql exec failed(%s).", p_mysql_conn->get_last_errstr());
        mysql_rollback(p_conn);
    	mysql_autocommit(p_conn, true);
        return ERR_SQL_ERR;
    }
    // 结束事务
    if (mysql_commit(p_conn) != 0)
    {
        KCRIT_LOG(user_id, "mysql_commit() failed.");
        mysql_rollback(p_conn);
        mysql_autocommit(p_conn, true);
        return ERR_SQL_ERR;
    }

    mysql_autocommit(p_conn, true);

    return 0;
}
Beispiel #4
0
uint32_t prize_lottery(i_mysql_iface *p_mysql_conn, c_memcached *p_memcached, uint32_t user_id, uint32_t msg_type, char *p_request_body, uint32_t request_len)
{
    if (check_val_len(msg_type, request_len, sizeof(db_request_prize_lottery_t)) != 0)
    {
        return ERR_MSG_LEN;
    }

    db_request_prize_lottery_t *p_req = (db_request_prize_lottery_t *)p_request_body;

    MYSQL_ROW row = NULL;
	MYSQL *p_conn = p_mysql_conn->get_conn();
     if(p_conn == NULL)
     {
         KCRIT_LOG(user_id, "get mysql conn failed.");
         return ERR_SQL_ERR;
     }
     if(mysql_autocommit(p_conn, false) != 0)
     {
         KCRIT_LOG(user_id, "close mysql_autocommit failed.");
         return ERR_SQL_ERR;
     }

	sprintf(g_sql_str, "UPDATE db_monster_%d.t_stuff_%d SET stuff_num = stuff_num-%u WHERE user_id= %u AND stuff_id=%u;", DB_ID(user_id), TABLE_ID(user_id), p_req->cost, user_id, p_req->stuff_a_id);
	if(p_mysql_conn->execsql(g_sql_str) < 0)
	{
		KCRIT_LOG(user_id, "sql exec failed(%s).", p_mysql_conn->get_last_errstr());
		mysql_rollback(p_conn);
		mysql_autocommit(p_conn,true);
		return ERR_SQL_ERR;
	}

	sprintf(g_sql_str, "INSERT INTO db_monster_%d.t_stuff_%d(user_id, stuff_id, stuff_num) VALUES(%u, %u, 1) ON DUPLICATE KEY UPDATE stuff_num = stuff_num+1;", DB_ID(user_id), TABLE_ID(user_id), user_id, p_req->stuff_b_id);
	if(p_mysql_conn->execsql(g_sql_str) < 0)
	{
		KCRIT_LOG(user_id, "sql exec failed(%s).", p_mysql_conn->get_last_errstr());
		mysql_rollback(p_conn);
		mysql_autocommit(p_conn,true);
		return ERR_SQL_ERR;
	}

     if (mysql_commit(p_conn) != 0)
     {
         KCRIT_LOG(user_id, "mysql_commit() failed.");
         mysql_rollback(p_conn);
         mysql_autocommit(p_conn, true);
         return ERR_SQL_ERR;
     }

     mysql_autocommit(p_conn, true);

	g_pack.pack(p_request_body, request_len);
	return 0;
}
Beispiel #5
0
static NEOERR* mysql_mdb_rollback(mdb_conn* conn)
{
    if (mysql_rollback(CONN(conn)->mysql) != 0)
        return nerr_raise(NERR_DB, mysql_error(CONN(conn)->mysql));

    return STATUS_OK;
}
Beispiel #6
0
void MySqlDataProvider::rollbackTransaction()
    throw (std::runtime_error)
{
    if (!mIsConnected)
    {
        const std::string error = "Trying to rollback a transaction while not "
                                  "connected to the database!";
        LOG_ERROR(error);
        throw std::runtime_error(error);
    }

    if (!inTransaction())
    {
        const std::string error = "Trying to rollback a transaction while no "
                                  "one is open!";
        LOG_ERROR(error);
        throw std::runtime_error(error);
    }

    if (mysql_rollback(mDb) != 0)
    {
        LOG_ERROR("MySqlDataProvider::rollbackTransaction: "
                  << mysql_error(mDb));
        throw DbSqlQueryExecFailure(mysql_error(mDb));
    }

    mysql_autocommit(mDb, AUTOCOMMIT_ON);
    mInTransaction = false;
    LOG_DEBUG("SQL: transaction rolled back");
}
Beispiel #7
0
/*	rollback()	*/
static VALUE rollback(VALUE obj)
{
    MYSQL* m = GetHandler(obj);
    if (mysql_rollback(m) != 0)
        mysql_raise(m);
    return obj;
}
Beispiel #8
0
void CMySQLConnection::rollback() throw (CDBException)
{
    MYSQL* mysql_handler = static_cast<MYSQL*>(_mysql_handler);

    if (mysql_rollback(mysql_handler) != 0)
        THROW_DB_EXCEPTION(NULL, mysql_error(mysql_handler), mysql_errno(mysql_handler));
}
Beispiel #9
0
int ExecuteModifyEx(MYSQL *pMySql, char **sSqlArray, int nSize)
{
	if (!sSqlArray || !pMySql || nSize <= 0)
	{
		ErrorInfor("ExecuteModifyEx", ERROR_ARGNULL);
		return 0;
	}

	for (int i = 0; i < nSize; i++)
	{
		if (mysql_query(pMySql, sSqlArray[i]) != 0)
		{
			ErrorInfor("ExecuteModifyEx-1", (char *)mysql_error(pMySql));

			if (mysql_rollback(pMySql) != 0)
			{
				ErrorInfor("ExecuteModifyEx-2", (char *)mysql_error(pMySql));
			}
			return 0;
		}
	}

	if (mysql_commit(pMySql) != 0)
	{
		ErrorInfor("ExecuteModifyEx-3", (char *)mysql_error(pMySql));
		return 0;
	}

	return 1;
}
Beispiel #10
0
/*
* Rollback the current transaction.
*/
static int Lmysql_rollback (lua_State *L) {
    lua_mysql_conn *my_conn = Mget_conn (L);
    if (mysql_rollback(my_conn->conn)) {
        return luaM_msg (L, 0, mysql_error(my_conn->conn));
    }
    return 0;
}
Beispiel #11
0
void DBConnection::RollBackTransaction() {
	if (!IsConnected()) {
		return;
	}
	mysql_rollback(m_pMysqlConn);
	mysql_autocommit(m_pMysqlConn, 1);
}
static ret_t
handle_error (cherokee_handler_dbslayer_t *hdl)
{
	int   re;
	char *tmp;

	/* Render error reply
	 */
	cherokee_dwriter_dict_open (&hdl->writer);
	add_cstr_int (&hdl->writer, "SUCCESS", false);
	add_cstr_int (&hdl->writer, "MYSQL_ERRNO", mysql_errno(hdl->conn));

	tmp = (char *)mysql_error (hdl->conn);
	add_cstr_str (&hdl->writer, "MYSQL_ERROR", tmp, strlen(tmp));

	/* Issue a rollback if needed
	 */
	if (hdl->rollback) {
		re = mysql_rollback (hdl->conn);

		add_cstr_int (&hdl->writer, "ROLLBACK_ON_ERROR", true);
		add_cstr_int (&hdl->writer, "ROLLBACK_ON_ERROR_SUCCESS", !re);
	}

	cherokee_dwriter_dict_close (&hdl->writer);
	return ret_ok;
}
Beispiel #13
0
uint32_t update_activity_status(i_mysql_iface *p_mysql_conn, c_memcached *p_memcached, uint32_t user_id, uint32_t msg_type, char *p_request_body, uint32_t request_len)
{
    single_activity_t *p_sa = (single_activity_t*)p_request_body;
    if(check_val_len(msg_type, request_len, sizeof(single_activity_t) + p_sa->kind_num * sizeof(single_reward_t)) != 0)
    {
        return ERR_MSG_LEN;
    }

    MYSQL *p_conn = p_mysql_conn->get_conn();
    if (NULL == p_conn)
    {
        KCRIT_LOG(user_id, "get mysql conn failed.");
        return ERR_SQL_ERR;
    }

    if (mysql_autocommit(p_conn, false) != 0)
    {
        KCRIT_LOG(user_id, "close mysql_autocommit failed.");
        return ERR_SQL_ERR;
    }

    for(uint16_t idx = 0; idx < p_sa->kind_num; idx++)
    {
		sprintf(g_sql_str, "INSERT INTO db_monster_%d.t_activity_%d(user_id, activity_id, reward_id, reward_num,  flag) values(%u, %u, %u, %u, %u) ON DUPLICATE KEY UPDATE flag = %u;", DB_ID(user_id), TABLE_ID(user_id), user_id, p_sa->activity_id, p_sa->reward[idx].reward_id, p_sa->reward[idx].reward_num, p_sa->reward[idx].reward_status, p_sa->reward[idx].reward_status);
		KINFO_LOG(user_id, "update open act_reward:%s", g_sql_str);
		if (p_mysql_conn->execsql(g_sql_str) < 0)
		{
			KCRIT_LOG(user_id, "[msg:%u]sql exec failed(%s).", msg_type, p_mysql_conn->get_last_errstr());
			mysql_rollback(p_conn);
			mysql_autocommit(p_conn, true);
			return ERR_SQL_ERR;
		}
    }
    // 结束事务
    if (mysql_commit(p_conn) != 0)
    {
        KCRIT_LOG(user_id, "mysql_commit() failed.");
        mysql_rollback(p_conn);
        mysql_autocommit(p_conn, true);
        return ERR_SQL_ERR;
    }

    mysql_autocommit(p_conn, true);

    g_pack.pack(p_request_body, request_len);
    return 0;
}
Beispiel #14
0
BOOL COpMySQL::ExecuteMulSQL(LPCTSTR szSql[], int iNum)
{
	char szTmp[512];
#ifdef _DEBUG	
	for(int i =0 ;i<iNum;i++)
	{
		sprintf(szTmp,"SQL[%d]:%s",i,szSql[i]);
		OutputDebugString(szTmp);
	}
#endif
	try
	{

		EnterCriticalSection(&m_csLock);
		mysql_autocommit(&m_connMysql,FALSE);
		for(int i = 0;i<iNum;i++)
		{
			if(mysql_real_query(&m_connMysql,szSql[i],strlen(szSql[i])) !=0)
			{
				sprintf(szTmp,"执行SQL语句失败,错误原因:%s",mysql_error(&m_connMysql));
				OutputDebugString(szTmp);
				mysql_rollback(&m_connMysql);
				LeaveCriticalSection(&m_csLock);
				return FALSE;
			}
		}
		
	
		
	}	
	catch (CException *e)
	{
		char szError[512] = {0};
		char szMsg[512] ={0};
		e->GetErrorMessage(szError,sizeof(szError));
		sprintf(szMsg,"执行多条SQL语句时发生异常,错误信息:%s",szError);
		OutputDebugString(szError);
		mysql_rollback(&m_connMysql);
		LeaveCriticalSection(&m_csLock);
		return FALSE;

	}
	mysql_commit(&m_connMysql);
	LeaveCriticalSection(&m_csLock);
	return TRUE;
	
}
Beispiel #15
0
void MysqlDatabase::rollback_transaction() {
  if (active)
  {
    mysql_rollback(conn);
    mysql_autocommit(conn, true);
    CLog::Log(LOGDEBUG,"Mysql rollback transaction");
    _in_transaction = false;
  }
}
Beispiel #16
0
/* {{{ mysql_handle_rollback */
static int mysql_handle_rollback(pdo_dbh_t *dbh)
{
	PDO_DBG_ENTER("mysql_handle_rollback");
	PDO_DBG_INF_FMT("dbh=%p", dbh);
#if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND)
	PDO_DBG_RETURN(0 <= mysql_rollback(((pdo_mysql_db_handle *)dbh->driver_data)->server));
#else
	PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("ROLLBACK")));
#endif
}
Beispiel #17
0
static int conn_rollback(lua_State* L)
{
    Connection* conn = check_conn(L);
    luaL_argcheck(L, conn && !conn->closed, 1, "invalid Connection object");
    if (mysql_rollback(&conn->my_conn) != 0)
    {
        return luaL_error(L, "rollback failed, %s\n", mysql_error(&conn->my_conn));
    }
    return 0;
}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void 
DatabaseTransaction::rollback()
{
    if( mysql_rollback(this->m_pConnection.get()) )
    {
        throw std::exception("Zen::ZMySQL::DatabaseTransaction::rollback() : Error rolling back transaction.");
    }
    this->m_isCommitted = false;
    this->m_isActive = false;
}
Beispiel #19
0
int
try_stmt_execute(MYSQL_STMT *mysql_stmt)
{
    int ret = mysql_stmt_execute(mysql_stmt);
    if (ret) {
        printf("\n%d, %s, %s\n", mysql_errno(mysql), mysql_sqlstate(mysql), mysql_error(mysql) );
        mysql_rollback(mysql);
    }
    return ret;
}
Beispiel #20
0
int do_mysql_rollback(const simple_list_node *node, void *data)
{
	MYSQL *con = (MYSQL *)node->data;
	if (mysql_rollback(con) != 0)
	{
		write_log(7, "rollback;");
		return 1;
	}
	return 0;
}
Beispiel #21
0
int wb_dbms_txn::abort()
{
    int rc = 0;

    rc = mysql_rollback(m_env->con());
    if (rc)
        printf("wb_dbms::abort, rc %d\n", rc);

    return rc;
}
	bool CDatabaseConnectionMySql::DoRollBack( const String & name )
	{
		bool result = mysql_rollback( _connection ) == 0;

		if ( result )
		{
			result = mysql_autocommit( _connection, true ) == 0;
		}

		return result;
	}
Beispiel #23
0
/*
 * success = connection:rollback()
 */
static int connection_rollback(lua_State *L) {
    connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_MYSQL_CONNECTION);
    int err = 0;

    if (conn->mysql) {
	err = mysql_rollback(conn->mysql);
    }

    lua_pushboolean(L, !err);
    return 1;
}
bool Database::rollback()
{
	if (mysql_rollback(m_handle) != 0) {
		std::cout << "[Error - mysql_rollback] Message: " << mysql_error(m_handle) << std::endl;
		database_lock.unlock();
		return false;
	}

	database_lock.unlock();
	return true;
}
bool CDBSrcMySql::Rollback(void)
{
	if (m_pDB == NULL) return false;
	if(mysql_rollback(m_pDB) == 0)
	{
		mysql_autocommit(m_pDB, 1);
		return true;
	}
	else
		return false;
}
Beispiel #26
0
uint32_t activity_update_dragon_boat_info(i_mysql_iface *p_mysql_conn, c_memcached *p_memcached, uint32_t user_id, uint32_t msg_type, char *p_request_body, uint32_t request_len)
{
    if(check_val_len(msg_type, request_len, sizeof(uint8_t)) != 0)
    {
        return ERR_MSG_LEN;
    }

	uint8_t level_id = *(uint8_t *)p_request_body;
 	uint8_t status = 0;
    MYSQL_ROW row = NULL;
	MYSQL *p_conn = NULL;

	sprintf(g_sql_str, "SELECT flag FROM db_monster_%d.t_activity_%d WHERE user_id = %u AND activity_id = %u AND reward_id = %u limit 1;", DB_ID(user_id), TABLE_ID(user_id),  user_id, DRAGON_BOAT_ACTIVITY_ID, level_id);
	int result_count = p_mysql_conn->select_first_row(&row, g_sql_str);
    if(result_count < 0)
    {
        KCRIT_LOG(user_id, "sql exev failed(%s)", g_sql_str);
        return ERR_SQL_ERR;
    }

	if(row)
	{
		status = 1;
	}
	else
	{
		p_conn = p_mysql_conn->get_conn();
		if (NULL == p_conn)
		{
			 KCRIT_LOG(user_id, "get mysql conn failed.");
			 return ERR_SQL_ERR;
		}

		if (mysql_autocommit(p_conn, false) != 0)
		{
			 KCRIT_LOG(user_id, "close mysql_autocommit failed.");
			 return ERR_SQL_ERR;
		}

		sprintf(g_sql_str, "INSERT INTO db_monster_%d.t_activity_%d(user_id, activity_id, reward_id, flag) VALUES(%u, %u, %u, 2);", DB_ID(user_id), TABLE_ID(user_id),	user_id, DRAGON_BOAT_ACTIVITY_ID, level_id);
		if (p_mysql_conn->execsql(g_sql_str) < 0)
		{
			 KCRIT_LOG(user_id, "[msg:%u]sql exec failed(%s).", msg_type, p_mysql_conn->get_last_errstr());
			 mysql_rollback(p_conn);
			 mysql_autocommit(p_conn, true);
			 return ERR_SQL_ERR;
		}
		mysql_autocommit(p_conn, true);
	}

	db_return_update_dragon_boat_t res = {level_id, status};
	g_pack.pack((char *)&res, sizeof(res));
    return 0;
}
Beispiel #27
0
bool COperMysql::RollBack()
{
	if(m_Commit)	//提交事务状态
	{
		return true;
	}
	if(mysql_rollback(m_PtrCon) == 0)
	{
		return true;
	}	
	return false;
}
Beispiel #28
0
bool DatabaseMySQL::rollback()
{
	if(!m_connected)
		return false;

	if(mysql_rollback(&m_handle))
	{
		std::clog << "mysql_rollback() - MYSQL ERROR: " << mysql_error(&m_handle) << " (" << mysql_errno(&m_handle) << ")" << std::endl;
		return false;
	}

	return true;
}
Beispiel #29
0
bool Mysql::rollback()
{
	my_bool result;

	result = mysql_rollback(this->db);
	this->endTransaction();
	if ( result != 0 )
	{
		KY_LOG_ERROR("mysql rollback transaction fail");
		return false;
	}

	return true;
}
Beispiel #30
0
static int test_wl4284_1(MYSQL *mysql)
{
  int rc;
  MYSQL_ROW row;
  MYSQL_RES *result;

  if (mysql_get_server_version(mysql) < 60000) {
    diag("Test requires MySQL Server version 6.0 or above");
    return SKIP;
  }

  /* set AUTOCOMMIT to OFF */
  rc= mysql_autocommit(mysql, FALSE);
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "DROP TABLE IF EXISTS trans");
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "CREATE TABLE trans (a INT) ENGINE= InnoDB");
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "INSERT INTO trans VALUES(1)");
  check_mysql_rc(rc, mysql);

  rc= mysql_refresh(mysql, REFRESH_GRANT | REFRESH_TABLES);
  check_mysql_rc(rc, mysql);

  rc= mysql_rollback(mysql);
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "SELECT * FROM trans");
  check_mysql_rc(rc, mysql);

  result= mysql_use_result(mysql);
  FAIL_IF(!result, "Invalid result set");

  row= mysql_fetch_row(result);
  FAIL_IF(!row, "Can't fetch row");

  mysql_free_result(result);

  /* set AUTOCOMMIT to OFF */
  rc= mysql_autocommit(mysql, FALSE);
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "DROP TABLE trans");
  check_mysql_rc(rc, mysql);

  return OK;
}