| 175 | } |
| 176 | |
| 177 | IDatabase *PgDriver::Connect(const DatabaseInfo *info, bool persistent, char *error, size_t maxlength) |
| 178 | { |
| 179 | std::lock_guard<std::mutex> lock(m_Lock); |
| 180 | |
| 181 | if (persistent) |
| 182 | { |
| 183 | /* Try to find a matching persistent connection */ |
| 184 | List<PgDatabase *>::iterator iter; |
| 185 | for (iter=m_PermDbs.begin(); |
| 186 | iter!=m_PermDbs.end(); |
| 187 | iter++) |
| 188 | { |
| 189 | PgDatabase *db = (*iter); |
| 190 | const DatabaseInfo &other = db->GetInfo(); |
| 191 | if (CompareField(info->host, other.host) |
| 192 | && CompareField(info->user, other.user) |
| 193 | && CompareField(info->pass, other.pass) |
| 194 | && CompareField(info->database, other.database) |
| 195 | && (info->port == other.port)) |
| 196 | { |
| 197 | db->IncReferenceCount(); |
| 198 | return db; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | PGconn *pgsql = ::Connect(info, error, maxlength); |
| 204 | if (!pgsql) |
| 205 | { |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | PgDatabase *db = new PgDatabase(pgsql, info, persistent); |
| 210 | |
| 211 | if (persistent) |
| 212 | { |
| 213 | m_PermDbs.push_back(db); |
| 214 | } |
| 215 | |
| 216 | return db; |
| 217 | } |
| 218 | |
| 219 | void PgDriver::RemoveFromList(PgDatabase *pdb, bool persistent) |
| 220 | { |
nothing calls this directly
no test coverage detected