/sqlite3cc

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

« back to all changes in this revision

Viewing changes to include/sqlitepp/database.hpp

  • Committer: edam
  • Date: 2009-11-25 20:32:34 UTC
  • Revision ID: edam@waxworlds.org-20091125203234-24i7mzd60c7o46py
- initial commit
- basic support for: database, statements, commands, transactions, exceptions
- initial test app
- initial liscence and readme

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * connection.h
 
2
 * database.hpp
3
3
 *
4
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
5
 *
6
 
 * This file is part of sqlite3cc (hereafter referred to as "this program").
7
 
 * See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
 
6
 * This file is part of sqlitepp (hereafter referred to as "this program").
 
7
 * See http://www.waxworlds.org/edam/software/sqlitepp for more information.
8
8
 *
9
9
 * This program is free software: you can redistribute it and/or modify
10
10
 * it under the terms of the GNU Lesser General Public License as published
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 DATABASE_HPP_
 
24
#define DATABASE_HPP_
25
25
 
26
26
 
27
27
#include <sqlite3.h>
28
28
#include <boost/utility.hpp>
29
 
#include <string>
30
29
 
31
30
 
32
31
namespace sqlite
33
32
{
34
33
 
35
34
 
36
 
namespace detail {
37
 
        class basic_statement;
38
 
        class basic_transaction;
39
 
}
40
 
 
41
 
 
42
 
class connection
 
35
class statement;
 
36
class transaction;
 
37
 
 
38
 
 
39
class database
43
40
        :
44
41
        private boost::noncopyable
45
42
{
46
43
//______________________________________________________________________________
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
44
//                                                                 instantiation
80
45
public:
81
46
 
84
49
         * @param filename the filename of the database file to open
85
50
         * @throws database_error on error
86
51
         */
87
 
        explicit connection(
 
52
        database(
88
53
                const std::string &filename );
89
54
 
90
 
        explicit connection();
91
 
        virtual ~connection();
 
55
        database();
 
56
        virtual ~database() throw( );
92
57
 
93
58
//______________________________________________________________________________
94
59
//                                                              public interface
113
78
        void close();
114
79
 
115
80
        /**
116
 
         * Execute an SQL statement. An exception is thrown on error.
 
81
         * Execute an SQL statement.
117
82
         * @param sql an SQL statement in UTF-8
 
83
         * @return an sqlite error code
118
84
         * @see sqlite3_exc()
119
85
         */
120
 
        void exec(
 
86
        int exec(
121
87
                const std::string &sql );
122
88
 
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
         */
134
100
//                                                                implementation
135
101
private:
136
102
 
137
 
        friend class detail::basic_statement;
138
 
        friend class detail::basic_transaction;
139
 
        friend class command;
140
 
        friend class sqlite_error;
 
103
        friend class statement;
 
104
        friend class transaction;
141
105
 
142
 
        /** the connection handle */
 
106
        /** the database handle */
143
107
        sqlite3 *_handle;
144
108
 
145
109
};
146
110
 
147
111
 
148
 
} // namespace sqlite
149
 
 
150
 
 
151
 
#endif /* SQLITE3CC_CONNECTION_H_ */
 
112
}
 
113
 
 
114
 
 
115
#endif /* DATABASE_HPP_ */