• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SRombauts / SQLiteCpp / #613698365

22 Nov 2023 10:24AM UTC coverage: 98.238%. First build
#613698365

travis-ci

669 of 681 relevant lines covered (98.24%)

29.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/include/SQLiteCpp/Savepoint.h
1
/**
2
 * @file    Savepoint.h
3
 * @ingroup SQLiteCpp
4
 * @brief   A Savepoint is a way to group multiple SQL statements into an atomic
5
 * secured operation. Similar to a transaction while allowing child savepoints.
6
 *
7
 * Copyright (c) 2020 Kelvin Hammond (hammond.kelvin@gmail.com)
8
 * Copyright (c) 2020-2025 Sebastien Rombauts (sebastien.rombauts@gmail.com)
9
 *
10
 * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or
11
 * copy at http://opensource.org/licenses/MIT)
12
 */
13
#pragma once
14

15
#include <SQLiteCpp/SQLiteCppExport.h>
16
#include <SQLiteCpp/Exception.h>
17

18
namespace SQLite
19
{
20

21
// Forward declaration
22
class Database;
23

24
/**
25
 * @brief RAII encapsulation of a SQLite Savepoint.
26
 *
27
 * SAVEPOINTs are a method of creating Transactions, similar to BEGIN and COMMIT,
28
 * except that the SAVEPOINT and RELEASE commands are named and may be nested..
29
 *
30
 * Resource Acquisition Is Initialization (RAII) means that the Savepoint
31
 * begins in the constructor and is rolled back in the destructor (unless committed before), so that there is
32
 * no need to worry about memory management or the validity of the underlying SQLite Connection.
33
 *
34
 * This method also offers big performances improvements compared to
35
 * individually executed statements.
36
 *
37
 * Caveats:
38
 *
39
 * 1) Calling COMMIT or committing a parent transaction or RELEASE on a parent
40
 * savepoint will cause this savepoint to be released.
41
 *
42
 * 2) Calling ROLLBACK TO or rolling back a parent savepoint will cause this
43
 * savepoint to be rolled back.
44
 *
45
 * 3) This savepoint is not saved to the database until this and all savepoints
46
 * or transaction in the savepoint stack have been released or committed.
47
 *
48
 * See also: https://sqlite.org/lang_savepoint.html
49
 *
50
 * Thread-safety: a Savepoint object shall not be shared by multiple threads, because:
51
 * 1) in the SQLite "Thread Safe" mode, "SQLite can be safely used by multiple threads
52
 *    provided that no single database connection is used simultaneously in two or more threads."
53
 * 2) the SQLite "Serialized" mode is not supported by SQLiteC++,
54
 *    because of the way it shares the underling SQLite precompiled statement
55
 *    in a custom shared pointer (See the inner class "Statement::Ptr").
56
 */
57
class SQLITECPP_API Savepoint
58
{
59
public:
60
    /**
61
     * @brief Begins the SQLite savepoint
62
     *
63
     * @param[in] aDatabase the SQLite Database Connection
64
     * @param[in] aName the name of the Savepoint
65
     *
66
     * Exception is thrown in case of error, then the Savepoint is NOT
67
     * initiated.
68
     */
69
    Savepoint(Database& aDatabase, const std::string& aName);
70

71
    // Savepoint is non-copyable
72
    Savepoint(const Savepoint&) = delete;
73
    Savepoint& operator=(const Savepoint&) = delete;
74

75
    /**
76
     * @brief Safely rollback the savepoint if it has not been committed.
77
     */
78
    ~Savepoint();
79

80
    /**
81
     * @brief Commit and release the savepoint.
82
     */
83
    void release();
84

85
    /**
86
     * @brief Rollback to the savepoint, but don't release it.
87
     */
88
    void rollbackTo();
89
    // @deprecated same as rollbackTo();
90
    void rollback() { rollbackTo(); }
5✔
91

92
private:
93
    Database&   mDatabase;          ///< Reference to the SQLite Database Connection
94
    std::string msName;             ///< Name of the Savepoint
95
    bool        mbReleased = false; ///< True when release has been called
96
};
97

98
}  // namespace SQLite
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc