*** UNDER CONSTRUCTION ***
Reverse Query
{
/*
This trigger fires formates a query using child/sibling variables and
fires this query in the parent/caller window.
Actions:
1. Determine if query is originating with parent or child.
2. If it is originating in the child then:
a. Construct an 'in' predicate using BNs from child window
b. Save values in query fields of child. (why do this?)
c. Run filter. (why do this?)
d. Run query trigger in parent using g.query_buf.
Problems:
1. What does g.save_val do? It is a flag for the field triggers:
{
char save_val[128];
if (g.save_val) save_val= field_d;
else field_d = save_val;
}
Pat McGreevy, 16 Feb 98
*/
int from_parent;
from_parent = true; /* initialize true */
/* if child in normal mode (p.mode=false) parent is calling so clear child */
if (!p.mode) { p.ar = 0; field_set(NULL); } /* clear if parent calling */
else { /* parent not calling */
query(query_max); /* run child query */
if (list_rows(p.wl)) { /* did child select returned data?*/
g.query_buf = NULL;
g.query_buf = "a.an in ("; /* start 'in' predicate */
while (list_rows(p.wl)) { /* append child variables */
g.query_buf = g.query_buf ^^ list_curr(p.wl,@p.bn);
list_mod(p.wl,0); /* delete curr row in child wl */
if (list_rows(p.wl)) g.query_buf = g.query_buf ^^ ",";
}
g.query_buf = g.query_buf ^^ ")"; /* finish 'in predicate' */
p.mode = 0; /* set child to normal mode */
g.save_val = true; /* set flag to save child fields */
field_exec(uat_noquery,false); /* save values in child qry flds */
/* window(start,query); run parent query/use g.qry_buf */
if (prompt("Filter results [N]: ") == "Y") {
g.save_val = false; /* reset save_val flag false */
field_set(NULL); /* clear child fields */
field_exec(uat_noquery,false); /* exe trg in child query fields */
from_parent = true;
g.save_val = true;
}
else from_parent = false;
}
refresh(false); /* turn off refresh temporarily */
}
if (from_parent) { /* run child query again ? */
status("Query in progress");
cursor_wait(true);
query(query_max,"a.bn = "^^start.bn);
status(query_count(G.query_buf)^^" rows returned");
G.query_buf = NULL; /* reset query_buf */
edit_win(p.wl,edt_refresh,false); /* refresh the window */
if (child) window(child,query); /* CHANGE TO RUN ONLY RUN IF OPEN */
else refresh(true);
}
}