/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/connection.h

  • Committer: edam
  • Date: 2012-01-23 13:46:27 UTC
  • Revision ID: edam@waxworlds.org-20120123134627-i6hi9aftfvwgp8vw
updated autotols stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * database.h
 
2
 * connection.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_DATABASE_H_
24
 
#define SQLITE3CC_DATABASE_H_
 
23
#ifndef SQLITE3CC_CONNECTION_H_
 
24
#define SQLITE3CC_CONNECTION_H_
25
25
 
26
26
 
27
27
#include <sqlite3.h>
33
33
{
34
34
 
35
35
 
36
 
class basic_statement;
37
 
class basic_transaction;
38
 
 
39
 
 
40
 
class database
 
36
namespace detail {
 
37
        class basic_statement;
 
38
        class basic_transaction;
 
39
}
 
40
 
 
41
 
 
42
class connection
41
43
        :
42
44
        private boost::noncopyable
43
45
{
44
46
//______________________________________________________________________________
 
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
//______________________________________________________________________________
45
79
//                                                                 instantiation
46
80
public:
47
81
 
50
84
         * @param filename the filename of the database file to open
51
85
         * @throws database_error on error
52
86
         */
53
 
        explicit database(
 
87
        explicit connection(
54
88
                const std::string &filename );
55
89
 
56
 
        explicit database();
57
 
        virtual ~database();
 
90
        explicit connection();
 
91
        virtual ~connection();
58
92
 
59
93
//______________________________________________________________________________
60
94
//                                                              public interface
89
123
        /**
90
124
         * Sets a default busy handler which will
91
125
         * wait for the specified number of milliseconds.
92
 
         * @param milliseconds number of milliseconds to wait
 
126
         * @param duration number of milliseconds to wait
93
127
         * @returns an sqlite error code
94
128
         * @see sqlite3_busy_timeout()
95
129
         */
98
132
 
99
133
//______________________________________________________________________________
100
134
//                                                                implementation
101
 
protected:
 
135
private:
102
136
 
103
 
        friend class basic_statement;
104
 
        friend class basic_transaction;
 
137
        friend class detail::basic_statement;
 
138
        friend class detail::basic_transaction;
105
139
        friend class command;
106
 
        friend class query;
107
140
        friend class sqlite_error;
108
141
 
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 */
 
142
        /** the connection handle */
130
143
        sqlite3 *_handle;
131
144
 
132
145
};
135
148
} // namespace sqlite
136
149
 
137
150
 
138
 
#endif /* SQLITE3CC_DATABASE_H_ */
 
151
#endif /* SQLITE3CC_CONNECTION_H_ */