-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCPostgresManager.cpp
More file actions
72 lines (58 loc) · 1.65 KB
/
CPostgresManager.cpp
File metadata and controls
72 lines (58 loc) · 1.65 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
61
62
63
64
65
66
67
68
69
70
71
72
/*********************************************************
*
* Multi Theft Auto: San Andreas - Deathmatch
*
* ml_base, External lua add-on module
*
* Copyright (c) 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is (c) 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
* PROVIDED WITH THIS PACKAGE.
*
*********************************************************/
#include "CPostgresManager.hpp"
CPostgresManager::CPostgresManager()
{
}
CPostgresManager::~CPostgresManager()
{
CloseAllConnections();
}
CPostgresConnection* CPostgresManager::NewConnection(lua_State* pLuaVM)
{
const char* szConnectionInfo = luaL_checkstring(pLuaVM, 1);
CPostgresConnection* pConnection = new CPostgresConnection(pLuaVM, szConnectionInfo);
g_pPostgresManager->Add(pConnection);
return pConnection;
}
void CPostgresManager::CloseAllConnections(lua_State* pLuaVM)
{
int i = 0;
for (auto& connection : m_vecConnections)
{
if (!pLuaVM || (connection && connection->GetVM() == pLuaVM))
{
SAFE_DELETE(connection);
m_vecConnections.erase(m_vecConnections.begin() + i);
}
i++;
}
}
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++;
}
}