-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCPostgresManager.cpp
More file actions
60 lines (48 loc) · 1.35 KB
/
CPostgresManager.cpp
File metadata and controls
60 lines (48 loc) · 1.35 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "CPostgresManager.h"
#include <algorithm>
CPostgresManager::CPostgresManager()
{
}
CPostgresManager::~CPostgresManager()
{
CloseAllConnections();
}
CPostgresConnection* CPostgresManager::NewConnection(lua_State* pLuaVM)
{
const char* szConnectionInfo = luaL_checkstring(pLuaVM, 1);
CPostgresConnection* pConnection = new CPostgresConnection(pLuaVM, szConnectionInfo);
if (pConnection && pConnection->IsConnected())
g_pPostgresManager->Add(pConnection);
return pConnection;
}
void CPostgresManager::CloseAllConnections(lua_State* pLuaVM)
{
m_vecConnections.erase(
std::remove_if(
m_vecConnections.begin(),
m_vecConnections.end(),
[=](auto& pConnection) -> bool {
if (!pLuaVM || (pConnection && pConnection->GetVM() == pLuaVM))
{
SAFE_DELETE(pConnection);
return true;
}
return false;
}
),
m_vecConnections.end()
);
}
void CPostgresManager::RemoveConnection(CPostgresConnection* pConnection)
{
int i = 0;
for (auto& connection : m_vecConnections)
{
if(pConnection == connection)
{
SAFE_DELETE(connection);
m_vecConnections.erase(m_vecConnections.begin() + i);
}
i++;
}
}