diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-04-19 11:14:33 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-04-19 11:14:33 +0200 |
commit | a5923caf474983e14477498117fabb041805fd04 (patch) | |
tree | e6a40a174d064acb2c7ab5a3b1e6366193b8b7d8 /pgsql.c | |
parent | 4a88c817b17498e72a95589f887197ab43edc491 (diff) | |
download | pgfuse-a5923caf474983e14477498117fabb041805fd04.tar.gz pgfuse-a5923caf474983e14477498117fabb041805fd04.tar.bz2 |
added first simple transaction policy (per FUSE operation)
Diffstat (limited to 'pgsql.c')
-rw-r--r-- | pgsql.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -641,3 +641,51 @@ int psql_truncate( PGconn *conn, const int id, const char *path, const off_t off return 0; } + +int psql_begin( PGconn *conn ) +{ + PGresult *res; + + res = PQexec( conn, "BEGIN" ); + + if( PQresultStatus( res ) != PGRES_COMMAND_OK ) { + syslog( LOG_ERR, "Begin of transaction failed!!" ); + return -EIO; + } + + PQclear( res ); + + return 0; +} + +int psql_commit( PGconn *conn ) +{ + PGresult *res; + + res = PQexec( conn, "COMMIT" ); + + if( PQresultStatus( res ) != PGRES_COMMAND_OK ) { + syslog( LOG_ERR, "Commit of transaction failed!!" ); + return -EIO; + } + + PQclear( res ); + + return 0; +} + +int psql_rollback( PGconn *conn ) +{ + PGresult *res; + + res = PQexec( conn, "ROLLBACK" ); + + if( PQresultStatus( res ) != PGRES_COMMAND_OK ) { + syslog( LOG_ERR, "Rollback of transaction failed!!" ); + return -EIO; + } + + PQclear( res ); + + return 0; +} |