When using the Query API calls, one must remember that the command PA_OpenQuery returns a PA_QueryRef, and that you must use the PA_QueryRef in all other Query API calls with the exception of the PA_CloseQuery command. This can be an easy omission to make when writing code since one does not usually think about this variable, but is instead thinking about what tables, fields, and comparison operators to use.
The PA_OpenQuery command will always return a PA_QueryRef variable as shown below.
PA_QueryRef queryReference;
queryReference = PA_OpenQuery(TableNumber);
Once you have returned a value into the queryReference variable, you then need to pass this variable to all subsequent PA_QueryXXX calls, where XXX is Longint, Date, and so on. Below we have made a call to the PA_QueryLongint command.
PA_QueryLongint(queryReference, TableNum, FieldNum, eQO_NoOperator, eQC_IsEqual, longintValue);
Notice the first variable is the queryReference.
Finally, it is not necessary to use the PA_QueryRef command in the PA_CloseQuery API call. This API does not take any parameters.
So remember to return a PA_QueryRef variable when calling PA_OpenQuery, and to then use this variable in each of your PA_QueryXXX calls.