/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
 
 * database.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_DATABASE_H_
24
 
#define SQLITE3CC_DATABASE_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
 
class basic_statement;
37
 
class basic_transaction;
 
35
class statement;
 
36
class transaction;
38
37
 
39
38
 
40
39
class database
50
49
         * @param filename the filename of the database file to open
51
50
         * @throws database_error on error
52
51
         */
53
 
        explicit database(
 
52
        database(
54
53
                const std::string &filename );
55
54
 
56
 
        explicit database();
57
 
        virtual ~database();
 
55
        database();
 
56
        virtual ~database() throw( );
58
57
 
59
58
//______________________________________________________________________________
60
59
//                                                              public interface
79
78
        void close();
80
79
 
81
80
        /**
82
 
         * Execute an SQL statement. An exception is thrown on error.
 
81
         * Execute an SQL statement.
83
82
         * @param sql an SQL statement in UTF-8
 
83
         * @return an sqlite error code
84
84
         * @see sqlite3_exc()
85
85
         */
86
 
        void exec(
 
86
        int exec(
87
87
                const std::string &sql );
88
88
 
89
89
        /**
98
98
 
99
99
//______________________________________________________________________________
100
100
//                                                                implementation
101
 
protected:
102
 
 
103
 
        friend class basic_statement;
104
 
        friend class basic_transaction;
105
 
        friend class command;
106
 
        friend class query;
107
 
        friend class sqlite_error;
108
 
 
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
101
private:
128
102
 
 
103
        friend class statement;
 
104
        friend class transaction;
 
105
 
129
106
        /** the database handle */
130
107
        sqlite3 *_handle;
131
108
 
132
109
};
133
110
 
134
111
 
135
 
} // namespace sqlite
136
 
 
137
 
 
138
 
#endif /* SQLITE3CC_DATABASE_H_ */
 
112
}
 
113
 
 
114
 
 
115
#endif /* DATABASE_HPP_ */