| 168 | } |
| 169 | |
| 170 | bool |
| 171 | ECPGsetcommit(int lineno, const char *mode, const char *connection_name) |
| 172 | { |
| 173 | struct connection *con = ecpg_get_connection(connection_name); |
| 174 | PGresult *results; |
| 175 | |
| 176 | if (!ecpg_init(con, connection_name, lineno)) |
| 177 | return false; |
| 178 | |
| 179 | ecpg_log("ECPGsetcommit on line %d: action \"%s\"; connection \"%s\"\n", lineno, mode, con->name); |
| 180 | |
| 181 | if (con->autocommit && strncmp(mode, "off", strlen("off")) == 0) |
| 182 | { |
| 183 | if (PQtransactionStatus(con->connection) == PQTRANS_IDLE) |
| 184 | { |
| 185 | results = PQexec(con->connection, "begin transaction"); |
| 186 | if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL)) |
| 187 | return false; |
| 188 | PQclear(results); |
| 189 | } |
| 190 | con->autocommit = false; |
| 191 | } |
| 192 | else if (!con->autocommit && strncmp(mode, "on", strlen("on")) == 0) |
| 193 | { |
| 194 | if (PQtransactionStatus(con->connection) != PQTRANS_IDLE) |
| 195 | { |
| 196 | results = PQexec(con->connection, "commit"); |
| 197 | if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL)) |
| 198 | return false; |
| 199 | PQclear(results); |
| 200 | } |
| 201 | con->autocommit = true; |
| 202 | } |
| 203 | |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | bool |
| 208 | ECPGsetconn(int lineno, const char *connection_name) |