postgresql的transaction

postgresql的transaction,第1张

概述从odb的源码中看出了,其实和其它的数据库一样,也都是三条命令。 // file      : odb/pgsql/transaction-impl.cxx // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC // license   : GNU GPL v2; see accompanying LICENSE file #

从odb的源码中看出了,其实和其它的数据库一样,也都是三条命令。


// file : odb/pgsql/transaction-impl.cxx

// copyright : copyright (c) 2009-2013 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying liCENSE file


#include <cassert>


#include <libpq-fe.h>


#include <odb/tracer.hxx>


#include <odb/pgsql/database.hxx>
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/error.hxx>
#include <odb/pgsql/exceptions.hxx>
#include <odb/pgsql/transaction-impl.hxx>
#include <odb/pgsql/auto-handle.hxx>


namespace odb
{
namespace pgsql
{
transaction_impl::
transaction_impl (database_type& db)
: odb::transaction_impl (db)
{

}


transaction_impl::
transaction_impl (connection_ptr c)
: odb::transaction_impl (c->database (),*c),connection_ (c)
{
}


transaction_impl::
~transaction_impl ()
{
}


voID transaction_impl::
start ()
{
// Grab a connection if we don't already have one.
//
if (connection_ == 0)
{
connection_ = static_cast<database_type&> (database_).connection ();
odb::transaction_impl::connection_ = connection_.get ();
}


{
odb::tracer* t;
if ((t = connection_->tracer ()) || (t = database_.tracer ()))
t->execute (*connection_,"BEGIN");
}


auto_handle<PGresult> h (PQexec (connection_->handle (),"begin"));


if (!h || PGRES_COMMAND_OK != PQresultStatus (h))
translate_error (*connection_,h);
}


voID transaction_impl::
commit ()
{
// InvalIDate query results.
//
connection_->invalIDate_results ();


{
odb::tracer* t;
if ((t = connection_->tracer ()) || (t = database_.tracer ()))
t->execute (*connection_,"COMMIT");
}


auto_handle<PGresult> h (PQexec (connection_->handle (),"commit"));


if (!h || PGRES_COMMAND_OK != PQresultStatus (h))
translate_error (*connection_,h);


// Release the connection.
//
connection_.reset ();
}


voID transaction_impl::
rollback ()
{
// InvalIDate query results.
//
connection_->invalIDate_results ();


{
odb::tracer* t;
if ((t = connection_->tracer ()) || (t = database_.tracer ()))
t->execute (*connection_,"RolLBACK");
}

auto_handle<PGresult> h (PQexec (connection_->handle (),"rollback")); if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) translate_error (*connection_,h); // Release the connection. // connection_.reset (); } } } 总结

以上是内存溢出为你收集整理的postgresql的transaction全部内容,希望文章能够帮你解决postgresql的transaction所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1176453.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存