SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.41k stars 477 forks source link

how to exec sql << support dynamic variable params #977

Closed stan1334 closed 2 years ago

stan1334 commented 2 years ago
template<class ... Args>
inline void execSql(soci::session & sql, const std::string & strSql, Args &&...args) {
    try {
        if (0 < sizeof...(args))
            //sql << strSql, args...; ???
            int a = 10;
        else
            sql << strSql;
    }
    catch (soci_error const& e) {
        VLOG_E("HDCommon", "execSql what is {}", e.what());
    }

    VLOG_D("HDCommon", "execSql {} over", strSql);
}

define SOCI_EXEC(sql, strSql, ...) execSql(sql, strSql, __VA_ARGS__)

SOCI_EXEC(sql, SELECT_MAX_EVENTID_SQL, into(maxEventID)); SOCI_EXEC(sql, SELECT_MAX_EVENTID_SQL, into(maxEventID), use(111)); SOCI_EXEC(sql, SELECT_MAX_EVENTID_SQL, into(maxEventID), into(test222), use(test111) );

//sql << strSql, args...; ???

@mloskot @tt4g