Home » U++ Library support » U++ SQL » Syntactic sugar
Syntactic sugar [message #18767] |
Mon, 20 October 2008 14: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?
|
|
|
Re: Syntactic sugar [message #18770 is a reply to message #18767] |
Mon, 20 October 2008 14: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
|
|
|
Re: Syntactic sugar [message #18772 is a reply to message #18770] |
Mon, 20 October 2008 15:28   |
|
This is very good. When did it happen?
By the way. There is a tool - Clarion, - to create applications under Win.
There is construction
and further in all fields table Nametable differ from the fields of other tables prefix Nam - it looks like this:
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   |
|
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
|
|
|
|
Re: Syntactic sugar [message #18782 is a reply to message #18780] |
Mon, 20 October 2008 22:18   |
|
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 #18913 is a reply to message #18767] |
Fri, 31 October 2008 15:02  |
 |
mirek
Messages: 14255 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 
Mirek
|
|
|
Goto Forum:
Current Time: Mon Apr 28 20:38:27 CEST 2025
Total time taken to generate the page: 0.00815 seconds
|