Dam*_*mir 5 c++ postgresql libpqxx c++11
如何IN使用pqxxin c++for在 sql 查询中执行postgresql?我有vector<long>id,我需要更新表学生中的每一行(设置faculty_id为一些新值)。我想避免循环,faculty当我用prepared INSERT语句插入教师时得到的新值(_id)。是否可以prepared IN使用 pqxx传递如此可迭代的结构或创建查询?
void prepareChangeFaculty(connection_base &c){
const std::string sql =
"UPDATE students SET faculty_id=$2 WHERE id IN $1"; // here is a problem
c.prepare("change_faculty", sql);
}
Run Code Online (Sandbox Code Playgroud)
$1 我喜欢我需要更新的行的 id 向量
为什么不在C++11 中使用类似的东西(How to concatenate a std::string and an int? )
string a="";
for (int k=0;k<myVector.size();k++){
a += string(myVector[k]);
if (k<myVector.size()-1){
a += ",";
}
}
std::string sql = "UPDATE students SET faculty_id=$2 WHERE id IN (" + a + ")";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
958 次 |
| 最近记录: |