Class ExecuteSqlCommand
java.lang.Object
org.labkey.remoteapi.Command<SelectRowsResponse>
org.labkey.remoteapi.PostCommand<SelectRowsResponse>
org.labkey.remoteapi.query.BaseQueryCommand<SelectRowsResponse>
org.labkey.remoteapi.query.ExecuteSqlCommand
- All Implemented Interfaces:
HasRequiredVersion
Command for executing arbitrary LabKey SQL.
LabKey SQL is variant of standard SQL that supports most of the SELECT-related operations. For more information on LabKey SQL, see the following page:
https://www.labkey.org/Documentation/wiki-page.view?name=labkeySql
The response of this command is exactly the same as the
SelectRowsCommand, so the response object
will be of type SelectRowsResponse.
JavaClientApiTest includes some testing of this command.
-
Nested Class Summary
Nested classes/interfaces inherited from class Command
Command.CommonParameters, Command.Response -
Field Summary
Fields inherited from class Command
CONTENT_TYPE_JSON -
Constructor Summary
ConstructorsConstructorDescriptionExecuteSqlCommand(String schemaName) Constructs an ExecuteSqlCommand, initialized with a schema name.ExecuteSqlCommand(String schemaName, String sql) Constructs an ExecuteSqlCommand, initialized with a schema name and SQL query. -
Method Summary
Modifier and TypeMethodDescriptionReturns a new, mutable parameter map.protected SelectRowsResponsecreateResponse(String text, int status, String contentType, org.json.JSONObject json) Creates an instance of the response class, initialized with the response text, the HTTP status code, and parsed JSONObject.org.json.JSONObjectReturns the JSON object to post or null for no JSON.Returns the current schema name.getSql()Returns the current SQL query.booleanbooleanReturns whether the extended format will be requested.booleanInclude the Details link column in the set of columns (defaults to false).booleanWhether the definition of this query should be stored for reuse during the current session.static StringquoteIdentifier(String identifier) voidsetExtendedFormat(boolean extendedFormat) Set to true to request the extended response format, which includes URLs, Missing-Value indicators and display values in addition to the raw values.voidsetIncludeDetailsColumn(boolean includeDetailsColumn) Include the Details link column in the set of columns (defaults to false).voidsetSaveInSession(boolean saveInSession) Whether the definition of this query should be stored for reuse during the current session.voidsetSchemaName(String schemaName) Sets the current schema name.voidDeprecated.voidSets the SQL query to execute.voidsetWafEncoding(boolean wafEncoding) By default, this command encodes the SQL parameter to allow it to pass through web application firewalls.Methods inherited from class BaseQueryCommand
addOffsetAndMaxRows, addSort, addSort, addSortAndParams, getContainerFilter, getMaxRows, getOffset, getQueryParameters, getSorts, isIncludeMetadata, isIncludeTotalCount, setContainerFilter, setIncludeMetadata, setIncludeTotalCount, setMaxRows, setOffset, setQueryParameters, setSortsMethods inherited from class PostCommand
createRequestMethods inherited from class Command
_execute, execute, getActionName, getControllerName, getHttpRequest, getParameters, getParamValueAsString, getRequiredVersion, getTimeout, setRequiredVersion, setTimeout
-
Constructor Details
-
ExecuteSqlCommand
Constructs an ExecuteSqlCommand, initialized with a schema name.When using this constructor, you must call the
setSql(String)method before executing the command.- Parameters:
schemaName- The schema name to query.
-
ExecuteSqlCommand
-
-
Method Details
-
setExtendedFormat
public void setExtendedFormat(boolean extendedFormat) Set to true to request the extended response format, which includes URLs, Missing-Value indicators and display values in addition to the raw values. Use the getRowset() method on the response to iterate over the returned rows in a format-neutral manner.- Parameters:
extendedFormat- True to get the extended format.
-
isExtendedFormat
public boolean isExtendedFormat()Returns whether the extended format will be requested. See setExtendedFormat() for details.- Returns:
- true if extended format will be requested.
-
getSchemaName
-
setSchemaName
Sets the current schema name.- Parameters:
schemaName- The new schema name to query.
-
getSql
-
setSql
-
setSort
Deprecated.UseBaseQueryCommand.setSorts(List)instead.- Parameters:
sorts- the sort specifications to apply to the query
-
isSaveInSession
public boolean isSaveInSession()Whether the definition of this query should be stored for reuse during the current session. If true, all information required to recreate the query will be stored on the server and a unique query name will be passed to the success callback. This temporary query name can be used by all other API methods, including Query Web Part creation, for as long as the current user's session remains active.- Returns:
- whether to save the query definition in session or not
-
setSaveInSession
public void setSaveInSession(boolean saveInSession) Whether the definition of this query should be stored for reuse during the current session. If true, all information required to recreate the query will be stored on the server and a unique query name will be passed to the success callback. This temporary query name can be used by all other API methods, including Query Web Part creation, for as long as the current user's session remains active.- Parameters:
saveInSession- indication of whether to save in session or not
-
isIncludeDetailsColumn
public boolean isIncludeDetailsColumn()Include the Details link column in the set of columns (defaults to false). If included, the column will have the name "~~Details~~". The underlying table/query must support details links or the column will be omitted in the response.- Returns:
- whether to include the details column in the set of columns
-
setIncludeDetailsColumn
public void setIncludeDetailsColumn(boolean includeDetailsColumn) Include the Details link column in the set of columns (defaults to false). If included, the column will have the name "~~Details~~". The underlying table/query must support details links or the column will be omitted in the response.- Parameters:
includeDetailsColumn- indication of whether to include the details column or not
-
getWafEncoding
public boolean getWafEncoding() -
setWafEncoding
public void setWafEncoding(boolean wafEncoding) By default, this command encodes the SQL parameter to allow it to pass through web application firewalls. This is compatible with LabKey Server v23.9.0 and above. If targeting an earlier server, pass false to this method. -
createResponse
protected SelectRowsResponse createResponse(String text, int status, String contentType, org.json.JSONObject json) Description copied from class:CommandCreates an instance of the response class, initialized with the response text, the HTTP status code, and parsed JSONObject.Override this method to create an instance of a different class that extends CommandResponse
- Overrides:
createResponsein classCommand<SelectRowsResponse>- Parameters:
text- The response text from the server.status- The HTTP status code.contentType- The Content-Type header value.json- The parsed JSONObject (or null if no JSON was returned).- Returns:
- An instance of the response object.
-
getJsonObject
public org.json.JSONObject getJsonObject()Description copied from class:PostCommandReturns the JSON object to post or null for no JSON. Override this method to provide parameters as JSON.- Overrides:
getJsonObjectin classBaseQueryCommand<SelectRowsResponse>- Returns:
- The JSON object to post.
-
createParameterMap
Description copied from class:CommandReturns a new, mutable parameter map. Derived classes will typically override this method to put values passed to specialized setter methods into the map.- Overrides:
createParameterMapin classCommand<SelectRowsResponse>- Returns:
- The parameter map to use when building the URL.
-
quoteIdentifier
-
BaseQueryCommand.setSorts(List)instead.