1717
1818import org .json .JSONObject ;
1919import org .labkey .remoteapi .PostCommand ;
20+ import org .labkey .remoteapi .internal .EncodeUtils ;
2021
2122import java .util .HashMap ;
2223import java .util .List ;
@@ -47,6 +48,7 @@ public class ExecuteSqlCommand extends PostCommand<SelectRowsResponse> implement
4748 private boolean _saveInSession = false ;
4849 private boolean _includeDetailsColumn = false ;
4950 private Map <String , String > _queryParameters = new HashMap <>();
51+ private boolean _wafEncoding = true ;
5052
5153 /**
5254 * Constructs an ExecuteSqlCommand, initialized with a schema name.
@@ -198,7 +200,7 @@ public void setIncludeTotalCount(boolean includeTotalCount)
198200 The value of this property should be a comma-delimited list of column names you want to sort by.
199201 Use a - prefix to sort a column in descending order
200202 (e.g., 'LastName,-Age' to sort first by LastName, then by Age descending).
201- @return the set of sorts to apply
203+ @return the list of sorts to apply
202204 */
203205 public List <Sort > getSorts ()
204206 {
@@ -219,7 +221,7 @@ public void setSort(List<Sort> sorts)
219221 }
220222
221223 /**
222- * Whether or not the definition of this query should be stored for reuse during the current session.
224+ * Whether the definition of this query should be stored for reuse during the current session.
223225 * If true, all information required to recreate the query will be stored on the server and a unique query name
224226 * will be passed to the success callback. This temporary query name can be used by all other API methods,
225227 * including Query Web Part creation, for as long as the current user's session remains active.
@@ -231,7 +233,7 @@ public boolean isSaveInSession()
231233 }
232234
233235 /**
234- * Whether or not the definition of this query should be stored for reuse during the current session.
236+ * Whether the definition of this query should be stored for reuse during the current session.
235237 * If true, all information required to recreate the query will be stored on the server and a unique query name
236238 * will be passed to the success callback. This temporary query name can be used by all other API methods,
237239 * including Query Web Part creation, for as long as the current user's session remains active.
@@ -267,7 +269,7 @@ public void setIncludeDetailsColumn(boolean includeDetailsColumn)
267269 /**
268270 Map of name (string)/value pairs for the values of parameters if the SQL references underlying queries
269271 that are parameterized.
270- @return the set of query parameters for the SQL references
272+ @return map of query parameters for the SQL references
271273 */
272274 public Map <String , String > getQueryParameters ()
273275 {
@@ -305,6 +307,20 @@ public void setContainerFilter(ContainerFilter containerFilter)
305307 _containerFilter = containerFilter ;
306308 }
307309
310+ public boolean getWafEncoding ()
311+ {
312+ return _wafEncoding ;
313+ }
314+
315+ /**
316+ * By default, this command encodes the SQL parameter to allow it to pass through web application firewalls. This
317+ * is compatible with LabKey Server v23.9.0 and above. If targeting an earlier server, pass false to this method.
318+ */
319+ public void setWafEncoding (boolean wafEncoding )
320+ {
321+ _wafEncoding = wafEncoding ;
322+ }
323+
308324 @ Override
309325 protected SelectRowsResponse createResponse (String text , int status , String contentType , JSONObject json )
310326 {
@@ -318,7 +334,7 @@ public JSONObject getJsonObject()
318334 {
319335 JSONObject json = new JSONObject ();
320336 json .put ("schemaName" , getSchemaName ());
321- json .put ("sql" , getSql ());
337+ json .put ("sql" , getWafEncoding () ? EncodeUtils . wafEncode ( getSql ()) : getSql ());
322338 if (getMaxRows () >= 0 )
323339 json .put ("maxRows" , getMaxRows ());
324340 if (getOffset () > 0 )
@@ -337,7 +353,7 @@ protected Map<String, Object> createParameterMap()
337353 {
338354 Map <String , Object > params = super .createParameterMap ();
339355
340- if (null != getSorts () && getSorts ().size () > 0 )
356+ if (null != getSorts () && ! getSorts ().isEmpty () )
341357 params .put ("query.sort" , Sort .getSortQueryStringParam (getSorts ()));
342358
343359 for (Map .Entry <String , String > entry : getQueryParameters ().entrySet ())
0 commit comments