/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/command.h

  • Committer: edam
  • Date: 2010-01-28 12:21:03 UTC
  • Revision ID: edam@waxworlds.org-20100128122103-v3gs6hro5h7ffnhb
- further initial development
- basic support for: queries, rows (query results)
- filename, comment header and project name consistency

Show diffs side-by-side

added added

removed removed

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