/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to include/sqlite3cc/database.h

  • Committer: edam
  • Date: 2010-07-29 06:28:53 UTC
  • Revision ID: edam@waxworlds.org-20100729062853-4i2fec52m86mh724
- made basic_statement::step() protected, for use by query and command only
- moved basic_statement::operator<<() to command and query instead; one needs to accept sqlite::exec, the other doesn't
- added tests for query::operator<<()
- added code to invlaidate in-progress queries during any transaction rollbacks (currently segfaults in basic_statement::finalize())
- added new sqlite_error constructor that obtains a full error message
- implemented database::database_mutex_guard class
- swapped command's step mutex in favour of the database mutex

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * connection.h
 
2
 * database.h
3
3
 *
4
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
5
 *
20
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
 */
22
22
 
23
 
#ifndef SQLITE3CC_CONNECTION_H_
24
 
#define SQLITE3CC_CONNECTION_H_
 
23
#ifndef SQLITE3CC_DATABASE_H_
 
24
#define SQLITE3CC_DATABASE_H_
25
25
 
26
26
 
27
27
#include <sqlite3.h>
33
33
{
34
34
 
35
35
 
36
 
namespace detail {
37
 
        class basic_statement;
38
 
        class basic_transaction;
39
 
}
40
 
 
41
 
 
42
 
class connection
 
36
class basic_statement;
 
37
class basic_transaction;
 
38
 
 
39
 
 
40
class database
43
41
        :
44
42
        private boost::noncopyable
45
43
{
46
44
//______________________________________________________________________________
47
 
//                                                                         types
48
 
public:
49
 
 
50
 
        /**
51
 
         * Class to provide a scope lock for the connection mutex
52
 
         */
53
 
        class mutex_guard
54
 
        {
55
 
        public:
56
 
 
57
 
                /**
58
 
                 * Constructor that provides a connection upon which to act
59
 
                 * @param connection reference to a connection
60
 
                 * @see sqlite3_db_mutex()
61
 
                 * @see sqlite3_mutex_enter()
62
 
                 */
63
 
                mutex_guard(
64
 
                        connection &connection );
65
 
 
66
 
                ~mutex_guard();
67
 
 
68
 
                /**
69
 
                 * Release the mutex early
70
 
                 * @see sqlite3_mutex_leave()
71
 
                 */
72
 
                void leave();
73
 
 
74
 
        private:
75
 
                sqlite3_mutex *_mutex;
76
 
        };
77
 
 
78
 
//______________________________________________________________________________
79
45
//                                                                 instantiation
80
46
public:
81
47
 
84
50
         * @param filename the filename of the database file to open
85
51
         * @throws database_error on error
86
52
         */
87
 
        explicit connection(
 
53
        explicit database(
88
54
                const std::string &filename );
89
55
 
90
 
        explicit connection();
91
 
        virtual ~connection();
 
56
        explicit database();
 
57
        virtual ~database();
92
58
 
93
59
//______________________________________________________________________________
94
60
//                                                              public interface
123
89
        /**
124
90
         * Sets a default busy handler which will
125
91
         * wait for the specified number of milliseconds.
126
 
         * @param duration number of milliseconds to wait
 
92
         * @param milliseconds number of milliseconds to wait
127
93
         * @returns an sqlite error code
128
94
         * @see sqlite3_busy_timeout()
129
95
         */
132
98
 
133
99
//______________________________________________________________________________
134
100
//                                                                implementation
135
 
private:
 
101
protected:
136
102
 
137
 
        friend class detail::basic_statement;
138
 
        friend class detail::basic_transaction;
 
103
        friend class basic_statement;
 
104
        friend class basic_transaction;
139
105
        friend class command;
 
106
        friend class query;
140
107
        friend class sqlite_error;
141
108
 
142
 
        /** the connection handle */
 
109
        /** class to provide a scope lock for the database mutex */
 
110
        class database_mutex_guard
 
111
        {
 
112
        public:
 
113
 
 
114
                /** constructor that provides a database */
 
115
                database_mutex_guard(
 
116
                        database &database );
 
117
 
 
118
                ~database_mutex_guard();
 
119
 
 
120
                /** release the mutex early */
 
121
                void leave();
 
122
 
 
123
        private:
 
124
                sqlite3_mutex *_mutex;
 
125
        };
 
126
 
 
127
private:
 
128
 
 
129
        /** the database handle */
143
130
        sqlite3 *_handle;
144
131
 
145
132
};
148
135
} // namespace sqlite
149
136
 
150
137
 
151
 
#endif /* SQLITE3CC_CONNECTION_H_ */
 
138
#endif /* SQLITE3CC_DATABASE_H_ */