We often need to useCodeCreate a query. The sysquery class provides the queryfromtablerelation method. Of course, the code of this method is exactly the same as the process of constructing a query based on the relationship between tables, however, it is made into a general method, and you don't need to repeat it every time by calling it directly. In addition, there are several good methods in sysquery. It is worth looking at source.
Public static query queryfromtablerelation (Common _ parenttable, tableid _ relationtableid, Boolean _ update = false, Boolean _ norelationnorecords = true)
Function: Construct a query based on the table relationship.
Parameter description:
_ Parenttable: parent table
_ Relationtableid: child table ID
_ Update: whether to allow query to update database records
_ Norelationnorecords: records are not returned if there is no relationship, which is implemented by the following statement:
If (_ Norelationnorecords && Dictrelation. Lines () = 0 )
{
Query. datasourcetable (_ relationtableid). addrange (fieldnum (common, tableid). Value (queryvalue (0));
}
Call example:Query querysalesparmline (Boolean _ forupdate= False)
{
ReturnSysquery: queryfromtablerelation (This, Tablenum (salesparmline), _ forupdate );
}
The code of this function is pretty. It can be seen as the sample code of the dictionraltaion application.