|
|
Home » U++ Library support » U++ SQL » How to display fields from different tables in one SQLArray
template + convert problem [message #23153 is a reply to message #22348] |
Sat, 19 September 2009 14:22 |
|
I make a table in which multiple fields of reference from other tables. The mapping of the field from another table I made with the converter.
Now it looks as follows:
converts.h
struct ConvCompany : Convert
{
virtual Value Format(const Value& q) const;
};
struct ConvNomencl : Convert
{
virtual Value Format(const Value& q) const;
};
struct ConvManager : Convert
{
virtual Value Format(const Value& q) const;
};
converts.cpp:
Value ConvCompany::Format(const Value &q) const
{
if(q.IsNull()) return Null;
static VectorMap<int, String> comp;
static Time lastcleartime;
if(GetSysTime()-lastcleartime > 600){
comp.Clear();
lastcleartime=GetSysTime();
}
int f = comp.Find(int(q));
if(f >= 0){
return comp[f];
} else {
Sql sql;
sql * Select(COM_NAME).From(COMPANY).Where(COM_ID == q);
String company;
if(sql.Fetch()) {
int sid = int(q);
company = sql[COM_NAME];
comp.Add(sid, company);
} else {
company = "";
}
return company;
}
}
Value ConvNomencl::Format(const Value& q) const
{
if(q.IsNull()) return Null;
static VectorMap<int, String> nom;
static Time lastcleartime;
if(GetSysTime()-lastcleartime > 600){
nom.Clear();
lastcleartime=GetSysTime();
}
int f = nom.Find(int(q));
if(f >= 0){
return nom[f];
} else {
Sql sql;
sql * SqlSelect(NOM_ID,NOM_NAME).From(NOMENCL).Where(NOM_ID == q);
String nomencl;
if(sql.Fetch()) {
int sid = sql[NOM_ID];
nomencl = sql[NOM_NAME];
nom.Add(sid, nomencl);
} else {
nomencl = "";
}
return nomencl;
}
}
Value ConvManager::Format(const Value &q) const
{
if(q.IsNull()) return Null;
static VectorMap<int, String> man;
static Time lastcleartime;
if(GetSysTime()-lastcleartime > 600){
man.Clear();
lastcleartime=GetSysTime();
}
int f = man.Find(int(q));
if(f >= 0){
return man[f];
} else {
Sql sql;
sql * SqlSelect(USR_REALNAME).From(USER).Where(USR_ID == q);
String manager;
if(sql.Fetch()) {
int sid = int(q);
manager = sql[USR_REALNAME];
man.Add(sid, manager);
} else {
manager = "";
}
return manager;
}
}
These converters differ only in the name of the table and field names. I want this to be in the form of a template, something like:
template <SqlId TBL ,SqlId ID, SqlId NAME,int CLEARTIME>
struct ConvDict : Convert
//ConvDict<COMPANY,COM_ID,COM_NAME,600>()
{
virtual Value Format(const Value& q) const {
if(q.IsNull()) return Null;
static VectorMap<int, String> dict;
static Time lastcleartime;
if(GetSysTime()-lastcleartime > CLEARTIME){
dict.Clear();
lastcleartime=GetSysTime();
}
int f = dict.Find(int(q));
if(f >= 0){
return dict[f];
} else {
Sql sql;
sql * Select(NAME).From(TBL).Where(ID == q);
String s;
if(sql.Fetch()) {
int sid = int(q);
s = sql[NAME];
dict.Add(sid, s);
} else {
s = "";
}
return s;
}
}
};
But this code is not compiled, wrote that at this point can not be applied SqlId.
Can someone experienced with this?
How do make a template for the Converter, or Display?
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
|
|
|
|
|
How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: zsolt on Mon, 20 October 2008 14:20
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: zsolt on Mon, 20 October 2008 22:51
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: mirek on Sun, 02 November 2008 16:47
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: unodgs on Sun, 02 November 2008 19:09
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: unodgs on Sun, 02 November 2008 20:44
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: mirek on Sun, 02 November 2008 22:01
|
|
|
Re: How to display fields from different tables in one SQLArray
By: mirek on Sun, 02 November 2008 21:59
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: mirek on Wed, 12 November 2008 22:23
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: mirek on Sat, 15 November 2008 15:02
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
By: mirek on Sun, 02 November 2008 21:55
|
|
|
Re: How to display fields from different tables in one SQLArray
By: mr_ped on Fri, 20 March 2009 21:37
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
Re: How to display fields from different tables in one SQLArray
|
|
|
template + convert problem
|
|
|
Re: template + convert problem
By: Zbych on Sat, 19 September 2009 19:30
|
|
|
Re: template + convert problem
|
|
|
Re: template + convert problem
|
|
|
Re: template + convert problem
|
|
|
Re: template + convert problem
By: Zbych on Sun, 20 September 2009 15:47
|
|
|
Re: template + convert problem
|
|
|
Re: template + convert problem
|
Goto Forum:
Current Time: Thu May 23 09:28:11 CEST 2024
Total time taken to generate the page: 0.01889 seconds
|
|
|