C++用pqxx写数据库

void PQUtil::updatePsql(std::string& path,std::vector<std::tuple<std::string,std::string>> codes){
    std::filesystem::path p(path);
    auto file = p.filename().string();
    try{
        pqxx::connection C;
        pqxx::work W{C};

        C.prepare("delete", "delete from psql where path = $1");
        W.exec_prepared("delete",path );

        C.prepare("insert", "insert into psql(path,name,describe,code) values($1,$2,$3,$4)");

        for(auto desc_code :codes){
            auto [desc,code] = desc_code;
            W.exec_prepared("insert",path,file,desc,code );
        }

        W.commit();
        std::cout << "OK.\n";
    }
    catch (std::exception const &e)
    {
        std::cerr << e.what() << '\n';
    }
}
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!