Create an ad-hoc query from a query definition

Prev Next

Queries stored in can be exported and duplicated in a script.

If you have an existing persistent query, and you can define it as an ad-hoc query using core.executeQuery. Use the Export Definitions action in to obtain the internal representation of the query. In almost all cases, the exported definition can be used to construct the core.executeQuery method call. For example, starting with an existing query as a model, then you modify the parameters, filtering, or sorting when executing the query from a script.

This is an example of using an exported persistent query to create an ad-hoc query.

Example

This is a typical exported query definition:

<query> 
  <name language="en">My AuditLogQuery</name> 
  <description language="en"></description> 
  <property name="target">OrionAuditLog</property> 
  <property name="tableURI">query:table?orion.table.columns=OrionAuditLog.UserName%3AOrionAuditLog.CmdName%3A
OrionAuditLog.Success%3AOrionAuditLog.StartTime&amp;orion.table.order.by=OrionAuditLog.CmdName
&amp;orion.table.order=asc</property> 
  <property name="conditionURI">query:condition?orion.condition.sexp=%28+where+%28+olderThan+
OrionAuditLog.EndTime+3600000++%29+%29</property> 
  <property name="summaryURI">query:summary?orion.sum.query=false&amp;orion.query.type=table.table</property> 
</query>

Dissect this definition as:

  • The target attribute is used directly as the target parameter of the ad-hoc query.

  • The conditionURI attribute contains the S-Expression to use as the where parameter.

In an S-expression, the SELECT clause mirrors the limitations of a SELECT SQL clause. The SELECT clause operations include columns and unary operations on table columns. For example, Count, Max, Top, and others.

The unary operators work on only one expression of any one of the data types of the numeric data type category. For example, you cannot use SUM, or any other aggregate operations, with SELECT.

Note

The best way to become familiar with what SELECT clause arguments are supported, and their limitations in an ad-hoc query S-expression, is to export queries and examine their structure.

Remember that the exported form of the query contains strings that are URL-encoded. To form a valid query string, decode the URL-encoded characters. For example:

  • "+" is used for a single space " "

  • %28 is an opening parenthesis "("

  • %29 is a closing parenthesis ")"

  • %3A is a colon ":"

This is the equivalent ad-hoc URL query using the exported query definition:

https://servername:port/remote/core.executeQuery?target=OrionAuditLog&select=(select OrionAuditLog.UserName OrionAuditLog.CmdName OrionAuditLog.Success OrionAuditLog.StartTime)&where=(where(olderThan OrionAuditLog.EndTime 36000000))&order=(order(asc OrionAuditLog.CmdName))

This is the equivalent ad-hoc Python query using the exported query definition:

mc.core.executeQuery(target="OrionAuditLog", 
select="(select OrionAuditLog.UserName OrionAuditLog.CmdName OrionAuditLog.Success OrionAuditLog.StartTime)",
where="(where(olderThan OrionAuditLog.EndTime 36000000))",
order="(order(asc OrionAuditLog.CmdName))");

This equivalent ad-hoc query returns this output:

OK:
User Name: ga
Priority: 1
Action: Login attempt
Details: Failed logon for user "ga" from IP Address: 172.1.5.1
Success: false
Start Time: 10/11/12 4:41:18 PM PDT
Completion Time: 10/11/12 4:41:18 PM PDT

User Name: system
Priority: 1
Action: Server restart
Details: Server was started.
Success: true
Start Time: 10/11/12 4:41:42 PM PDT
Completion Time: 10/11/12 4:41:42 PM PDT
.
.
.