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

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

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:


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++.


6 Responses to “Boost.SqlCli: How do you connect to a database?”

  1. is Says:


    Your library looks great!!!, is it usable, are you actively working on it, any chance for a Boost review soon?

    You should really submit progess/info to the Boost ml and many people would be interested I suspect and they may give you some good feedback

    I like the way that you have separated the connection and the statement especially statement.prepare and statement.execute


  2. nmusatti Says:

    I’m glad you like it. At the current stage SqlCli is nothing more than an incomplete prototype. I’m working on it, but my free time is scarce and progress is slow. I’m still far away from a Boost review; what I plan to do as soon as the things I’m working on settle is to add it to the new Boost sandbox so as to make it easier for interested people to see what’s there.


  3. Andreo Says:

    Tell me please, how to build boost::sql_cli.
    What is wrong?

    D:\Install\Coding\_boost>bjam –build-dir=”tmp” –toolset=msvc –build-type=complete –with-sql_cli stage
    Системе не удается найти указанный путь.
    Системе не удается найти указанный путь.
    Warning: “using python” expects a two part (major, minor) version number; got D:
    /opt/python24 instead
    Warning: “using python” expects a two part (major, minor) version number; got 0
    error: Unable to find file or target named
    error: ‘/boost/signals//boost_signals’
    error: referred from project at
    error: ‘libs/sql_cli/build’

    Для продолжения нажмите любую клавишу . . .

  4. nmusatti Says:

    Hallo, Andreo.
    First of all, how did you get your copy of SqlCli? I’m asking because the most recent version (still rather old) is the one in the Boost sandbox and not the one in the Boost vault.

    From the messages you posted I suspect that bjam isn’t finding a Boost installation it needs to compile SqlCli; you can specify it on the bjam command line, but I don’t remember exactly how offhand. Otherwise you can copy the SqlCli source into a Boost installation, in which case you should have no further problems.

    Before you go on, however, I have to warn you that SqlCli is very incomplete and I haven’t been able to work on it for quite some time.

  5. Andreo Says:

    I downloaded it form boost::vault(how to download from sandbox?), than copied all directories ‘boost’ and ‘libs’ to boost directory, and invoked
    ‘bjam –build-dir=”tmp” –toolset=msvc –build-type=complete –with-sql_cli stage’

    i tried to copy ‘tools’ directory also, but building failed

  6. Coward Says:

    This is an interesting project, can you please update your code with the latest changes to boost sandbox, much appreciated.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: