Click here to Skip to main content
15,891,529 members
Articles / Database Development / SQL Server

A scripted SQL query generation framework with IDE: SQLpp (v1.4)

Rate me:
Please Sign up or sign in to vote.
4.98/5 (47 votes)
12 Sep 200311 min read 413.1K   5.4K   133  
A helper framework for generation of SQL queries in C++ and Lua
#include <sqlpp/constraint.hpp>
#include <sqlpp/field.hpp>
#include <sqlpp/table.hpp>

namespace sqlpp
{

constraint::constraint( 
		table_shared_ptr table_,
		string_const_reference name_,
		field_container_const_reference fields_
		)
	: 
		properties::table_property(table_),
		properties::name_property(name_),
		field_map(*table_, fields_)
{};

string_type constraint::get_sql_name() const
{
	if (!get_name().empty())
		return get_name();

	std::ostringstream out;

	out<<get_small_type_string()<<"_"<<get_checked_table()->get_name()<<"_"<<get_field_list("_");

	return out.str();
};

string_type constraint::get_sql() const
{
	if (empty())
		return string_type();

	string_type field_list = get_field_list(",");
	if (field_list.empty())
		return string_type();

	table_shared_ptr table=get_checked_table();

	std::ostringstream out;
	out<<"\tCONSTRAINT "<<get_sql_name()<<" "<<get_type_string()<<" ("<<field_list<<")";

	return out.str();
};

};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions