viabtc / viabtc_exchange_server

A trading engine with high-speed performance and real-time notification
MIT License
2.68k stars 1.49k forks source link

balance.history 接口中的 business 参数查询多项内容 #97

Closed tornodo closed 6 years ago

tornodo commented 6 years ago

rh_reader.c里面方法get_user_balance_history中

    size_t business_len = strlen(business); 
    if (business_len > 0) { 
        char _business[2 * business_len + 1]; 
        mysql_real_escape_string(conn, _business, business, strlen(business)); 
        sql = sdscatprintf(sql, " AND `business` = '%s'", _business); 
    }

并没有把business参数当作数组来处理,与wiki上描述不符吧。我想同时查成交、提现、充值就没有办法来,只能一条一条来。

@haipome

haipome commented 6 years ago

是的,这里最初的实现是按照列表来的,后来担心性能问题改为了只能查询一个。如果需要的话,你自己可以改一下。

tornodo commented 6 years ago

收到。

tornodo commented 6 years ago
size_t business_len = strlen(business);
    if (business_len > 0) {
        int _busLen = 2 * business_len + 1;
        char _business[_busLen];
        mysql_real_escape_string(conn, _business, business, business_len);
        int count = 0;
        sds* businessArray = sdssplitlen(_business, _busLen, ",", 1, &count);
        if (count > 0) {
            sds sql_business = sdsempty();
            sql_business = sdscatprintf(sql_business, " AND (`business` = '%s'", businessArray[0]);
            for (int i = 1;i < count;i++) {
                sql_business = sdscatprintf(sql_business, " OR `business` = '%s'", businessArray[i]);
            }
            sql = sdscatprintf(sql, " %s)", sql_business);
            sdsfree(sql_business);
        } else {
            sql = sdscatprintf(sql, " AND `business` = '%s'", _business);
        }
        sdsfreesplitres(businessArray, count);
    }

改了改,仅供参考😄