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 » Convert String to SqlId
Convert String to SqlId [message #19619] Tue, 23 December 2008 16:22 Go to next message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
I'm using the following code to query my database:

SqlId count("COUNT(*)");
sql * Select(count).From(sqlTable).Where(PRODUKT=="prohibis");


sqlTable is a String. How do i use these String as a SqlId? I get the following errors when compiling:

G:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(1048) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 
	'Upp::SqlVal' (or there is no acceptable conversion)
        C:\upp\uppsrc\Core/String.h(297): could be 'Upp::String &Upp::String::operator =(const char *)'
        C:\upp\uppsrc\Core/String.h(298): or       'Upp::String &Upp::String::operator =(const Upp::String &)'
        C:\upp\uppsrc\Core/String.h(299): or       'Upp::String &Upp::String::operator =(Upp::StringBuffer &)'
        while trying to match the argument list '(Upp::String, Upp::SqlVal)'
G:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(1052) : error C2668: 'Upp::SqlSelect::From' : ambiguous call to overloaded function
        c:\upp\uppsrc\sql\Sqlexp.h(454): could be 'Upp::SqlSelect &Upp::SqlSelect::From(const Upp::SqlVal &)'
        c:\upp\uppsrc\sql\Sqlexp.h(451): or       'Upp::SqlSelect &Upp::SqlSelect::From(Upp::SqlId)'
        while trying to match the argument list '(Upp::String)'
G:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(1052) : error C2228: left of '.Where' must have class/struct/union
prohibisZA: 1 file(s) built in (0:02.01), 2016 msecs / file, duration = 2047 msecs, parallelization 0%


I get no errors when i replace the String sqlTable with the SqlId KUNDEN which i defined in the schema-file:

sql * Select(count).From(KUNDEN).Where(PRODUKT=="prohibis");


How can i convert my String sqlTable into a SqlId?

[Updated on: Tue, 23 December 2008 16:52]

Report message to a moderator

Re: Convert String to SqlId [message #19620 is a reply to message #19619] Tue, 23 December 2008 18:39 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 696
Registered: December 2005
Location: Budapest, Hungary
Contributor
why don't you use SqlCountRows()?
sql * Select(SqlCountRows()).From(sqlTable).Where(PRODUKT=="prohibis");
Re: Convert String to SqlId [message #19621 is a reply to message #19619] Tue, 23 December 2008 19:12 Go to previous messageGo to next message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
ok, that's a replacement for my count-method, but the main-problem is how to use a String (sqlTable) as SqlId:

Sql sql(session);
SqlId all("*");
sql * Select(SqlCountRows()).From(sqlTable).Where(PRODUKT=="prohibis");


H:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(1049) : error C2668: 'Upp::SqlSelect::From' : ambiguous call to overloaded function
        c:\upp\uppsrc\sql\Sqlexp.h(454): could be 'Upp::SqlSelect &Upp::SqlSelect::From(const Upp::SqlVal &)'
        c:\upp\uppsrc\sql\Sqlexp.h(451): or       'Upp::SqlSelect &Upp::SqlSelect::From(Upp::SqlId)'
        while trying to match the argument list '(Upp::String)'
H:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(1049) : error C2228: left of '.Where' must have class/struct/union
prohibisZA: 1 file(s) built in (0:03.63), 3635 msecs / file, duration = 3697 msecs, parallelization 0%

There were errors. (0:04.68)

[Updated on: Tue, 23 December 2008 19:17]

Report message to a moderator

Re: Convert String to SqlId [message #19622 is a reply to message #19621] Tue, 23 December 2008 20:52 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 696
Registered: December 2005
Location: Budapest, Hungary
Contributor
sql * Select(SqlCountRows()).From(SqlId(sqlTable)).Where(PRODUKT=="prohibis");
Re: Convert String to SqlId [message #19623 is a reply to message #19619] Tue, 23 December 2008 21:18 Go to previous messageGo to next message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
Damn, so simple? Works fine, thank you.

But there's another question: How can i put my Where-Statement into a String?

String sqlWhere = "PRODUKT=='prohibis'";

sql * Select(SqlCountRows()).From(SqlId(sqlTable)).Where(sqlWhere);


This doesn't work.
Re: Convert String to SqlId [message #19624 is a reply to message #19623] Tue, 23 December 2008 21:46 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 696
Registered: December 2005
Location: Budapest, Hungary
Contributor
SqlBool sqlWhere = (PRODUKT=='prohibis');


And you can use code like this:
if(something_true){
    sqlWhere = sqlWhere && Like(SOME_FIELD, "a%");
}

See Sqlexp.h for more tricks.
Re: Convert String to SqlId [message #19625 is a reply to message #19619] Tue, 23 December 2008 22:31 Go to previous message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
Thank you zsolt, this helps me alot!

Previous Topic: problems with schema-file
Next Topic: Issue with getting data back from a sqlite3 database
Goto Forum:
  


Current Time: Fri Apr 19 04:23:33 CEST 2024

Total time taken to generate the page: 0.04099 seconds