Boost logo

Boost :

From: Maciej Sobczak (prog_at_[hidden])
Date: 2006-12-06 04:24:08

Martin Adrian wrote:

> 1. Can you please make soci work with something else than the "C" locale.
> Currently the Session use the global locale for streaming values which will not
> work since most (all?) locales use a thousand separator which is not allowed in
> SQL.
> For me
> sql << "insert into soci_test (id) values (" << 1234 << ")";
> becomes
> "insert into soci_test (id) values (1 234)"
> I see two ways of solving it:
> a. Let the backend assign the locale required for sql-statements.
> This is the best solution since the backend can query the database to find out
> decimal separator and date format.
> b. Add an .imbue member to the session object.

That's a very good point.
There is also a third option here, probably most generic - expose the
whole stream object, so that users can play with it on their own; this
goes far beyond locale control, you can even replace the whole streambuf
there. I don't see any immediate use for this, but we didn't foresee the
locale issue either.

> 2. I find the "into" handling a bit inconvenient in its current shape:
> a. I have to create an indicator variable for each parameter.
> eIndicator inda, indb, indc, ...;
> sql << "select a,b,c,d... FROM tbl", into(vara, inda), into(varb, indb)...
> if (inda == eNull) vara = "";
> if (indb == eNull) varb = -1;
> why not have a "intonull" expression that take a second nullValue argument:
> sql << "select a,b,c,d... from tbl", intonull(vara, ""), intonull(varb, -1)...

First note: you don't have to create indicator vars if you don't expect
Second, the above assumes that you have some default value to replace
the null. Isn't there a dedicated SQL function for this?
What about:

sql << "select ...", into(a, default("")), into(b, default(-1));

The point is that there is already a framework for extending into
elements this way.

> 2. Don't understand why "NoData" is part of the indicator. Shouldn't it be part
> of the statement?
> something like:
> sql << "select x from tbl", into(a);
> if (!sql.empty())
> // something was fetched
> or
> sql << "update tbl set x = 2 where y = 3";
> if (sql.rowsaffected() == 0)
> // not found

Yes, that's one possible approach. Boost.optional would handle the rest.
We have to review this subject.

Maciej Sobczak :
Programming    :

Boost list run by bdawes at, gregod at, cpdaniel at, john at