Home » U++ Library support » TreeCtrl » off by 1 dynamic tree with sql: SOLVED
off by 1 dynamic tree with sql: SOLVED [message #53714] |
Fri, 24 April 2020 02:12  |
|
Hi all-
TIA
I go to draw the tree and I am off by one using postgres. If you have a second, can you see if something jumps off the page? I think it has something to do with the root. I'd like to change tree and create a branch for parent every time it encounters a master GL account.
It gives a result like :
basket weaving
-> auto
-> gas
-> maint
instead of
auto
-> gas
-> maint
PromptOK(" Lets go ");
VectorMap<String,int> vm;
Vector<int> v4;
Sql sql(m3_session);
sql.Clear();
int y = 0;
int n, n1 = 1;
sql.SetStatement("SELECT DISTINCT PFIELD, COUNT(*) from accounts GROUP BY GROUPING SETS (PFIELD) ");
sql.Execute();
while (sql.Fetch()) {
vm.Add(sql[0],sql[1]);
PromptOK(sql[0].ToString());
}
for (auto a: vm)
PromptOK(AsString(vm.GetCount()));
sql.SetStatement(Select(ACCTNUM, ACCTNAME).From(ACCOUNTS).OrderBy(ACCTNUM));
sql.Execute();
while (sql.Fetch()){
if ( vm.Find(sql[0])==1){
optree.Add(y, AsString(sql[1]));
PromptOK("okay");
// PromptOK(AsString(n));
} else {
optree.Add(0 , AsString(sql[1]));
}
++n;
++y;
}
PromptOK("Lets stop");
}
hI ALL AGAIN-
I think the chart of accounts are string and I was thinking it would sort it in number format. That is the bug. At least I hope so. I can figure that out if that is all that is going on. Thanks.
[Updated on: Fri, 24 April 2020 02:51] Report message to a moderator
|
|
|
Re: off by 1 dynamic tree with sql: SOLVED [message #53732 is a reply to message #53714] |
Sat, 25 April 2020 01:58  |
|
Hi all-
I just thought I'd share how I drew the tree with my chart of accounts...
thnx for all the cool help here. I'm working on making a very small budgeting application.
roboloki
void MyMain::RunSQL(){
Sql sql(m3_session);
sql.Clear();
int y = -0;
int n = 0;
int n1 = 1;
String mystr;
sql.SetStatement("SELECT DISTINCT PFIELD, COUNT(*) from accounts GROUP BY GROUPING SETS (PFIELD) order by pfield");
sql.Execute();
while (sql.Fetch()) {
mystr=sql[0];
if (mystr.Find('*') != -1){
vm.Add(sql[0],sql[1]);
// PromptOK(sql[0].ToString());
}
}
}
void MyMain::SlingTv() {
int n = 0;
int n1 = 0;
String mystr;
Sql sql(m3_session);
sql.Clear();
sql.SetStatement(Select(PFIELD,ACCTNUM, ACCTNAME).From(ACCOUNTS).OrderBy(ACCTNUM));
sql.Execute();
while (sql.Fetch()){
mystr=sql[0];
if ( mystr.Find('*') != -1){
//PromptOK(AsString(n1));
optree.Add(0, sql[2].ToString());
}
}
sql.SetStatement(Select(PFIELD,ACCTNUM, ACCTNAME).From(ACCOUNTS).OrderBy(ACCTNUM));
sql.Execute();
while (sql.Fetch()){
mystr=sql[0];
if ( mystr.Find('*') != -1){
//PromptOK(AsString(n1));
n1 = 0;
PromptOK(AsString(n)+":n");
++n;
continue;
} else {
optree.Insert(n,n1,sql[2].ToString());
n1++;;
PromptOK(AsString(n1 )+":n1");
}
}
// optree.Insert(5,0,"foo");
// optree.Insert(5,1,"foo2");
// optree.Add(
}
|
|
|
Goto Forum:
Current Time: Sat Apr 26 14:26:28 CEST 2025
Total time taken to generate the page: 0.03584 seconds
|