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 » Developing U++ » U++ TheIDE and Library: Releases and ChangeLogs » Some Sql addidtions
Some Sql addidtions [message #16562] Thu, 26 June 2008 14:56 Go to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Recently I made possible to write select in select fields list:
SQL * ::Select(
   ID, 
   NAME, 
   ::Select(NAME, AGE).From(PARENTS).Where(KID_ID == ID),
   PHONE
).From(KIDS)

..and conditions
SQL * ::Select(
  X == Y,
  NUMBER < 100,
).From(TABLE)

SqlNvl has now As() method so it's possible to write:
SQL * ::Select(
   (QUANTITY * PRICE).As(FINAL_PRICE)
   (NAME | SURNAME).As(FULL_NAME)
).From(PRICES)

It's also possible to write cases:
SQL * ::Select(
  ID,
  Case(AGE < 5, "Baby")
      (Between(AGE, 5, 10), "Kid")
      ("Young man"),
  NAME
.From(PERSONS)

Re: Some Sql addidtions [message #16567 is a reply to message #16562] Thu, 26 June 2008 20:13 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
This is very-very useful, thanks!
Re: Some Sql addidtions [message #16573 is a reply to message #16567] Fri, 27 June 2008 23:16 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

How about to write SQL queries as a simple text?
for example:
Quote:

Query *q;
q->SetText ( "SELECT SomeColumns FROM SomeTable WHERE SomeCondition = &SomeParameter GROUP BY SomeGoups HAVING SomeHavingCondition..." )
?
and after then we can set parameter value;
Quote:

q->SetParameter ( "SomeParameter", parameter_value );


after then we can do:

Quote:

QResult *q_result = q->Execute ();

QChoose q_chouse = q_result->Choose ();

while ( q_chouse->Next () ) {...}


or

Quote:

Array q_res = q->Execute ()->Unload ();


How about thi idea? I thing that this is more simple... and will be possible for sent to an server application only query text!

[Updated on: Fri, 27 June 2008 23:19]

Report message to a moderator

Re: Some Sql addidtions [message #16576 is a reply to message #16573] Sat, 28 June 2008 10:25 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
Sorry, but Ultimate++ is much better, than your suggestion Smile

Just read "SQL programming" section in Overview.
Re: Some Sql addidtions [message #16577 is a reply to message #16576] Sat, 28 June 2008 12:18 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
If you need something like that, check out mysql++.
Re: Some Sql addidtions [message #16578 is a reply to message #16573] Sat, 28 June 2008 13:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
tojocky wrote on Fri, 27 June 2008 17:16

How about to write SQL queries as a simple text?
for example:
Quote:

Query *q;
q->SetText ( "SELECT SomeColumns FROM SomeTable WHERE SomeCondition = &SomeParameter GROUP BY SomeGoups HAVING SomeHavingCondition..." )
?
and after then we can set parameter value;
Quote:

q->SetParameter ( "SomeParameter", parameter_value );


after then we can do:

Quote:

QResult *q_result = q->Execute ();

QChoose q_chouse = q_result->Choose ();

while ( q_chouse->Next () ) {...}


or

Quote:

Array q_res = q->Execute ()->Unload ();


How about thi idea? I thing that this is more simple... and will be possible for sent to an server application only query text!


You can. That is U++'s "low-level".

E.g.

Sql sql;
sql.Execute("select foo from bar");
....

Mirek
Re: Some Sql addidtions [message #16581 is a reply to message #16578] Sat, 28 June 2008 23:30 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Thank you Mirek! I like this "low level" query!

I tried to compile example package and get folow error:

Quote:

C:\uppdev\examples\SQLApp\query.cpp(17) : error C2593: 'operator ==' is ambiguous
c:\uppdev\uppsrc\sql\Sqlexp.h(346): could be 'Upp::SqlBool Upp::operator ==(const Upp::SqlVal &,const Upp::SqlSet &)'
c:\uppdev\uppsrc\sql\Sqlexp.h(308): or 'Upp::SqlBool Upp::operator ==(const Upp::SqlVal &,const Upp::SqlVal &)'
while trying to match the argument list '(Upp::SqlId, Upp::SqlSelect)'

[Updated on: Sat, 28 June 2008 23:37]

Report message to a moderator

Re: Some Sql addidtions [message #16582 is a reply to message #16581] Sun, 29 June 2008 00:46 Go to previous messageGo to next message
bytefield is currently offline  bytefield
Messages: 210
Registered: December 2007
Experienced Member
Well, maybe someone should do a more consistent tutorial on how is made SQL interface in upp, what you can do with and how to do, because the Overview is a bit unclear in explaining SQL stuff. And what about those macros (TABLE, INT, INT_), where exist an explication on how to use SQL schema with upp because examples are complicated (them use SQL without any explanation) or them don't use all features of SQL. I bet that upp don't implement all SQL stuff defined by standard Rolling Eyes so sometimes is good to use "low-level interface" specially when you don't have e good explanation of "high-level interface" or when you have to do your work in the hard way Rolling Eyes . So will be there an experienced upp user and a well-wisher which will do a tutorial or you think that the hard way of learning something is always the best?
Without any annoyance guys, that's my opinion.

Andrei


cdabbd745f1234c2751ee1f932d1dd75
Re: Some Sql addidtions [message #16584 is a reply to message #16581] Sun, 29 June 2008 18:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
tojocky wrote on Sat, 28 June 2008 17:30

Thank you Mirek! I like this "low level" query!

I tried to compile example package and get folow error:

Quote:

C:\uppdev\examples\SQLApp\query.cpp(17) : error C2593: 'operator ==' is ambiguous
c:\uppdev\uppsrc\sql\Sqlexp.h(346): could be 'Upp::SqlBool Upp::operator ==(const Upp::SqlVal &,const Upp::SqlSet &)'
c:\uppdev\uppsrc\sql\Sqlexp.h(308): or 'Upp::SqlBool Upp::operator ==(const Upp::SqlVal &,const Upp::SqlVal &)'
while trying to match the argument list '(Upp::SqlId, Upp::SqlSelect)'



Please, when posting a problem like this, mention the compiler (and platform, but it is obvious here Smile

Mirek
Re: Some Sql addidtions [message #16585 is a reply to message #16584] Sun, 29 June 2008 21:03 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Sun, 29 June 2008 19:15

tojocky wrote on Sat, 28 June 2008 17:30

Thank you Mirek! I like this "low level" query!

I tried to compile example package and get folow error:

Quote:

C:\uppdev\examples\SQLApp\query.cpp(17) : error C2593: 'operator ==' is ambiguous
c:\uppdev\uppsrc\sql\Sqlexp.h(346): could be 'Upp::SqlBool Upp::operator ==(const Upp::SqlVal &,const Upp::SqlSet &)'
c:\uppdev\uppsrc\sql\Sqlexp.h(308): or 'Upp::SqlBool Upp::operator ==(const Upp::SqlVal &,const Upp::SqlVal &)'
while trying to match the argument list '(Upp::SqlId, Upp::SqlSelect)'



Please, when posting a problem like this, mention the compiler (and platform, but it is obvious here Smile

Mirek

Sorry!

platform is Win32 xp, Compiler is MSC8 optimal!
Re: Some Sql addidtions [message #16586 is a reply to message #16562] Mon, 30 June 2008 09:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
unodgs wrote on Thu, 26 June 2008 08:56

Recently I made possible to write select in select fields list:
SQL * ::Select(
   ID, 
   NAME, 
   ::Select(NAME, AGE).From(PARENTS).Where(KID_ID == ID),
   PHONE
).From(KIDS)

..and conditions
SQL * ::Select(
  X == Y,
  NUMBER < 100,
).From(TABLE)

SqlNvl has now As() method so it's possible to write:
SQL * ::Select(
   (QUANTITY * PRICE).As(FINAL_PRICE)
   (NAME | SURNAME).As(FULL_NAME)
).From(PRICES)

It's also possible to write cases:
SQL * ::Select(
  ID,
  Case(AGE < 5, "Baby")
      (Between(AGE, 5, 10), "Kid")
      ("Young man"),
  NAME
.From(PERSONS)




Well, you have broken SqlExp in the process Smile

/*
SqlVal::SqlVal(const SqlSelect& x) {
	SetHigh('(' + ((SqlStatement) x).GetText() + ')');
}

SqlVal::SqlVal(const SqlBool& x) {
	SetHigh(~x);
}
*/


I had to comment these, otherwise I am getting a lot of errors like the one tojocky mentions.

Mirek
Re: Some Sql addidtions [message #16587 is a reply to message #16586] Mon, 30 June 2008 09:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, to avoid this situation in the future, I have moved my "SqlExp documentation examples" package to reference/SqlExp.

This should have two nice purposes:

When you add something new to SqlExp, add example of it to this package. And, by compiling it, there should be a bit of safeguarding against these kinds of bugs...

Mirek
Re: Some Sql addidtions [message #16589 is a reply to message #16587] Mon, 30 June 2008 12:05 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

luzr wrote on Mon, 30 June 2008 03:36

Well, to avoid this situation in the future, I have moved my "SqlExp documentation examples" package to reference/SqlExp.

This should have two nice purposes:

When you add something new to SqlExp, add example of it to this package. And, by compiling it, there should be a bit of safeguarding against these kinds of bugs...

Mirek

Good idea. I'll try to fix that (In my app there are so many sqls so I thought I hadn't broken anything..)
Re: Some Sql addidtions [message #16593 is a reply to message #16589] Mon, 30 June 2008 21:04 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Another solution (at least for SqlApp) is to comment
inline SqlBool operator==(const SqlVal& a, const SqlSet& b) { return In(a, b); }
inline SqlBool operator!=(const SqlVal& a, const SqlSet& b) { return NotIn(a, b); }

and using directly In or NotIn instead of SqlVal !=/== SqlSet. IMO it's more readable, but for now I'll leave it as it is. I'll try to find solution without compromise.
Re: Some Sql addidtions [message #16595 is a reply to message #16593] Mon, 30 June 2008 21:31 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
unodgs wrote on Mon, 30 June 2008 15:04

and using directly In or NotIn instead of SqlVal !=/== SqlSet. IMO it's more readable, but for now I'll leave it as it is. I'll try to find solution without compromise.


Well, that would lead to about 1000 errors in my code Wink

Not an option!

Besides, != and == are really quite intuitive. Tom introduced them originally and I resisted... tried to use In / NotIn but than catched myself thinking in "==" "!=" terms (is there any value in the set equal?)

Mirek
Previous Topic: One more sql news
Next Topic: Small new theide enhancement...
Goto Forum:
  


Current Time: Fri Mar 29 09:47:29 CET 2024

Total time taken to generate the page: 0.01691 seconds