You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -166,7 +166,7 @@ You can use transactions with `begin;`, `commit;` and `rollback;` commands.
166
166
<< u"jack"
167
167
<< 68.5;
168
168
db << "commit;"; // commit all the changes.
169
-
169
+
170
170
db << "begin;"; // begin another transaction ....
171
171
db << "insert into user (age,name,weight) values (?,?,?);"// utf16 string
172
172
<< 19
@@ -176,6 +176,24 @@ You can use transactions with `begin;`, `commit;` and `rollback;` commands.
176
176
177
177
```
178
178
179
+
Blob
180
+
=====
181
+
Use `std::vector<T>` to store and retrieve blob data.
182
+
`T` could be `char,short,int,long,long long, float or double`.
183
+
184
+
```c++
185
+
db << "CREATE TABLE person (name TEXT, numbers BLOB);";
186
+
db << "INSERT INTO person VALUES (?, ?)" << "bob" << vector<int> { 1, 2, 3, 4};
187
+
db << "INSERT INTO person VALUES (?, ?)" << "sara" << vector<double> { 1.0, 2.0, 3.0, 4.0};
188
+
189
+
vector<int> numbers_bob;
190
+
db << "SELECT numbers from person where name = ?;" << "bob" >> numbers_bob;
191
+
192
+
db << "SELECT numbers from person where name = ?;" << "sara" >> [](vector<double> numbers_sara){
193
+
for(auto e : numbers_sara) cout << e << ' '; cout << endl;
194
+
};
195
+
```
196
+
179
197
Dealing with NULL values
180
198
=====
181
199
If you have databases where some rows may be null, you can use boost::optional to retain the NULL value between C++ variables and the database. Note that you must enable the boost support by defining _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT befor importing the header.
@@ -184,45 +202,45 @@ If you have databases where some rows may be null, you can use boost::optional t
184
202
185
203
#define _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT
186
204
#include <sqlite_modern_cpp.h>
187
-
205
+
188
206
struct User {
189
207
long long _id;
190
208
boost::optional<int> age;
191
209
boost::optional<string> name;
192
210
boost::optional<real> weight;
193
211
};
194
-
212
+
195
213
{
196
214
User user;
197
215
user.name = "bob";
198
-
216
+
199
217
// Same database as above
200
218
database db("dbfile.db");
201
-
219
+
202
220
// Here, age and weight will be inserted as NULL in the database.
203
221
db << "insert into user (age,name,weight) values (?,?,?);"
204
222
<< user.age
205
223
<< user.name
206
224
<< user.weight;
207
-
225
+
208
226
user._id = db.last_insert_rowid();
209
227
}
210
-
228
+
211
229
{
212
230
// Here, the User instance will retain the NULL value(s) from the database.
213
231
db << "select _id,age,name,weight from user where age > ? ;"
0 commit comments