The Standard Query Builder
The standard query builder is used for creating queries for all data tables in Leapfrog Energy except for imported points data tables. For information on building queries for points data tables, see The Points Query Builder.
To create a query filter for a data table, right-click on the table in the project tree and select New Query Filter. The New Query Filter window will appear and you can choose which way you prefer to build your query. Assign the filter a name and click OK to save it. It will appear in the project tree under the table to which it applies:
Query filters defined for collar tables are available to all other drilling data tables.
There are three windows that make up the standard query builder:
In the first window, the New Query Filter window, you can type in a query using the query syntax described in Leapfrog Energy Query Syntax. Press Ctrl-Enter for a new line in longer queries.
The second window, the Build Query window helps you build some common queries by selecting from the data columns in the table and defining different tests. Open this window by clicking the Build Query button in the New Query Filter window. See The Build Query Window for more information on building queries in this way.
The third window, the Advanced Query window, shows all the data columns and possible operations. See The Advanced Query Builder for more information.
Leapfrog Energy Query Syntax
The Leapfrog Energy query syntax is based on the WHERE clause of the Structured Query Language (SQL) with some restrictions:
- Unary operators are not allowed
- SQL functions cannot be used
- The SELECT statement should not be used (as in 'holeid in (SELECT holeid FROM ...)')
- Following statements are also prohibited: CASE, WHEN or MATCH
There is also one main SQL extension:
- IN and NOT IN will accept a partition group for the value list. E.g. 'zone IN layers.weathered' where "layers" is a partition of the "zone" column that has a group called 'weathered'.
These are some examples of valid Leapfrog Energy query statements:
- holeid in ('m-001', 'm-002')
- holeid not in ('m-001', 'm-002')
- holeid not like 'MAR%'
To enter a query that contains an apostrophe, enter two apostrophes. Adding the second apostrophe lets the query builder treat this as a mid-phrase apostrophe instead of an end-of-phrase marker, and results in a valid query.
The Query box allows the following shortcut queries:
- Typing a single word will match all hole-ids starting with that string. For example, typing "MAR" is a shortcut for "holeid like 'MAR%'"
- Typing a comma-separated list of words will match all hole-ids that exactly match the given words. For example typing "M001, M002" is a shortcut for "holeid in ('M001', 'M002')".
The Build Query Window
Many common queries can be built using the Build Query window:
This window aims to be easy to use rather than comprehensive in its support for the full Leapfrog Energy query syntax.
To add a criteria, click Column to view a list of columns available in the table. Select a Test and enter a Value. What can be entered for the Value depends on the type of column and test selected.
Quotes are not required around text values entered in the value column as they are in SQL. Leapfrog Energy will add quotes and brackets to the value "MX, PM" to make a valid SQL list of strings "('MX', 'PM')" when the query is saved.
Once Column and Test have been entered, if the Column is an enumerated list of values, a button is enabled in the Build column to assist in selecting the Value. When clicked, the Select column values window opens, allowing the desired values to be selected from the list of available options.
Search for items in a list by pressing Ctrl-F. A Find window will appear that you can use to search the list. You can choose whether or not to match case in the search and whether or not to match the whole label. You can search forwards or backwards and you can select all list items that match the current search.
Click on the Apply button to apply the query to the context in which the dialog was opened.
Use the Delete button to delete the criteria in the selected row and the Add button to add a blank row.
The Advanced Query Builder
The Advanced Query window provides a powerful and flexible query building using the Leapfrog Energy query language.
Enter the query in the Criteria to Match area on the left. The query is displayed as a tree structure with AND and OR terms as the branch nodes and conditions as the leaves. Use the Delete button to delete a row from the query and the Add button to add a blank row. The Check button can be used at any time to check if the current query statement is valid. Below the buttons is a box showing the raw SQL form of the query.
Except for the arrow buttons, the buttons down the middle of the dialog are used for entering values into the query. The arrow buttons are used for moving the currently selected criteria to a different position in the query. The Date, List and Value buttons will open a builder dialog for the column selected in the current row. If there is no column found or the column is of the wrong type, an error message is displayed.
The tree on the right contains all the columns available to the query. Double-click on a column name to insert it into the query.