/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>
28
28
#include <boost/utility.hpp>
 
29
#include <string>
29
30
 
30
31
 
31
32
namespace sqlite
32
33
{
33
34
 
34
35
 
35
 
class basic_statement;
36
 
class transaction;
37
 
 
38
 
 
39
 
class database
 
36
namespace detail {
 
37
        class basic_statement;
 
38
        class basic_transaction;
 
39
}
 
40
 
 
41
 
 
42
class connection
40
43
        :
41
44
        private boost::noncopyable
42
45
{
43
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
//______________________________________________________________________________
44
79
//                                                                 instantiation
45
80
public:
46
81
 
49
84
         * @param filename the filename of the database file to open
50
85
         * @throws database_error on error
51
86
         */
52
 
        explicit database(
 
87
        explicit connection(
53
88
                const std::string &filename );
54
89
 
55
 
        explicit database();
56
 
        virtual ~database() throw( );
 
90
        explicit connection();
 
91
        virtual ~connection();
57
92
 
58
93
//______________________________________________________________________________
59
94
//                                                              public interface
78
113
        void close();
79
114
 
80
115
        /**
81
 
         * Execute an SQL statement.
 
116
         * Execute an SQL statement. An exception is thrown on error.
82
117
         * @param sql an SQL statement in UTF-8
83
 
         * @return an sqlite error code
84
118
         * @see sqlite3_exc()
85
119
         */
86
 
        int exec(
 
120
        void exec(
87
121
                const std::string &sql );
88
122
 
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
         */
100
134
//                                                                implementation
101
135
private:
102
136
 
103
 
        friend class basic_statement;
 
137
        friend class detail::basic_statement;
 
138
        friend class detail::basic_transaction;
104
139
        friend class command;
105
 
        friend class transaction;
 
140
        friend class sqlite_error;
106
141
 
107
 
        /** the database handle */
 
142
        /** the connection handle */
108
143
        sqlite3 *_handle;
109
144
 
110
145
};
113
148
} // namespace sqlite
114
149
 
115
150
 
116
 
#endif /* SQLITE3CC_DATABASE_H_ */
 
151
#endif /* SQLITE3CC_CONNECTION_H_ */