|
6 | 6 | #include <ctime>
|
7 | 7 | #include <tuple>
|
8 | 8 | #include <memory>
|
| 9 | +#include <vector> |
9 | 10 |
|
10 | 11 | #ifdef _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT
|
11 | 12 | #include <boost/optional.hpp>
|
@@ -188,17 +189,27 @@ namespace sqlite {
|
188 | 189 | }
|
189 | 190 |
|
190 | 191 | template <typename Type>
|
191 |
| - using is_sqlite_value = std::integral_constant< |
| 192 | + struct is_sqlite_value : public std::integral_constant< |
192 | 193 | bool,
|
193 | 194 | std::is_floating_point<Type>::value
|
194 | 195 | || std::is_integral<Type>::value
|
195 | 196 | || std::is_same<std::string, Type>::value
|
196 | 197 | || std::is_same<std::u16string, Type>::value
|
197 | 198 | || std::is_same<sqlite_int64, Type>::value
|
198 |
| - >; |
| 199 | + > { }; |
| 200 | + template <typename Type> |
| 201 | + struct is_sqlite_value< std::vector<Type> > : public std::integral_constant< |
| 202 | + bool, |
| 203 | + std::is_floating_point<Type>::value |
| 204 | + || std::is_integral<Type>::value |
| 205 | + || std::is_same<sqlite_int64, Type>::value |
| 206 | + > { }; |
| 207 | + |
199 | 208 |
|
200 | 209 | template<typename T> friend database_binder::chain_type& operator <<(database_binder::chain_type& db, const T& val);
|
201 | 210 | template<typename T> friend void get_col_from_db(database_binder& db, int inx, T& val);
|
| 211 | + template<typename T> friend database_binder::chain_type& operator <<(database_binder::chain_type& db, const std::vector<T>& val); |
| 212 | + template<typename T> friend void get_col_from_db(database_binder& db, int inx, std::vector<T>& val); |
202 | 213 | template<typename T> friend T operator++(database_binder& db, int);
|
203 | 214 |
|
204 | 215 |
|
@@ -410,6 +421,27 @@ namespace sqlite {
|
410 | 421 | }
|
411 | 422 | }
|
412 | 423 |
|
| 424 | + // vector<T> |
| 425 | + template<typename T> inline database_binder::chain_type& operator<<(database_binder::chain_type& db, const std::vector<T>& vec) { |
| 426 | + void const* buf = reinterpret_cast<void const *>(vec.data()); |
| 427 | + int bytes = vec.size() * sizeof(T); |
| 428 | + int hresult; |
| 429 | + if((hresult = sqlite3_bind_blob(db->_stmt.get(), db->_inx, buf, bytes, SQLITE_TRANSIENT)) != SQLITE_OK) { |
| 430 | + exceptions::throw_sqlite_error(hresult); |
| 431 | + } |
| 432 | + ++db->_inx; |
| 433 | + return db; |
| 434 | + } |
| 435 | + template<typename T> inline void get_col_from_db(database_binder& db, int inx, std::vector<T>& vec) { |
| 436 | + if(sqlite3_column_type(db._stmt.get(), inx) == SQLITE_NULL) { |
| 437 | + vec.clear(); |
| 438 | + } else { |
| 439 | + int bytes = sqlite3_column_bytes(db._stmt.get(), inx); |
| 440 | + T const* buf = reinterpret_cast<T const *>(sqlite3_column_blob(db._stmt.get(), inx)); |
| 441 | + vec = std::vector<T>(buf, buf + bytes/sizeof(T)); |
| 442 | + } |
| 443 | + } |
| 444 | + |
413 | 445 | // std::string
|
414 | 446 | template<> inline void get_col_from_db(database_binder& db, int inx, std::string & s) {
|
415 | 447 | if(sqlite3_column_type(db._stmt.get(), inx) == SQLITE_NULL) {
|
|
0 commit comments