larroy/sqlite3pp — pull request #2 by vakopian (2014-07-24 22:27:15+00:00)
Title: add support for nullable()

Currently, the `get()` method and therefore the stream redirect methods throw an exception if a null value is fetched. This forces lots of boilerplate code using `(column_type(idx) == SQLITE_NULL)` logic. For example, consider the case with 3 columns: `present` which is nullable, `name` which is not null and `status` which is also nullable. Then a nice and fluid statement like this one
```
bool present;
string name, status;
for (; it != itEnd; ++it) {
it->getter() >> present >> name >> status;
}
```
does not work since exceptions are thrown when null is encountered. So the code becomes
```
bool present;
string name, status;
for (; it != itEnd; ++it) {
present = (it->column_type(0) == SQLITE_NULL) ? false : it->get(0);
name = it->get(1);
status = (it->column_type(2) == SQLITE_NULL) ? "" : it->get(2);
}
```
(other equally verbose implementations may use ugly try-catch constructs too).

This patch will add support for a `nullable()` function that allows to write the same fluid code above in a null-safe way:
```
bool present;
string name, status;
for (; it != itEnd; ++it) {
it->getter() >> nullable(present, false) >> name >> nullable(status, "");
}
```

The patch also adds a `get_nullable()` function similar to `get()`.