Click here to Skip to main content
15,885,760 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 410.9K   5.4K   133  
A helper framework for generation of SQL queries in C++ and Lua
#include <sqlpp/field.hpp>
#include <sqlpp/table.hpp>
#include <sqlpp/database.hpp>


namespace sqlpp{

	field::field(
		table_shared_ptr table_,
		string_const_reference name_,
		string_const_reference type_,
		bool not_null_
		)
	:
	  properties::table_property(table_),
	  properties::name_property(name_),
	  m_not_null(not_null_)
	 {
		 m_type = data_type::from_string( type_ );
	 };


	field::field(
		table_shared_ptr table_,
		string_const_reference name_,
		data_type const& type_,
		bool not_null_
		)
	:
	  properties::table_property(table_),
	  properties::name_property(name_),
	  m_type(type_),
	  m_not_null(not_null_)
	 {};

string_type field::get_create_statement() const
{
	std::ostringstream out;

	out<<"\t"<<get_name()<<" "<<m_type.get_sql();
	if (is_not_null())
		out<<" NOT NULL";

	return out.str();
};

	void field::set_type( string_const_reference type_)
	{
		m_type  = data_type::from_string( type_ );
	}
	void field::set_type( data_type const& type_)
	{
		m_type  = type_;
	}
	data_type const& field::get_type() const
	{	return m_type;};
	bool field::is_not_null() const
	{	return m_not_null;};	
	void field::set_not_null( bool not_null_ )
	{	m_not_null = not_null_;};

};

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