/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: 2010-07-29 20:56:19 UTC
  • Revision ID: edam@waxworlds.org-20100729205619-a9yo4uzu647nvnsj
- renamed database to connection to better identify what it is (would database_connection be better though?)
- moved basic_statement and basic_transaction to sqlite::detail
- made sqlite::threadsafe() return the threading mode int, not a bool
- renamed row::index() to row_number() so it isn't confused with column index
- added typedef for deferred_transaction
- added early rollback method to transaction_guard
- allowed transaction_guard::~transaction_guard() to throw exceptions, since when it needs to, we're really screwed anyway
- bugfix: query::reset() didn't reset the internal row counter
- added query::num_results()
- added docs/design-notes
- reimplemented query::iterator so that increment() (which performs a step() on the query) now caches the returned row to be returned during dereference() (previously it stashed details and returned new row!?)
- bugfix: resetting active queries during rollbacks would hang!

Show diffs side-by-side

added added

removed removed

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;
 
140
        friend class sqlite_error;
105
141
 
106
 
        /** the database handle */
 
142
        /** the connection handle */
107
143
        sqlite3 *_handle;
108
144
 
109
145
};
112
148
} // namespace sqlite
113
149
 
114
150
 
115
 
#endif /* SQLITE3CC_DATABASE_H_ */
 
151
#endif /* SQLITE3CC_CONNECTION_H_ */