Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Please help me make this better
Please help me make this better [message #8560] |
Sat, 17 March 2007 19:53  |
MikeyV
Messages: 20 Registered: February 2007
|
Promising Member |
|
|
Hi,
I have a rather cumbersome block of code that I would like to streamline.
void Sats3::DoDrops() {
// Populate the drop lists
SQL*Select(Code).From(Generation);
while(SQL.Fetch())
ist.dGen.Add(SQL[0]);
SQL*Select(Code).From(EdCode);
while(SQL.Fetch())
ist.dEdCode.Add(SQL[0]);
SQL*Select(Code).From(Sex);
while(SQL.Fetch())
ist.dSex.Add(SQL[0]);
SQL*Select(Code).From(Race);
while(SQL.Fetch())
ist.dRace.Add(SQL[0]);
SQL*Select(Code).From(Ethnic);
while(SQL.Fetch())
ist.dEthnic.Add(SQL[0]);
SQL*Select(Code).From(EnlType);
while(SQL.Fetch())
ist.dEnlType.Add(SQL[0]);
SQL*Select(Code).From(Area);
while(SQL.Fetch())
mis.txtOpsArea.Add(SQL[0]);
}
As you can see, it just does the same thing over and over. I was thinking something like this:
void SATS3::Populate (const char *field, const char *table, const char *tab, const char *control) {
SQL*Select(field).From(table);
while(SQL.Fetch())
tab.control.Add(SQL[0]);
}
And then call it like this:
Populate("Code", "Area", "ist", "dEnlType");
Any suggestions?
Mike
|
|
|
|
|
|
|
Re: Please help me make this better [message #8565 is a reply to message #8560] |
Sun, 18 March 2007 07:23   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
MikeyV wrote on Sat, 17 March 2007 14:53 |
As you can see, it just does the same thing over and over. I was thinking something like this:
void SATS3::Populate (const char *field, const char *table, const char *tab, const char *control) {
SQL*Select(field).From(table);
while(SQL.Fetch())
tab.control.Add(SQL[0]);
}
And then call it like this:
Populate("Code", "Area", "ist", "dEnlType");
Any suggestions?
Mike
|
Yes, that is a good idea. We had it too 
tab.control *= Select(Code).From(Generation);
Note that often you will want to fetch pairs (key - name), then
tab.contro *= Select(Key, Code).From(Generation);
Works for DropList and MapConvert.
Mirek
|
|
|
Re: Please help me make this better [message #8567 is a reply to message #8565] |
Sun, 18 March 2007 09:35   |
MikeyV
Messages: 20 Registered: February 2007
|
Promising Member |
|
|
Sweet!
Thanks Mirek
EDIT: Bah...spoke too soon.
ist is my tab, and dGen is my droplist. So I have :
ist.dGen *= Select(Code).From(Generation);
Linker returns:
C:\Development\MyApps\Sats3\Sats3.cpp(16) : error C2678: binary '*=' : no operator found which takes a left-hand operand of type 'Upp::D
ropList' (or there is no acceptable conversion)
C:\Development\upp\uppsrc\Core/Gtypes.h(582): could be 'Upp::Size &Upp::operator *=(Upp::Size &,double)'
C:\Development\upp\uppsrc\Core/Gtypes.h(596): or 'Upp::Size &Upp::operator *=(Upp::Size &,Upp::Sizef)'
C:\Development\upp\uppsrc\Core/Gtypes.h(617): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,double)'
C:\Development\upp\uppsrc\Core/Gtypes.h(631): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,Upp::Sizef)'
C:\Development\upp\uppsrc\RichText/RichText.h(37): or 'void Upp::operator *=(int &,Upp::Zoom)'
C:\Development\upp\uppsrc\RichText/RichText.h(42): or 'void Upp::operator *=(Upp::Rect &,Upp::Zoom)'
c:\development\upp\uppsrc\richtext\Para.h(282): or 'void Upp::operator *=(Upp::RichPara::Format &,Upp::Zoom)'
c:\development\upp\uppsrc\sql\Sqlexp.h(191): or 'Upp::SqlVal &Upp::operator *=(Upp::SqlVal &,const Upp::SqlVal &)'
while trying to match the argument list '(Upp::DropList, Upp::SqlSelect)'
[Updated on: Sun, 18 March 2007 09:48] Report message to a moderator
|
|
|
Re: Please help me make this better [message #8568 is a reply to message #8567] |
Sun, 18 March 2007 11:06   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
MikeyV wrote on Sun, 18 March 2007 04:35 | Sweet!
Thanks Mirek
EDIT: Bah...spoke too soon.
ist is my tab, and dGen is my droplist. So I have :
ist.dGen *= Select(Code).From(Generation);
Linker returns:
C:\Development\MyApps\Sats3\Sats3.cpp(16) : error C2678: binary '*=' : no operator found which takes a left-hand operand of type 'Upp::D
ropList' (or there is no acceptable conversion)
C:\Development\upp\uppsrc\Core/Gtypes.h(582): could be 'Upp::Size &Upp::operator *=(Upp::Size &,double)'
C:\Development\upp\uppsrc\Core/Gtypes.h(596): or 'Upp::Size &Upp::operator *=(Upp::Size &,Upp::Sizef)'
C:\Development\upp\uppsrc\Core/Gtypes.h(617): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,double)'
C:\Development\upp\uppsrc\Core/Gtypes.h(631): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,Upp::Sizef)'
C:\Development\upp\uppsrc\RichText/RichText.h(37): or 'void Upp::operator *=(int &,Upp::Zoom)'
C:\Development\upp\uppsrc\RichText/RichText.h(42): or 'void Upp::operator *=(Upp::Rect &,Upp::Zoom)'
c:\development\upp\uppsrc\richtext\Para.h(282): or 'void Upp::operator *=(Upp::RichPara::Format &,Upp::Zoom)'
c:\development\upp\uppsrc\sql\Sqlexp.h(191): or 'Upp::SqlVal &Upp::operator *=(Upp::SqlVal &,const Upp::SqlVal &)'
while trying to match the argument list '(Upp::DropList, Upp::SqlSelect)'
|
Do you have
#include <SqlCtrls/SqlCtrls.h>
?
Mirek
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 03:34:48 CEST 2025
Total time taken to generate the page: 0.00864 seconds
|