Vinnie-4 wrote:
> 
>> From: Neville Franks <sql...@surfulater.com>
> 
> Apparently I did come up with an original idea. Because none of the
> wrappers from the archives are using variable argument lists.
> 

That's because many C++ programmer don't like using printf-like vararg calls
which are not type safe. I for one want to ensure the compiler catches my
mistake, instead of getting a crash at runtime if I don't provide the right
format string (wrong type, wrong number of args), or the wrong addresses.

   {
        enum { DERIVED = 0, BASE, DISTANCE }; // just for easier code
reading
        typedef boost::tuple<unsigned short, unsigned short, unsigned short>
Row;
        std::vector<Row> rset;
        get_rows(
            "select type_id, id_is_a, distance from rtti where type_id = :1
and id_is_a = :2",
            make_tuple(some_id, another_id), rset
        );
        CPPUNIT_ASSERT_EQUAL(1, (int)rset.size());
        CPPUNIT_ASSERT_EQUAL(some_id, boost::get<DERIVED>(rset[0]));
        CPPUNIT_ASSERT_EQUAL(another_id, boost::get<BASE>(rset[0]));
        CPPUNIT_ASSERT_EQUAL((unsigned short)1,
boost::get<DISTANCE>(rset[0]));
    }

In the code above both the binds and the gets are routed to the proper
SQLite calls based on the types of the variables, thanks to sqlite3pp (one
of the wrappers listed in the wrapper page) and our own extensions using the
magic of templates and boost, all done at compile time. There can be no
crashes, and any SQLite error is translated into a C++ exception being
thrown (sqlite3pp does not do that, we do) that we catch higher up (actually
cppunit does the catching). That's the C++ way ;-) --DD
-- 
View this message in context: 
http://www.nabble.com/How-do-you-guys-use-sqlite-from-C%2B%2B--tp23253633p23302398.html
Sent from the SQLite mailing list archive at Nabble.com.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to