Click here to Skip to main content
15,881,812 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.4K   5.4K   133  
A helper framework for generation of SQL queries in C++ and Lua
#include "test.h"

namespace
{
	LUABIND_ANONYMOUS_FIX int feedback = 0;
	LUABIND_ANONYMOUS_FIX int feedback2 = 0;

	struct A
	{
		A(int a) { feedback = a; }
		A(const A&) { feedback = 21; }
		A() { feedback = 20; }
		~A() { feedback = -1; }

	};

	void f(A*, const A&) {}

	struct B: public A
	{
		B(int a):A(a) { feedback2 = a; }
		B() { feedback2 = 20; }
		~B() { feedback2 = -1; }
	};

	struct C {};

} // anonymous namespace

bool test_construction()
{
	using namespace luabind;

	lua_State* L = lua_open();
	lua_closer c(L);
	int top = lua_gettop(L);

	open(L);

	module(L)
	[
		class_<A>("A")
			.def("f", &f)
			.def(constructor<int>())
			.def(constructor<const A&>())
			.def(constructor<>()),

		class_<B>("B")
			.def(constructor<int>())
			.def(constructor<>()),

		class_<C>("C")

	];

	if (dostring2(L, "a = C()") == 0) return false;
	lua_pop(L, 1); // pop error message

	if (dostring(L, "a = A(4)")) return false;
	if (feedback != 4) return false;

	if (dostring(L, "a2 = A(a)")) return false;
	if (feedback != 21) return false;

	if (dostring(L, "b = B(6)")) return false;
	if (feedback != 6) return false;
	if (feedback2 != 6) return false;

	if (dostring(L, "b2 = B()")) return false;
	if (feedback != 20) return false;
	if (feedback2 != 20) return false;

//	if (dostring(L, "a:f(a)")) return false;

	if (top != lua_gettop(L)) return false;

	c.release();
	if (feedback != -1) return false;
	if (feedback2 != -1) return false;

	return true;
}

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