diff options
| author | David Sommerseth <davids@redhat.com> | 2009-10-14 20:00:24 +0200 |
|---|---|---|
| committer | David Sommerseth <davids@redhat.com> | 2009-10-14 20:00:24 +0200 |
| commit | b99c0760b814c39163ad46e4793fbe1bc8c507f2 (patch) | |
| tree | 2508682ca288882d1eda98a8e96e7193c7b8011a /server/parser/pgsql.c | |
| parent | 53a8294f6ad7068336806979d55222073ba01f17 (diff) | |
| download | rteval-b99c0760b814c39163ad46e4793fbe1bc8c507f2.tar.gz rteval-b99c0760b814c39163ad46e4793fbe1bc8c507f2.tar.xz rteval-b99c0760b814c39163ad46e4793fbe1bc8c507f2.zip | |
Added db_begin(), db_rollback() and db_commit() functions
Diffstat (limited to 'server/parser/pgsql.c')
| -rw-r--r-- | server/parser/pgsql.c | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/server/parser/pgsql.c b/server/parser/pgsql.c index d3ead49..0d1ccd8 100644 --- a/server/parser/pgsql.c +++ b/server/parser/pgsql.c @@ -312,10 +312,76 @@ eurephiaVALUES *pgsql_INSERT(PGconn *dbc, xmlDoc *sqldoc) { /** + * Start an SQL transaction (SQL BEGIN) + * + * @param dbc Database handler where to perform the SQL queries + * + * @return Returns 1 on success, otherwise -1 is returned + */ +int db_begin(dbconn *dbc) { + PGresult *dbres = NULL; + + dbres = PQexec((PGconn *) dbc, "BEGIN"); + if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { + fprintf(stderr, "** ERROR ** Failed to do prepare a transaction (BEGIN)\n%s\n", + PQresultErrorMessage(dbres)); + PQclear(dbres); + return -1; + } + PQclear(dbres); + return 1; +} + + +/** + * Commits an SQL transaction (SQL COMMIT) + * + * @param dbc Database handler where to perform the SQL queries + * + * @return Returns 1 on success, otherwise -1 is returned + */ +int db_commit(dbconn *dbc) { + PGresult *dbres = NULL; + + dbres = PQexec((PGconn *) dbc, "COMMIT"); + if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { + fprintf(stderr, "** ERROR ** Failed to do commit a database transaction (COMMIT)\n%s\n", + PQresultErrorMessage(dbres)); + PQclear(dbres); + return -1; + } + PQclear(dbres); + return 1; +} + + +/** + * Aborts an SQL transaction (SQL ROLLBACK/ABORT) + * + * @param dbc Database handler where to perform the SQL queries + * + * @return Returns 1 on success, otherwise -1 is returned + */ +int db_rollback(dbconn *dbc) { + PGresult *dbres = NULL; + + dbres = PQexec((PGconn *) dbc, "ROLLBACK"); + if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { + fprintf(stderr, "** ERROR ** Failed to do abort/rollback a transaction (ROLLBACK)\n%s\n", + PQresultErrorMessage(dbres)); + PQclear(dbres); + return -1; + } + PQclear(dbres); + return 1; +} + + +/** * Registers information into the 'systems' and 'systems_hostname' tables, based on the * summary/report XML file from rteval. * - * @param dbc Database handler where to perform the SQL queries + * @param dbc Database handler where to perform the SQL queries * @param xslt A pointer to a parsed 'xmlparser.xsl' XSLT template * @param summaryxml The XML report from rteval * |
