/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/command.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
 
 * command.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_COMMAND_H_
24
 
#define SQLITE3CC_COMMAND_H_
25
 
 
26
 
 
27
 
#include <sqlite3cc/basic_statement.h>
 
23
#ifndef COMMAND_HPP_
 
24
#define COMMAND_HPP_
 
25
 
 
26
 
 
27
#include "statement.hpp"
28
28
 
29
29
 
30
30
namespace sqlite
39
39
 */
40
40
class command
41
41
        :
42
 
        public detail::basic_statement
 
42
        public statement
43
43
{
44
44
//______________________________________________________________________________
45
45
//                                                                 instantiation
46
46
public:
47
47
 
48
48
        /**
49
 
         * Constructor that provides a connection upon which to act and the SQL
50
 
         * command to execute.
51
 
         * @param connection a reference to a connection
 
49
         * Constructor that provides the SQL statement to execute
52
50
         * @param sql an SQL statement in UTF-8
53
51
         */
54
 
        explicit command(
55
 
                connection &connection,
56
 
                const std::string &sql );
57
 
 
58
 
        /**
59
 
         * Constructor that provides a connection upon which to act.
60
 
         * @param connection a reference to a connection
61
 
         */
62
 
        explicit command(
63
 
                connection &connection );
 
52
        command(
 
53
                database &database,
 
54
                const std::string &sql )
 
55
                :
 
56
                statement( database, sql )
 
57
        { }
64
58
 
65
59
//______________________________________________________________________________
66
60
//                                                              public interface
67
61
public:
68
62
 
69
63
        /**
70
 
         * Prepare an SQL statement.
71
 
         * @param sql an SQL statement in UTF-8
72
 
         * @returns an sqlite error code
73
 
         * @see sqlite3_prepare_v2()
74
 
         */
75
 
        virtual int prepare(
76
 
                const std::string &sql );
77
 
 
78
 
        /**
79
 
         * Step through one execution cycle of the SQL statement. If this is an SQL
80
 
         * statement that doesn't return any rows, only one cycle is required,
81
 
         * otherwise, each cycle will return another row
82
 
         * @return an sqlite error code
83
 
         * @see sqlite3_step()
84
 
         */
85
 
        int step();
86
 
 
87
 
        /**
88
64
         * Execute the command. This is the same as doing a step().
89
 
         * @return an sqlite error code
90
65
         * @see sqlite3_step()
91
66
         */
92
67
        inline int exec()
94
69
                return step();
95
70
        }
96
71
 
97
 
        /**
98
 
         * Get the number of changes made by the last successful execution of this
99
 
         * command. This doesn't include changes made in trigger subcontexts.
100
 
         * @return the number of changed rows
101
 
         * @see sqlite3_changes()
102
 
         */
103
 
        inline int changes()
104
 
        {
105
 
                return _changes;
106
 
        }
107
 
 
108
 
        /**
109
 
         * Get the number of changes made by the last successful execution of this
110
 
         * command. This includes changes made in all trigger subcontexts.
111
 
         * @return the number of changed rows
112
 
         * @see sqlite3_total_changes()
113
 
         */
114
 
        inline int total_changes()
115
 
        {
116
 
                return _total_changes;
117
 
        }
118
 
 
119
 
        /**
120
 
         * Get the rowid of the last row inserted via a successful INSERT command
121
 
         * (regardless of whether that is this command or not).
122
 
         * @return the last inserted rowid
123
 
         */
124
 
        inline long long last_insert_rowid()
125
 
        {
126
 
                return _last_insert_rowid;
127
 
        }
128
 
 
129
 
//______________________________________________________________________________
130
 
//                                                                implementation
131
 
private:
132
 
 
133
 
        /** non-recursive number of changes made by the last execution */
134
 
        int _changes;
135
 
 
136
 
        /** recursive number of changes made by the last execution */
137
 
        int _total_changes;
138
 
 
139
 
        /** the rowid of the last successful insert command */
140
 
        long long _last_insert_rowid;
141
 
 
142
72
};
143
73
 
144
74
 
145
 
namespace detail
146
 
{
147
 
 
148
 
 
149
 
// template specialisations for detail::basic_statement::operator <<()
150
 
template< >
151
 
basic_statement &basic_statement::operator << < detail::exec_t >(
152
 
        const detail::exec_t & );
153
 
 
154
 
 
155
 
} // namespace detail
156
 
 
157
 
 
158
 
} // namespace sqlite
159
 
 
160
 
 
161
 
#endif /* SQLITE3CC_COMMAND_H_ */
 
75
}
 
76
 
 
77
 
 
78
#endif /* COMMAND_HPP_ */