/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-07-29 06:28:53 UTC
  • Revision ID: edam@waxworlds.org-20100729062853-4i2fec52m86mh724
- made basic_statement::step() protected, for use by query and command only
- moved basic_statement::operator<<() to command and query instead; one needs to accept sqlite::exec, the other doesn't
- added tests for query::operator<<()
- added code to invlaidate in-progress queries during any transaction rollbacks (currently segfaults in basic_statement::finalize())
- added new sqlite_error constructor that obtains a full error message
- implemented database::database_mutex_guard class
- swapped command's step mutex in favour of the database mutex

Show diffs side-by-side

added added

removed removed

25
25
 
26
26
 
27
27
#include <sqlite3cc/basic_statement.h>
28
 
#include <boost/thread/recursive_mutex.hpp>
29
28
 
30
29
 
31
30
namespace sqlite
83
82
         * @return an sqlite error code
84
83
         * @see sqlite3_step()
85
84
         */
86
 
        virtual int step();
 
85
        int step();
87
86
 
88
87
        /**
89
88
         * Execute the command. This is the same as doing a step().
127
126
                return _last_insert_rowid;
128
127
        }
129
128
 
 
129
        /**
 
130
         * Stream operator is used to bind values to parameters automatically, in
 
131
         * ascending order. In addition, the null, set_index() and execute auto-
 
132
         * binding manipulators can be used.
 
133
         * @param value a value to bind
 
134
         */
 
135
        template< class T >
 
136
        command &operator <<(
 
137
                const T &value )
 
138
        {
 
139
                int code = bind( _bind_index, value );
 
140
                if( code != SQLITE_OK ) throw sqlite_error( _database, code );
 
141
                _bind_index++;
 
142
                return *this;
 
143
        }
 
144
 
130
145
//______________________________________________________________________________
131
146
//                                                                implementation
132
147
private:
140
155
        /** the rowid of the last successful insert command */
141
156
        long long _last_insert_rowid;
142
157
 
143
 
        /** exclusive use during command mutex */
144
 
        static boost::recursive_mutex _command_mutex;
145
 
 
146
158
};
147
159
 
148
160
 
 
161
// template specialisations for command::operator <<()
 
162
template< >
 
163
command &command::operator << < detail::null_t >(
 
164
        const detail::null_t & );
 
165
template< >
 
166
command &command::operator << < detail::exec_t >(
 
167
        const detail::exec_t & );
 
168
template< >
 
169
command &command::operator << < detail::set_index_t >(
 
170
        const detail::set_index_t &t );
 
171
 
 
172
 
149
173
} // namespace sqlite
150
174
 
151
175