Boost logo

Boost :

From: Andy Tompkins (atompkins_at_[hidden])
Date: 2006-01-18 12:47:42

I think that most people either define their sql statement directly in
(ie. string sql("SELECT * FROM ORDERS");), or put the same string in a
resource and load it. The application that I work on often builds
complex statements from user input and requires a lot of code to create
the correct sql statement. I would like something that delimits table
and column names:
  "table 1" "column 1" => "[table 1].[column 1]"
inserts commas in lists:
  SELECT "c1" "c2" "c3" => "SELECT [c1], [c2], [c3]
and manages table aliases:
  SELECT table1.column FROM table1 AS t1
  => "SELECT [t1].[column] FROM [table1] AS [t1]"

It would also be nice if it knew what dialect of sql it is working with
and thus abstract away from that. Then one piece of code would know
how to make the sql statement correct for Microsoft jet, mysql, ANSI
SQL92, etc.

stringstream s << select << column("c1") << column("table1", "column2")
  from << table("table1").as("t1");

assert(s.str() == "SELECT [c1], [t1].[column2] FROM [table1] AS [t1]");

Is their a library that helps the user form sql statements in code?

I believe that a database library for boost should include something
like this.


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