Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

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 Smile

[Updated on: Mon, 20 October 2008 21:27]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: linking error trying to compile SQL_MySql demo on linux fedora 9
Next Topic: SQL*, SQL&, SQL*:: ???
Goto Forum:
  


Current Time: Tue Jun 24 08:30:14 CEST 2025

Total time taken to generate the page: 0.05352 seconds