Home » U++ Library support » U++ SQL » Syntactic sugar
Re: Syntactic sugar [message #18779 is a reply to message #18772] |
Mon, 20 October 2008 21:26   |
|
Try this :
#include <Core/Core.h>
#include <Sql/Sql.h>
using namespace Upp;
struct CustomerTable
{
const SqlId ID;
const SqlId NAME;
const SqlId AGE;
operator SqlId()
{
return SqlId("CUSTOMER");
}
CustomerTable() :
ID("CUSTOMER.ID"),
NAME("CUSTOMER.NAME"),
AGE("CUSTOMER.AGE")
{}
};
CustomerTable CUSTOMER;
#define CUS CUSTOMER //alias
CONSOLE_APP_MAIN
{
SqlSelect s =
::Select(CUSTOMER.NAME, CUSTOMER.AGE)
.From(CUSTOMER)
.Where(CUS.ID == 10);
SqlStatement stmt = s;
Cout() << stmt.GetText() << '\n';
}
If we expand TABLE macros in this way it would be possible to use natural SQL field qualification.
If you would like to use :: instead dot you should declare all SqlId's inside the CustomerTable as static, but this is a more complicated way and there is a problem with From.
Anyway I think I'll explore my new approach
[Updated on: Mon, 20 October 2008 21:27] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue Jun 24 17:57:34 CEST 2025
Total time taken to generate the page: 0.03010 seconds
|