/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

39
39
 */
40
40
class command
41
41
        :
42
 
        public detail::basic_statement
 
42
        public basic_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
 
49
         * Constructor that provides a database upon which to act and the SQL
50
50
         * command to execute.
51
 
         * @param connection a reference to a connection
 
51
         * @param database a reference to a database
52
52
         * @param sql an SQL statement in UTF-8
53
53
         */
54
54
        explicit command(
55
 
                connection &connection,
 
55
                database &database,
56
56
                const std::string &sql );
57
57
 
58
58
        /**
59
 
         * Constructor that provides a connection upon which to act.
60
 
         * @param connection a reference to a connection
 
59
         * Constructor that provides a database upon which to act.
 
60
         * @param database a reference to a database
61
61
         */
62
62
        explicit command(
63
 
                connection &connection );
 
63
                database &database );
64
64
 
65
65
//______________________________________________________________________________
66
66
//                                                              public interface
126
126
                return _last_insert_rowid;
127
127
        }
128
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
 
129
145
//______________________________________________________________________________
130
146
//                                                                implementation
131
147
private:
142
158
};
143
159
 
144
160
 
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 >(
 
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 >(
152
167
        const detail::exec_t & );
153
 
 
154
 
 
155
 
} // namespace detail
 
168
template< >
 
169
command &command::operator << < detail::set_index_t >(
 
170
        const detail::set_index_t &t );
156
171
 
157
172
 
158
173
} // namespace sqlite