Click here to Skip to main content
15,896,118 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 415.6K   5.4K   133  
A helper framework for generation of SQL queries in C++ and Lua
#include <sqlpp/bindings/lua/table.hpp>
#include <luabind/luabind.hpp>

#include <sqlpp/field.hpp>
#include <sqlpp/table.hpp>
#include <sqlpp/properties/id_property.hpp>
#include <sqlpp/properties/name_property.hpp>
#include <sqlpp/properties/database_property.hpp>

namespace sqlpp{
namespace bindings{
namespace lua{

lua_State* lua_sqlppopen_table(lua_State* L)
{
	using namespace luabind;

	// table::set_primary_key overlaods
	primary_key_constraint_shared_ptr (table::* set_primary_key_fields)
		(field_container_const_reference, string_const_reference)
		= &table::set_primary_key;
	primary_key_constraint_shared_ptr (table::* set_primary_key_field)
		(field_shared_ptr, string_const_reference)
		= &table::set_primary_key;
	primary_key_constraint_shared_ptr (table::* set_primary_key_string)
		(string_const_reference, string_const_reference)
		= &table::set_primary_key;

	// table::add_unique overlaods
	unique_constraint_shared_ptr (table::* add_unique_fields)( 
		field_container_const_reference, 
		string_const_reference)
		= &table::add_unique;
	unique_constraint_shared_ptr (table::* add_unique_field)( 
		field_shared_ptr, 
		string_const_reference)
		= &table::add_unique;
	unique_constraint_shared_ptr (table::* add_unique_string)( 
		string_const_reference, 
		string_const_reference)
		= &table::add_unique;

	// table::add_foreign_key
	ref_constraint_shared_ptr (table::* add_foreign_key)(table_shared_ptr)	
		= & table::add_foreign_key;

	module(L, SQLPP_MODULE_NAME)
	[
		class_< 
			table
			,bases< 
				properties::id_property
				,properties::name_property
				,properties::database_property 
				,field_container
				>
			,table_shared_ptr 
			>("table")
			.def("get_pk", &table::get_primary_key)
			.def("get_field", &table::get_field)
			.def("add_pk", &table::add_primary_key)
			.def("add_fk", add_foreign_key)
			.def("add_field", &table::add_field)
			.def("set_pk", set_primary_key_fields )
			.def("set_pk", set_primary_key_field )
			.def("set_pk", set_primary_key_string )
			.def("add_u", add_unique_fields)
			.def("add_u", add_unique_field)
			.def("add_u", add_unique_string)
			.def("get_create_statement", &table::get_create_statement )
			.def("get_alter_create_statement", &table::get_alter_create_statement )
			.def("get_unique_statement", &table::get_unique_statement)
			.def("get_alter_primary_key", &table::get_alter_primary_key)
			.def("get_alter_foreign_keys", &table::get_alter_foreign_keys)
			.def("get_alter_unique_fields", &table::get_alter_unique_fields)
			.def("set_field_prefix", &table::set_field_prefix)
	];

	return L;
};

}; // lua
}; // bindings
}; // sqlpp

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