Archive for the ‘SqlCli’ Category

Boost.SqlCli: How do you connect to a database?

July 2, 2007

With a not very original approach SqlCli’s entry point is the sql_cli::connection class, which is meant to be used as follows:

// Create a connection to a specific backend:
// ODBC, Oracle, PostgreSQL, etc.
sql_cli::connection conn("ODBC");

// Connect to a specific database
conn.connect(...);

My problem is what to put in the ellipsis’s place. At one extreme I could try to be completely independent from the underlying technology, by assuming that all DBMS’s support the use of database, user and password as connection parameters and only provide access through those:

conn.connect("Customer", "nmusatti", "password1");

This is a convenient approach, especially for those that aren’t too familiar with relational database implementations or need to write code that’s independent from the underlying technology, but it’s not very general.

The opposite approach would request a connection string as single parameter, to be passed unchanged to the lower level API routines:

conn.connect("SERVER=Customer;UID=nmusatti;PWD=password1;");

This is as general as it gets, but requires that users know some rather specific details of the DBMS they’re connecting to.

One intermediate alternative is a combination of the two; the database, username and password parameters are still used, but some optional mechanism is also provided to allow the specification of additional parameters. This is certainly as general as the second option above, but I’m not convinced that it provides any gain in terms of clarity and simplicity. Moreover, such an additional mechanism is likely to involve some ad hoc argument specification syntax, which would further complicate things.

What is your point of view?

Chi volesse discutere dell’argomento in italiano trova lo stesso quesito sul newsgroup it.comp.lang.c++.

Boost.SqlCli’s design goals

June 28, 2007

The goal of Boost.SqlCli is to provide the lowest abstraction layer that may effectively hide the details of the underlying database technology. This choice comes for the observation that there are many possible approaches to a more abstract representation of a database and there is no consensus on a best one. Actually I’m convinced that different applications are best served by different ways of using RDMBS’s.

However, at the lowest level, all these different approaches tend to share a remarkably uniform architecture, whose main elements are connections, statements and result sets. This architecture may be observed in many different existing libraries, such as SOCI, SQLAPI++ and CodeGear‘s VCL, just to mention those I’m most familiar with.

In order to be useful as a building block for higher level solutions Boost.SqlCli should be limited to the minimal feature set that proves to be convenient in performing queries to a database and retrieving the corresponding results. Trying to be too helpful may well result in choices that do not match well with other libraries’ needs.

Last but not least the library should be pleasant to use by competent programmers, but simple enough not to scare beginners away. The ultimate goal is to come up with a design that is worthy of submission to the C++ standard committee.

Whether I’ll be up to fulfilling these goals remains to be seen 🙂

Introducing Boost.SqlCli

June 25, 2007

During the last few months I’ve been working on and off on a basic C++ library to interface relational databases. I was inspired by a discussion on the Boost developers’ mailing list and by SOCI, a rather popular library whose programming interface I’m not very fond of. The idea is to define an API that may be considered suitable for inclusion in a future version of the C++ standard and to provide an experimental implementation. My aim is to implement an ODBC backend and possibly also a PostgreSQL one.

SqlCli doesn’t have a home yet; I plan to upload it to the new Boost Sandbox whenever the current discussions on its structure settle to an agreement. Meanwhile you can find a not too old snapshot in the Boost Vault, which also contains all the currently available documentation. Since I put it there very little went on: I mainly gathered a few ideas and many doubts. I plan to post both to this blog, in the hope of gathering useful suggestions 🙂