- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdbprepared.cpp
More file actions
Latest commit
27 lines (22 loc) · 632 Bytes
/
Copy pathdbprepared.cpp
File metadata and controls
27 lines (22 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include"dbprepared.h"
#include"dbcommon.h"
#include<iostream>
#include<map>
#include<mutex>
usingnamespacestd;
static std::map<std::string, std::string> keyToSql;
static std::mutex keyToSqlMutex;
voidprepare_deduplicated(pqxx::connection &c, std::string key, std::string sql)
{
//cout << "prepare " << key << " " << sql << endl;
std::lock_guard<std::mutex> lock(keyToSqlMutex);
auto existing = keyToSql.find(key);
if (existing != keyToSql.end())
{
if (existing->second != sql)
throwruntime_error("SQL statement in prepared statement has changed");
return;
}
c.prepare(key, sql);
keyToSql[key] = sql;
}