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

  • Committer: edam
  • Date: 2010-02-07 15:28:23 UTC
  • Revision ID: edam@waxworlds.org-20100207152823-42k206h6gwy7vla4
- fixed .am files so the library gets built!

Show diffs side-by-side

added added

removed removed

24
24
#define SQLITE3CC_ROW_H_
25
25
 
26
26
 
 
27
#include <sqlite3cc/query.h>
27
28
#include <sqlite3.h>
28
29
#include <boost/utility.hpp>
29
30
#include <boost/lexical_cast.hpp>
38
39
 
39
40
struct _null_t;
40
41
struct _set_index_t;
41
 
class query;
42
42
 
43
43
 
44
44
/**
54
54
//                                                                 instantiation
55
55
protected:
56
56
 
57
 
        friend class query;
58
 
 
59
57
        /**
60
 
         * Constructor that produces a valid row.
61
 
         * @param the handle of the statement (query) that created this row
62
 
         * @oaram the result index that is this row
 
58
         * Constructor that provides the database that we were extracted from.
 
59
         * @param the query that this row belongs to
 
60
         * @oaram true if this row represents there being no more rows
63
61
         */
64
62
        explicit row(
65
 
                sqlite3_stmt *handle,
66
 
                unsigned long long index );
67
 
 
68
 
        /**
69
 
         * Constructor that produces an invalid row.
70
 
         * @param the handle of the statement (query) that created this row
71
 
         */
72
 
        explicit row();
 
63
                query &query,
 
64
                bool valid = true );
73
65
 
74
66
//______________________________________________________________________________
75
67
//                                                              public interface
79
71
         * Determine if this row is valid or not. If it is not valid, there are no
80
72
         * more rows in the results of the query.
81
73
         */
82
 
        inline operator bool() const
83
 
        {
84
 
                return _index != std::numeric_limits< unsigned long long >::max();
85
 
        }
86
 
 
87
 
        /**
88
 
         * get the index in to the results that is this row
89
 
         * @return index
90
 
         */
91
 
        inline unsigned long long index()
92
 
        {
93
 
                return _index;
 
74
        inline operator bool()
 
75
        {
 
76
                return _valid;
94
77
        }
95
78
 
96
79
        /**
112
95
                unsigned int index );
113
96
 
114
97
        /**
115
 
         * Get a value from the row.
 
98
         * Get a value from the row
116
99
         * @param index column index
117
100
         * @param value reference to object to set with the value
118
101
         * @see sqlite3_column_*()
122
105
                unsigned int index,
123
106
                T &value )
124
107
        {
125
 
                assert( index <
126
 
                        static_cast< unsigned int >( sqlite3_column_count( _handle ) ) );
 
108
                assert( index < _query.column_count() );
127
109
                const char *text = reinterpret_cast< const char * >(
128
 
                        sqlite3_column_text( _handle, index ) );
 
110
                        sqlite3_column_text( _query._handle, index ) );
129
111
                if( text )
130
112
                        value = boost::lexical_cast< T >( text );
131
113
                else
133
115
        }
134
116
 
135
117
        /**
136
 
         * Get a value from the row and return it.
137
 
         * @param index column index
138
 
         * @return the value
139
 
         * @see sqlite3_column_*()
140
 
         */
141
 
        template< class T >
142
 
        T column(
143
 
                unsigned int index )
144
 
        {
145
 
                T value;
146
 
                column( index, value );
147
 
                return value;
148
 
        }
149
 
 
150
 
        /**
151
118
         * Stream operator is used to obtain values from a result row, fetching from
152
119
         * each column in turn. In addition, the null and set_index() auto-column-
153
120
         * getting manipulators can be used.
168
135
        row &operator >>(
169
136
                _set_index_t t );
170
137
 
 
138
        /**
 
139
         * Check of this row is valid
 
140
         * @return true if it is
 
141
         */
 
142
        operator bool() const
 
143
        {
 
144
                return _valid;
 
145
        }
 
146
 
171
147
//______________________________________________________________________________
172
148
//                                                                implementation
173
149
protected:
174
150
 
175
 
        /** the query's handle */
176
 
        sqlite3_stmt *_handle;
 
151
        friend class query;
 
152
 
 
153
        /** the parent query */
 
154
        query &_query;
177
155
 
178
156
private:
179
157
 
180
158
        /** index used when auto-column-getting */
181
159
        unsigned int _column_index;
182
160
 
183
 
        /** the index of this row */
184
 
        unsigned long long _index;
 
161
        /** is this row valid? */
 
162
        bool _valid;
185
163
 
186
164
};
187
165
 
192
170
        _null_t & );
193
171
 
194
172
 
195
 
} // namespace sqlite
 
173
} // namespace row
196
174
 
197
175
 
198
176
#endif /* SQLITE3CC_ROW_H_ */