17
17
*/
18
18
19
19
#ifndef RESULT_SET_HPP
20
- #define RESULT_SET_HPP
20
+ #define RESULT_SET_HPP
21
21
22
22
namespace vgi { namespace dbconn { namespace dbi {
23
23
@@ -34,29 +34,30 @@ struct iresult_set
34
34
virtual bool has_data () = 0;
35
35
virtual bool more_results () = 0;
36
36
virtual size_t row_count () const = 0;
37
+ virtual size_t rows_affected () const = 0;
37
38
virtual size_t column_count () const = 0;
38
39
virtual bool next () = 0;
39
- virtual std::string column_name (size_t index ) = 0;
40
+ virtual std::string column_name (size_t col_idx ) = 0;
40
41
virtual int column_index (const std::string& col_name) = 0;
41
- virtual bool is_null (unsigned int colidx ) = 0;
42
- virtual int16_t get_short (unsigned int colidx ) = 0;
43
- virtual uint16_t get_ushort (unsigned int colidx ) = 0;
44
- virtual int32_t get_int (unsigned int colidx ) = 0;
45
- virtual uint32_t get_uint (unsigned int colidx ) = 0;
46
- virtual int64_t get_long (unsigned int colidx ) = 0;
47
- virtual uint64_t get_ulong (unsigned int colidx ) = 0;
48
- virtual float get_float (unsigned int colidx ) = 0;
49
- virtual double get_double (unsigned int colidx ) = 0;
50
- virtual long double get_ldouble (unsigned int colidx ) = 0;
51
- virtual bool get_bool (unsigned int colidx ) = 0;
52
- virtual char get_char (unsigned int colidx ) = 0;
53
- virtual std::string get_string (unsigned int colidx ) = 0;
54
- virtual int get_date (unsigned int colidx ) = 0;
55
- virtual double get_time (unsigned int colidx ) = 0;
56
- virtual time_t get_datetime (unsigned int colidx ) = 0;
57
- virtual char16_t get_unichar (unsigned int colidx ) = 0;
58
- virtual std::u16string get_unistring (unsigned int colidx ) = 0;
59
- virtual std::vector<uint8_t > get_image (unsigned int colidx ) = 0;
42
+ virtual bool is_null (size_t col_idx ) = 0;
43
+ virtual int16_t get_short (size_t col_idx ) = 0;
44
+ virtual uint16_t get_ushort (size_t col_idx ) = 0;
45
+ virtual int32_t get_int (size_t col_idx ) = 0;
46
+ virtual uint32_t get_uint (size_t col_idx ) = 0;
47
+ virtual int64_t get_long (size_t col_idx ) = 0;
48
+ virtual uint64_t get_ulong (size_t col_idx ) = 0;
49
+ virtual float get_float (size_t col_idx ) = 0;
50
+ virtual double get_double (size_t col_idx ) = 0;
51
+ virtual long double get_ldouble (size_t col_idx ) = 0;
52
+ virtual bool get_bool (size_t col_idx ) = 0;
53
+ virtual char get_char (size_t col_idx ) = 0;
54
+ virtual std::string get_string (size_t col_idx ) = 0;
55
+ virtual int get_date (size_t col_idx ) = 0;
56
+ virtual double get_time (size_t col_idx ) = 0;
57
+ virtual time_t get_datetime (size_t col_idx ) = 0;
58
+ virtual char16_t get_unichar (size_t col_idx ) = 0;
59
+ virtual std::u16string get_unistring (size_t col_idx ) = 0;
60
+ virtual std::vector<uint8_t > get_image (size_t col_idx ) = 0;
60
61
// TODO: add xml, binary, money, lob
61
62
};
62
63
@@ -74,75 +75,149 @@ struct iresult_set
74
75
class result_set
75
76
{
76
77
public:
78
+ /* *
79
+ * Copy constructor
80
+ * @param rs
81
+ */
77
82
result_set (const result_set& rs) : rs_impl(rs.rs_impl)
78
83
{
79
84
}
80
85
86
+ /* *
87
+ * Move constructor
88
+ * @param rs
89
+ */
81
90
result_set (result_set&& rs) : rs_impl(std::move(rs.rs_impl))
82
91
{
83
92
}
84
93
94
+ /* *
95
+ * Assignment copy operator
96
+ * @param rs
97
+ * @return
98
+ */
85
99
result_set& operator =(const result_set& rs)
86
100
{
87
101
if (this != &rs)
88
102
rs_impl = rs.rs_impl ;
89
103
return *this ;
90
104
}
91
105
106
+ /* *
107
+ * Assignment move operator
108
+ * @param rs
109
+ * @return
110
+ */
92
111
result_set& operator =(result_set&& rs)
93
112
{
94
113
if (this != &rs)
95
114
rs_impl = std::move (rs.rs_impl );
96
115
return *this ;
97
116
}
98
117
118
+ /* *
119
+ * Function checks if current result set contains data.
120
+ * Even after whole data set has been iterated through using next() the
121
+ * has_data() function would still return true - it is only reset after call
122
+ * to more_results() function which will close current result set.
123
+ * @return true if there is data in current result set, false otherwise
124
+ */
99
125
bool has_data ()
100
126
{
101
127
return rs_impl->has_data ();
102
128
}
103
129
130
+ /* *
131
+ * Function checks if there is another data set or status.
132
+ * @return true if there is another result set, false otherwise
133
+ */
104
134
bool more_results ()
105
135
{
106
136
return rs_impl->more_results ();
107
137
}
108
138
139
+ /* *
140
+ * Function returns current row count while iterating through the result set
141
+ * and total number of rows after data set was processed
142
+ */
109
143
size_t row_count () const
110
144
{
111
145
return rs_impl->row_count ();
112
146
}
113
147
148
+ /* *
149
+ * Function returns number of affected rows after execution of command
150
+ * @return number of rows
151
+ */
152
+ size_t rows_affected () const
153
+ {
154
+ return rs_impl->rows_affected ();
155
+ }
156
+
157
+ /* *
158
+ * Function returns number of columns of current result set or zero
159
+ * @return number of columns or zero otherwise
160
+ */
114
161
size_t column_count () const
115
162
{
116
163
return rs_impl->column_count ();
117
164
}
118
165
119
- const std::string column_name (size_t index)
166
+ /* *
167
+ * Function returns column name by column index or throws an exception if
168
+ * index is invalid
169
+ * @param col_idx
170
+ * @return column name string or exception is thrown if index is invalid
171
+ */
172
+ const std::string column_name (size_t col_idx)
120
173
{
121
- return rs_impl->column_name (index );
174
+ return std::move ( rs_impl->column_name (col_idx) );
122
175
}
123
176
177
+ /* *
178
+ * Function returns column index by column name, if column name is invalid
179
+ * then -1 is returned
180
+ * @param col_name
181
+ * @return index or -1 on invalid column name
182
+ */
124
183
int column_index (const std::string& col_name)
125
184
{
126
185
return rs_impl->column_index (col_name);
127
186
}
128
187
188
+ /* *
189
+ * Function moves iterator to the next row of the current result data set
190
+ * @return true on success, or false if there is no more rows
191
+ */
129
192
bool next ()
130
193
{
131
194
return rs_impl->next ();
132
195
}
133
196
134
- bool is_null (unsigned int colidx)
197
+ /* *
198
+ * Function checks if cell data is NULL by column index or throws an exception
199
+ * if index is invalid.
200
+ * @param col_idx
201
+ * @return true if cell data is NULL, false otherwise
202
+ */
203
+ bool is_null (size_t col_idx)
135
204
{
136
- return rs_impl->is_null (colidx );
205
+ return rs_impl->is_null (col_idx );
137
206
}
138
207
208
+ /* *
209
+ * Function checks if cell data is NULL by column name or throws an exception
210
+ * if index is invalid.
211
+ * @param colname
212
+ * @return
213
+ */
139
214
bool is_null (const std::string& colname)
140
215
{
141
216
return rs_impl->is_null (rs_impl->column_index (colname));
142
217
}
143
218
144
- #define get_type_by_index (t ) get_##t(unsigned int colidx ) { return rs_impl->get_ ##t (colidx ); }
145
- #define get_type_by_name (t ) get_##t(const std::string& colname) { return rs_impl->get_ ##t (rs_impl->column_index (colname)); }
219
+ #define get_type_by_index (t ) get_##t(size_t col_idx ) { return rs_impl->get_ ##t (col_idx ); }
220
+ #define get_type_by_name (t ) get_##t(const std::string& colname) { return rs_impl->get_ ##t (rs_impl->column_index (colname)); }
146
221
147
222
int16_t get_type_by_index (short );
148
223
int16_t get_type_by_name (short );
@@ -193,5 +268,5 @@ class result_set
193
268
194
269
} } } // namespace vgi::dbconn::dbi
195
270
196
- #endif // RESULT_SET_HPP
271
+ #endif // RESULT_SET_HPP
197
272
0 commit comments