-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_02.cxx
65 lines (57 loc) · 1.43 KB
/
example_02.cxx
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
61
62
63
64
65
#include <stdexcept>
#include <cstdint>
#include <string>
#include <iostream>
#include <fstream>
#include <WonderRabbitProject/SQLite3.hpp>
int main()
try
{
using WonderRabbitProject::SQLite3::sqlite3_t;
sqlite3_t d;
d.execute("create table bin(filename primary key, blob)");
d.execute
( "insert into bin values('nico.png',x'"
"89504e470d0a1a0a0000000d49484452"
"000000080000000808020000004b6d29"
"dc0000003f4944415408d77d8b410ac0"
"301002cd2cf9ff83836b2fa58590563c"
"88a3234127dd6d95b6709eff8101b277"
"5cd59f0fd902253c06d91a09dd3de77b"
"5dab810be8c319189c120a0400000000"
"49454e44ae426082"
"')"
);
auto s = d.prepare("select * from bin");
using WonderRabbitProject::SQLite3::RESULT_CODE;
// low level access: step
while ( s.step() == RESULT_CODE::ROW )
{
// low level access: data_element
auto filename = s.data_element<0, std::string>();
auto blob = s.data_element<1, std::vector<char>>();
std::ofstream o( filename
, std::ofstream::binary
| std::ofstream::trunc
);
o.write( blob.data(), blob.size());
std::cout
<< "write \""
<< filename
<< "\" , "
<< blob.size()
<< " [bytes]"
<< std::endl
;
}
}
catch(const std::exception & e)
{
std::cerr << "exception: " << e.what();
return -1;
}
catch(...)
{
std::cerr << "exception: unkown";
return -2;
}