Patent Document ID: 6128612
Application ID: 09106968

Base Claim:
1. A method, performed in a data processing system, for translating an an-hoc query input string to a string of common table expressions, the method comprising the computer implemented steps of: creating a postfix queue by parsing each item of the input string until all items are parsed: if the item is a joiner object or left parenthesis, adding the joiner object or left parenthesis to a temporary pushdown stack and then returning to parse the next item of the input string; if the item is a query clause, adding the query clause to the postfix queue, and if the object is a query clause or right parenthesis, if the temporary pushdown stack is empty, returning to parse the next item of the input string; if the temporary pushdown stack is not empty and the next item in the temporary pushdown stack is not a joiner object, returning to parse the next item of the input string; and if the temporary pushdown stack is not empty and the next item in the temporary pushdown stack is a joiner object, adding the next item in the pushdown stack to the postfix queue and returning to parse the next item of the input string; and processing each item of the postfix queue to translate the input string to an initially empty string of common table expressions until all items are processed: if the item is a query clause, forming a common table expression to return a unique key field of all records matching the specification of the query clause, placing that expression into a second temporary pushdown stack, appending the new common table expression to the initially empty string, and returning to process the next item of the postfix queue; and if the item is not a query clause: if the item is an "AND" joiner object, forming a common table expression to represent an "INNER JOIN" of the top two items of the second temporary pushdown stack, said expression returning a unique key field, replacing the top two items of the second temporary pushdown stack with the expression just created, appending the new common table expression to the initially empty string, and returning to process the next item of the postfix queue; if the item is an "OR" joiner object, forming a common table expression to represent a "UNION" of the top two items of the second temporary pushdown stack, said expression returning a unique key field, replacing the top two items of the second temporary pushdown stack with the expression just created, appending the new common table expression to the initially empty string, and returning to process the next item of the postfix queue; and if the item is a "NOT" joiner object, forming a common table expression to represent an "EXCLUDE" of the top item of the second temporary pushdown stack from the results of the second item of the second temporary pushdown stack, said expression returning a unique key field, replacing the top two items of the second temporary pushdown stack with the expression just created, appending the new common table expression to the initially empty string, and returning to process the next item of the postfix queue.

---

Claim 2:
2. The method of claim 1, further comprising the computer implemented steps, if all items in the postfix queue have been processed, of forming a common table expression to return items represented by the last expression in the second temporary pushdown stack; removing the last expression from the second temporary pushdown stack; and forming a final SELECT statement.