-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathvalue.cpp
More file actions
61 lines (47 loc) · 1.56 KB
/
Copy pathvalue.cpp
File metadata and controls
61 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// (c) 2013 Stephan Hohe
#include "value.hpp"
#include <sqlite3.h>
namespace sqxx {
value::value(sqlite3_value *handle_arg) : handle(handle_arg) {
}
bool value::null() const {
return (sqlite3_value_type(handle) == SQLITE_NULL);
}
template<>
int value::val<int>() const {
return sqlite3_value_int(handle);
}
template<>
int64_t value::val<int64_t>() const {
return sqlite3_value_int64(handle);
}
template<>
double value::val<double>() const {
return sqlite3_value_double(handle);
}
template<>
const char* value::val<const char*>() const {
const unsigned char *text = sqlite3_value_text(handle);
return reinterpret_cast<const char*>(text);
}
template<>
std::string value::val<std::string>() const {
// Correct order to call functions according to http://www.sqlite.org/c3ref/column_blob.html
const unsigned char *text = sqlite3_value_text(handle);
int bytes = sqlite3_value_bytes(handle);
return std::string(reinterpret_cast<const char*>(text), bytes);
}
template<>
blob value::val<blob>() const {
// Correct order to call functions according to http://www.sqlite.org/c3ref/column_blob.html
const void *data = sqlite3_value_blob(handle);
int len = sqlite3_value_bytes(handle);
return blob(data, len);
}
value::operator int() const { return val<int>(); }
value::operator int64_t() const { return val<int64_t>(); }
value::operator double() const { return val<double>(); }
value::operator const char*() const { return val<const char*>(); }
value::operator std::string() const { return val<std::string>(); }
value::operator blob() const { return val<blob>(); }
} // namespace sqxx