| 116 } |
116 } |
| 117 pool_free(pg->pool, res); |
117 pool_free(pg->pool, res); |
| 118 } |
118 } |
| 119 |
119 |
| 120 int pg_resourcepool_prepare(PgResourcePool *pg, PgResource *res) { |
120 int pg_resourcepool_prepare(PgResourcePool *pg, PgResource *res) { |
| |
121 if(PQstatus(res->connection) != CONNECTION_OK) { |
| |
122 log_ereport(LOG_WARN, "pg_resourcepool_prepare: connection not ok"); |
| |
123 // try to recreate the resource |
| |
124 PQfinish(res->connection); |
| |
125 res->connection = PQconnectdb(pg->connection); |
| |
126 if(pg_check_connection(LOG_FAILURE, pg->name, res->connection)) { |
| |
127 return 1; |
| |
128 } |
| |
129 } |
| |
130 |
| 121 PGresult *result = PQexec(res->connection, "BEGIN"); |
131 PGresult *result = PQexec(res->connection, "BEGIN"); |
| 122 PQclear(result); // TODO: handle error |
132 PQclear(result); // TODO: handle error |
| 123 return 0; |
133 return 0; |
| 124 } |
134 } |
| 125 |
135 |