/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-07-23 09:17:03 UTC
  • Revision ID: edam@waxworlds.org-20100723091703-3siqjj6eeux9hupz
- added NEWS
- added library checks to configure.ac
- added query::iterators
- remove dependency that rows have on querys (since querys have to be dependent on rows for boost::iterator_facade to work)
- rows now have the handle to the sqlite3 statement and know a count of their row number
- added convenience function tht can be used to detect presence of sqlite3cc in other packages
- updated test-main
- renamed all subdir.mk files to emake.mk

Show diffs side-by-side

added added

removed removed

24
24
#define SQLITE3CC_ROW_H_
25
25
 
26
26
 
27
 
#include <sqlite3cc/query.h>
28
27
#include <sqlite3.h>
29
28
#include <boost/utility.hpp>
30
29
#include <boost/lexical_cast.hpp>
39
38
 
40
39
struct _null_t;
41
40
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
 
57
59
        /**
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
 
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
61
63
         */
62
64
        explicit row(
63
 
                query &query,
64
 
                bool valid = true );
 
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();
65
73
 
66
74
//______________________________________________________________________________
67
75
//                                                              public interface
71
79
         * Determine if this row is valid or not. If it is not valid, there are no
72
80
         * more rows in the results of the query.
73
81
         */
74
 
        inline operator bool()
75
 
        {
76
 
                return _valid;
 
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;
77
94
        }
78
95
 
79
96
        /**
95
112
                unsigned int index );
96
113
 
97
114
        /**
98
 
         * Get a value from the row
 
115
         * Get a value from the row.
99
116
         * @param index column index
100
117
         * @param value reference to object to set with the value
101
118
         * @see sqlite3_column_*()
105
122
                unsigned int index,
106
123
                T &value )
107
124
        {
108
 
                assert( index < _query.column_count() );
 
125
                assert( index <
 
126
                        static_cast< unsigned int >( sqlite3_column_count( _handle ) ) );
109
127
                const char *text = reinterpret_cast< const char * >(
110
 
                        sqlite3_column_text( _query._handle, index ) );
 
128
                        sqlite3_column_text( _handle, index ) );
111
129
                if( text )
112
130
                        value = boost::lexical_cast< T >( text );
113
131
                else
115
133
        }
116
134
 
117
135
        /**
 
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
        /**
118
151
         * Stream operator is used to obtain values from a result row, fetching from
119
152
         * each column in turn. In addition, the null and set_index() auto-column-
120
153
         * getting manipulators can be used.
135
168
        row &operator >>(
136
169
                _set_index_t t );
137
170
 
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
 
 
147
171
//______________________________________________________________________________
148
172
//                                                                implementation
149
173
protected:
150
174
 
151
 
        friend class query;
152
 
 
153
 
        /** the parent query */
154
 
        query &_query;
 
175
        /** the query's handle */
 
176
        sqlite3_stmt *_handle;
155
177
 
156
178
private:
157
179
 
158
180
        /** index used when auto-column-getting */
159
181
        unsigned int _column_index;
160
182
 
161
 
        /** is this row valid? */
162
 
        bool _valid;
 
183
        /** the index of thi row */
 
184
        unsigned long long _index;
163
185
 
164
186
};
165
187
 
170
192
        _null_t & );
171
193
 
172
194
 
173
 
} // namespace row
 
195
} // namespace sqlite
174
196
 
175
197
 
176
198
#endif /* SQLITE3CC_ROW_H_ */