Boost logo

Boost :

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

I think that most people either define their statement directly in code
(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 (ie SELECT "c1" "c2" "c3" => "SELECT [c1], [c2],
[c3]), and manages table aliases (ie SELECT table1.column FROM table1 AS
t1 => "SELECT [t1].[column] FROM [table1] AS [t1]"). It would also be
nice if it know what dialect of sql it is working with and thus abstract
away from that so one can have one piece of code know how to make the
sql statement correct for Microsoft jet, mysql, ANSI SQL92, etc.

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

=> "SELECT [c1], [t1].[column2] FROM [table1] AS [t1]"

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