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
Syntactic sugar [message #18767] Mon, 20 October 2008 14:22 Go to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

I think it would be nice to add to SqlId interface overloaded [] operator:
SqlCol operator [] (const SqlId& id) const;

which let us to write
Select(ID, CUSTOMER[NAME], PRODUCT[QUANTITY])...

insead of
Select(ID, NAME.Of(CUSTOMER), QUANTITY.Of(PRODUCT))...


What do you think?
Re: Syntactic sugar [message #18770 is a reply to message #18767] Mon, 20 October 2008 14:33 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

We could also add extended version of TABLE macro with alias parameter.
TABLE(CUSTOMER, CU)
END_TABLE

Select(CU[NAME], CU[AGE])
.From(CUSTOMER).As(CU) //of course As is not necessary here




Re: Syntactic sugar [message #18772 is a reply to message #18770] Mon, 20 October 2008 15:28 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

This is very good. When did it happen?

By the way. There is a tool - Clarion, - to create applications under Win.

There is construction
Nametable Table,Pre(Nam) 

and further in all fields table Nametable differ from the fields of other tables prefix Nam - it looks like this:
Nam:ID 
or 
Nam:Comment 

The design is very convenient. I wish that the UPP would be such a structure.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Syntactic sugar [message #18779 is a reply to message #18772] Mon, 20 October 2008 21:26 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
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

Re: Syntactic sugar [message #18780 is a reply to message #18779] Mon, 20 October 2008 22:04 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Doesn't matter what sign used in expression '.' or ':' .

Any case this form is better then FIELD.Of(TABLE)

How soon it will appear in a working version? Already want to write new Razz .


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Syntactic sugar [message #18782 is a reply to message #18780] Mon, 20 October 2008 22:18 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Another small question. How to show in single SqlArray fields from linked tables (as a Join)?

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Syntactic sugar [message #18911 is a reply to message #18770] Fri, 31 October 2008 14:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
unodgs wrote on Mon, 20 October 2008 08:33

We could also add extended version of TABLE macro with alias parameter.
TABLE(CUSTOMER, CU)
END_TABLE

Select(CU[NAME], CU[AGE])
.From(CUSTOMER).As(CU) //of course As is not necessary here







I am afraid this would be prone to collide with TABLE inheritance....

Mirek
Re: Syntactic sugar [message #18912 is a reply to message #18782] Fri, 31 October 2008 14:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Mon, 20 October 2008 16:18

Another small question. How to show in single SqlArray fields from linked tables (as a Join)?


Well, the most straightforward is not to use SqlArray Wink

What you want requires select from multiple tables. SqlArray is designed to support only one table.

Anyway, SqlArray has Join to create master-detail relation of two SqlArrays (or, in fact, you can Join SqlArray to ArrayCtrl too).

Mirek
Re: Syntactic sugar [message #18913 is a reply to message #18767] Fri, 31 October 2008 15:02 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
unodgs wrote on Mon, 20 October 2008 08:22

I think it would be nice to add to SqlId interface overloaded [] operator:
SqlCol operator [] (const SqlId& id) const;

which let us to write
Select(ID, CUSTOMER[NAME], PRODUCT[QUANTITY])...

insead of
Select(ID, NAME.Of(CUSTOMER), QUANTITY.Of(PRODUCT))...


What do you think?



Well, it felt a bit weird at first, but after a bit of thinking, I think this is quite natural.

Added. (And sorry for the delay, T++/A++ is really driving me insane Smile

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


Current Time: Mon Apr 29 00:45:40 CEST 2024

Total time taken to generate the page: 0.06287 seconds