1 /**
  2  * @fileOverview
  3  * @author <a href="https://www.labkey.org">LabKey</a> (<a href="mailto:info@labkey.com">info@labkey.com</a>)
  4  * @license Copyright (c) 2008-2017 LabKey Corporation
  5  * <p/>
  6  * Licensed under the Apache License, Version 2.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at
  9  * <p/>
 10  * http://www.apache.org/licenses/LICENSE-2.0
 11  * <p/>
 12  * Unless required by applicable law or agreed to in writing, software
 13  * distributed under the License is distributed on an "AS IS" BASIS,
 14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing permissions and
 16  * limitations under the License.
 17  * <p/>
 18  */
 19 
 20 /**
 21  * @namespace Query static class to programmatically retrieve, insert, update and
 22  *		delete data from LabKey public queries. <p/>
 23  *		{@link LABKEY.Query.selectRows} works for all LabKey public queries.  However,
 24  *		{@link LABKEY.Query.updateRows}, {@link LABKEY.Query.insertRows} and
 25  *		{@link LABKEY.Query.deleteRows} are not available for all tables and queries.
 26  *            <p>Additional Documentation:
 27  *              <ul>
 28  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=labkeySql">
 29  *                      LabKey SQL Reference</a></li>
 30  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
 31  *                      How To Find schemaName, queryName & viewName</a></li>
 32  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=javascriptTutorial">LabKey JavaScript API Tutorial</a> and
 33  *                      <a href="https://www.labkey.org/home/Study/demo/wiki-page.view?name=reagentRequest">Demo</a></li>
 34  *              </ul>
 35  *           </p>
 36  */
 37 LABKEY.Query = new function()
 38 {
 39     function sendJsonQueryRequest(config)
 40     {
 41         var dataObject = {
 42             schemaName : config.schemaName,
 43             queryName : config.queryName,
 44             rows : config.rows || config.rowDataArray,
 45             transacted : config.transacted,
 46             extraContext : config.extraContext
 47         };
 48 
 49         var requestConfig = {
 50             url : LABKEY.ActionURL.buildURL("query", config.action, config.containerPath),
 51             method : 'POST',
 52             success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
 53             failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
 54             jsonData : dataObject,
 55             headers : {
 56                 'Content-Type' : 'application/json'
 57             }
 58         };
 59 
 60         if (LABKEY.Utils.isDefined(config.timeout))
 61             requestConfig.timeout = config.timeout;
 62 
 63         return LABKEY.Ajax.request(requestConfig);
 64     }
 65 
 66     function getSuccessCallbackWrapper(callbackFn, stripHiddenCols, scope, requiredVersion)
 67     {
 68         if (requiredVersion && (requiredVersion === 13.2 || requiredVersion === "13.2" || requiredVersion === 16.2 || requiredVersion === 17.1)) {
 69             return LABKEY.Utils.getCallbackWrapper(function(data, response, options){
 70                 if (data && callbackFn)
 71                     callbackFn.call(scope || this, new LABKEY.Query.Response(data), response, options);
 72             }, this);
 73         }
 74 
 75         return LABKEY.Utils.getCallbackWrapper(function(data, response, options){
 76             if (data && data.rows && stripHiddenCols)
 77                 stripHiddenColData(data);
 78             if (callbackFn)
 79                 callbackFn.call(scope || this, data, options, response);
 80         }, this);
 81     }
 82 
 83     function stripHiddenColData(data)
 84     {
 85         //gather the set of hidden columns
 86         var hiddenCols = [];
 87         var newColModel = [];
 88         var newMetaFields = [];
 89         var colModel = data.columnModel;
 90         for(var idx = 0; idx < colModel.length; ++idx)
 91         {
 92             if (colModel[idx].hidden)
 93                 hiddenCols.push(colModel[idx].dataIndex);
 94             else
 95             {
 96                 newColModel.push(colModel[idx]);
 97                 newMetaFields.push(data.metaData.fields[idx]);
 98             }
 99         }
100 
101         //reset the columnModel and metaData.fields to include only the non-hidden items
102         data.columnModel = newColModel;
103         data.metaData.fields = newMetaFields;
104 
105         //delete column values for any columns in the hiddenCols array
106         var row;
107         for(idx = 0; idx < data.rows.length; ++idx)
108         {
109             row = data.rows[idx];
110             for(var idxHidden = 0; idxHidden < hiddenCols.length; ++idxHidden)
111             {
112                 delete row[hiddenCols[idxHidden]];
113                 delete row[LABKEY.Query.URL_COLUMN_PREFIX + hiddenCols[idxHidden]];
114             }
115         }
116     }
117 
118     function configFromArgs(args)
119     {
120         return {
121             schemaName: args[0],
122             queryName: args[1],
123             rows: args[2],
124             successCallback: args[3],
125             errorCallback: args[4]
126         };
127     }
128 
129     function getMethod(value)
130     {
131         if (value && (value.toUpperCase() === 'GET' || value.toUpperCase() === 'POST'))
132             return value.toUpperCase();
133         return 'GET';
134     }
135 
136     // public methods:
137     /** @scope LABKEY.Query */
138     return {
139 
140         /**
141          * An enumeration of the various container filters available. Note that not all
142          * data types and queries can contain that spans multiple containers. In those cases,
143          * all values will behave the same as current and show only data in the current container. 
144          * The options are as follows:
145          * <ul>
146          * <li><b>current:</b> Include the current folder only</li>
147          * <li><b>currentAndFirstChildren:</b> Include the current folder and all first children, excluding workbooks</li>
148          * <li><b>currentAndSubfolders:</b> Include the current folder and all subfolders</li>
149          * <li><b>currentPlusProject:</b> Include the current folder and the project that contains it</li>
150          * <li><b>currentAndParents:</b> Include the current folder and its parent folders</li>
151          * <li><b>currentPlusProjectAndShared:</b> Include the current folder plus its project plus any shared folders</li>
152          * <li><b>allFolders:</b> Include all folders for which the user has read permission</li>
153          * </ul>
154          */
155         containerFilter : {
156             current: "Current",
157             currentAndFirstChildren: "CurrentAndFirstChildren",
158             currentAndSubfolders: "CurrentAndSubfolders",
159             currentPlusProject: "CurrentPlusProject",
160             currentAndParents: "CurrentAndParents",
161             currentPlusProjectAndShared: "CurrentPlusProjectAndShared",
162             allFolders: "AllFolders"
163         },
164 
165         /**
166          * Execute arbitrary LabKey SQL. For more information, see the
167          * <a href="https://www.labkey.org/Documentation/wiki-page.view?name=labkeySql">
168          * LabKey SQL Reference</a>.
169          * @param config An object which contains the following configuration properties.
170          * @param {String} config.schemaName name of the schema to query.
171          * @param {String} config.sql The LabKey SQL to execute.
172          * @param {String} [config.containerPath] The path to the container in which the schema and query are defined,
173          *       if different than the current container. If not supplied, the current container's path will be used.
174          * @param {String} [config.containerFilter] One of the values of {@link LABKEY.Query.containerFilter} that sets
175          *       the scope of this query. Defaults to containerFilter.current, and is interpreted relative to
176          *       config.containerPath.
177          * @param {Function} config.success
178                  Function called when the "selectRows" function executes successfully.
179                  This function will be called with the following arguments:
180                  <ul>
181                      <li>
182                          <b>data:</b> If config.requiredVersion is not set, or set to "8.3", the success handler will be
183                          passed a {@link LABKEY.Query.SelectRowsResults} object. If set to "9.1" the success handler will
184                          be passed a {@link LABKEY.Query.ExtendedSelectRowsResults} object. If requiredVersion is greater than 13.2 the success
185                          handler will be passed a {@link LABKEY.Query.Response} object.
186                      </li>
187                      <li><b>responseObj:</b> The XMLHttpResponseObject instance used to make the AJAX request</li>
188                      <li><b>options:</b> The options used for the AJAX request</li>
189                  </ul>
190          * @param {Function} [config.failure] Function called when execution of the "executeSql" function fails.
191          *                   See {@link LABKEY.Query.selectRows} for more information on the parameters passed to this function.
192          * @param {Integer} [config.maxRows] The maximum number of rows to return from the server (defaults to returning all rows).
193          * @param {Integer} [config.offset] The index of the first row to return from the server (defaults to 0).
194          *        Use this along with the maxRows config property to request pages of data.
195          * @param {Boolean} [config.includeTotalCount] Include the total number of rows available (defaults to true).
196          *       If false totalCount will equal number of rows returned (equal to maxRows unless maxRows == 0).
197          * @param {String} [config.sort] A sort specification to apply over the rows returned by the SQL. In general,
198          * you should either include an ORDER BY clause in your SQL, or specific a sort specification in this config property,
199          * but not both. The value of this property should be a comma-delimited list of column names you want to sort by. Use
200          * a - prefix to sort a column in descending order (e.g., 'LastName,-Age' to sort first by LastName, then by Age descending).
201          * @param {Boolean} [config.saveInSession] Whether or not the definition of this query should be stored for reuse during the current session.
202          * 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
203          * success callback.  This temporary query name can be used by all other API methods, including Query Web Part creation, for as long
204          * as the current user's session remains active.
205          * @param {Boolean} [config.includeDetailsColumn] Include the Details link column in the set of columns (defaults to false).
206          *       If included, the column will have the name "~~Details~~". The underlying table/query must support details links
207          *       or the column will be omitted in the response.
208          * @param {Object} [config.parameters] Map of name (string)/value pairs for the values of parameters if the SQL
209          *        references underlying queries that are parameterized. For example, the following passes two parameters to the query: {'Gender': 'M', 'CD4': '400'}.
210          *        The parameters are written to the request URL as follows: query.param.Gender=M&query.param.CD4=400.  For details on parameterized SQL queries, see
211          *        <a href="https://www.labkey.org/Documentation/wiki-page.view?name=paramsql">Parameterized SQL Queries</a>.
212          * @param {Double} [config.requiredVersion] If not set, or set to "8.3", the success handler will be passed a {@link LABKEY.Query.SelectRowsResults}
213          *       object. If set to "9.1" the success handler will be passed a {@link LABKEY.Query.ExtendedSelectRowsResults}
214          *       object. If greater than 13.2 the success handler will be passed a {@link LABKEY.Query.Response} object.
215          *       The main difference between SelectRowsResults and ExtendedSelectRowsResults is that each column in each row
216          *       will be another object (not just a scalar value) with a "value" property as well as other related properties
217          *       (url, mvValue, mvIndicator, etc.). In the LABKEY.Query.Response format each row will be an instance of
218          *       {@link LABKEY.Query.Row}.
219          *       In the "16.2" format, multi-value columns will be returned as an array of values, each of which may have a value, displayValue, and url.
220          *       In the "17.1" format, "formattedValue" may be included in the response as the display column's value formatted with the display column's format or folder format settings.
221          * @param {Integer} [config.timeout] The maximum number of milliseconds to allow for this operation before
222          *       generating a timeout error (defaults to 30000).
223          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
224          * @returns {Mixed} In client-side scripts, this method will return a transaction id
225          * for the async request that can be used to cancel the request
226          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
227          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
228          * @example Example, from the Reagent Request Confirmation <a href="https://www.labkey.org/Documentation/wiki-page.view?name=reagentRequestConfirmation">Tutorial</a> and <a href="https://www.labkey.org/home/Study/demo/wiki-page.view?name=Confirmation">Demo</a>: <pre name="code" class="xml">
229          // This snippet extracts a table of UserID, TotalRequests and
230          // TotalQuantity from the "Reagent Requests" list.
231          // Upon success, the writeTotals function (not included here) uses the
232          // returned data object to display total requests and total quantities.
233 
234              LABKEY.Query.executeSql({
235                      containerPath: 'home/Study/demo/guestaccess',
236                      schemaName: 'lists',
237                      sql: 'SELECT "Reagent Requests".UserID AS UserID, \
238                          Count("Reagent Requests".UserID) AS TotalRequests, \
239                          Sum("Reagent Requests".Quantity) AS TotalQuantity \
240                          FROM "Reagent Requests" Group BY "Reagent Requests".UserID',
241                      success: writeTotals
242              });  </pre>
243 
244          * @see LABKEY.Query.SelectRowsOptions
245          * @see LABKEY.Query.SelectRowsResults
246          * @see LABKEY.Query.ExtendedSelectRowsResults
247          * @see LABKEY.Query.Response
248          */
249         executeSql : function(config)
250         {
251             var dataObject = {
252                 schemaName: config.schemaName,
253                 sql: config.sql
254             };
255 
256             // Work with Ext4.Ajax.request
257             if (config.saveInSession !== undefined && config.saveInSession !== null)
258                 dataObject.saveInSession = config.saveInSession;
259 
260             //set optional parameters
261             if (config.maxRows !== undefined && config.maxRows >= 0)
262                 dataObject.maxRows = config.maxRows;
263             if (config.offset && config.offset > 0)
264                 dataObject.offset = config.offset;
265             if (config.includeTotalCount != undefined)
266                 dataObject.includeTotalCount = config.includeTotalCount;
267 
268             if (config.containerFilter)
269                 dataObject.containerFilter = config.containerFilter;
270 
271             if (config.requiredVersion)
272                 dataObject.apiVersion = config.requiredVersion;
273 
274             if (config.includeStyle)
275                 dataObject.includeStyle = config.includeStyle;
276 
277             var qsParams = {};
278             if (config.sort)
279                 qsParams["query.sort"] = config.sort;
280 
281             if (config.parameters)
282             {
283                 for (var n in config.parameters)
284                 {
285                     if (config.parameters.hasOwnProperty(n))
286                     {
287                         qsParams["query.param." + n] = config.parameters[n];
288                     }
289                 }
290             }
291 
292             var requestConfig = {
293                 url : LABKEY.ActionURL.buildURL("query", "executeSql.api", config.containerPath, qsParams),
294                 method : 'POST',
295                 success: getSuccessCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.stripHiddenColumns, config.scope, config.requiredVersion),
296                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
297                 jsonData : dataObject,
298                 headers : {
299                     'Content-Type' : 'application/json'
300                 }
301             };
302 
303             if (LABKEY.Utils.isDefined(config.timeout))
304                 requestConfig.timeout = config.timeout;
305 
306             return LABKEY.Ajax.request(requestConfig);
307         },
308 
309         /**
310         * Select rows.
311         * @param {Object} config An object which contains the following configuration properties.
312         * @param {String} config.schemaName Name of a schema defined within the current container. See also: <a class="link"
313 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
314 					How To Find schemaName, queryName & viewName</a>.
315         * @param {String} config.queryName Name of a query table associated with the chosen schema. See also: <a class="link"
316 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
317 					How To Find schemaName, queryName & viewName</a>.
318         * @param {Function} config.success
319 				Function called when the "selectRows" function executes successfully.
320 				This function will be called with the following arguments:
321 				<ul>
322 				    <li>
323                         <b>data:</b> If config.requiredVersion is not set, or set to "8.3", the success handler will be
324                         passed a {@link LABKEY.Query.SelectRowsResults} object. If set to "9.1" the success handler will
325                         be passed a {@link LABKEY.Query.ExtendedSelectRowsResults} object. If greater than "13.2" the success
326                         handler will be passed a {@link LABKEY.Query.Response} object.
327                     </li>
328                     <li><b>responseObj:</b> The XMLHttpResponseObject instance used to make the AJAX request</li>
329 				    <li><b>options:</b> The options used for the AJAX request</li>
330 				</ul>
331         * @param {Function} [config.failure] Function called when execution of the "selectRows" function fails.
332         *       This function will be called with the following arguments:
333 				<ul>
334 				    <li><b>errorInfo:</b> an object describing the error with the following fields:
335                         <ul>
336                             <li><b>exception:</b> the exception message</li>
337                             <li><b>exceptionClass:</b> the Java class of the exception thrown on the server</li>
338                             <li><b>stackTrace:</b> the Java stack trace at the point when the exception occurred</li>
339                         </ul>
340                     </li>
341                     <li><b>responseObj:</b> the XMLHttpResponseObject instance used to make the AJAX request</li>
342 				    <li><b>options:</b> the options used for the AJAX request</li>
343 				</ul>
344         * @param {Array} [config.filterArray] Array of objects created by {@link LABKEY.Filter.create}.
345         * @param {Object} [config.parameters] Map of name (string)/value pairs for the values of parameters if the SQL
346         *        references underlying queries that are parameterized. For example, the following passes two parameters to the query: {'Gender': 'M', 'CD4': '400'}.
347         *        The parameters are written to the request URL as follows: query.param.Gender=M&query.param.CD4=400.  For details on parameterized SQL queries, see
348         *        <a href="https://www.labkey.org/Documentation/wiki-page.view?name=paramsql">Parameterized SQL Queries</a>.
349         * @param {String} [config.sort]  String description of the sort.  It includes the column names
350         *       listed in the URL of a sorted data region (with an optional minus prefix to indicate
351         *       descending order). In the case of a multi-column sort, up to three column names can be
352         *       included, separated by commas.
353         * @param {String} [config.viewName] The name of a custom view saved on the server for the specified query.
354         * @param {String} [config.columns] An Array of columns or a comma-delimited list of column names you wish to select from the specified
355         *       query. By default, selectRows will return the set of columns defined in the default value for this query,
356         *       as defined via the Customize View user interface on the server. You can override this by specifying a list
357         *       of column names in this parameter, separated by commas. The names can also include references to related
358         *       tables (e.g., 'RelatedPeptide/Peptide' where 'RelatedPeptide is the name of a foreign key column in the
359         *       base query, and 'Peptide' is the name of a column in the related table).
360         * @param {String} [config.containerPath] The path to the container in which the schema and query are defined,
361         *       if different than the current container. If not supplied, the current container's path will be used.
362          * @param {String} [config.containerFilter] One of the values of {@link LABKEY.Query.containerFilter} that sets
363          *       the scope of this query. Defaults to containerFilter.current, and is interpreted relative to
364          *       config.containerPath.
365         * @param {String} [config.showRows] Either 'paginated' (the default) 'selected', 'unselected', 'all', or 'none'.
366         *        When 'paginated', the maxRows and offset parameters can be used to page through the query's result set rows.
367         *        When 'selected' or 'unselected' the set of rows selected or unselected by the user in the grid view will be returned.
368         *        You can programatically get and set the selection using the {@link LABKEY.DataRegion.setSelected} APIs.
369         *        Setting <code>config.maxRows</code> to -1 is the same as 'all'
370         *        and setting <code>config.maxRows</code> to 0 is the same as 'none'.
371         * @param {Integer} [config.maxRows] The maximum number of rows to return from the server (defaults to 100000).
372         *        If you want to return all possible rows, set this config property to -1.
373         * @param {Integer} [config.offset] The index of the first row to return from the server (defaults to 0).
374         *        Use this along with the maxRows config property to request pages of data.
375         * @param {Boolean} [config.includeTotalCount] Include the total number of rows available (defaults to true).
376         *       If false totalCount will equal number of rows returned (equal to maxRows unless maxRows == 0).
377         * @param {Boolean} [config.includeDetailsColumn] Include the Details link column in the set of columns (defaults to false).
378         *       If included, the column will have the name "~~Details~~". The underlying table/query must support details links
379         *       or the column will be omitted in the response.
380         * @param {Boolean} [config.includeUpdateColumn] Include the Update (or edit) link column in the set of columns (defaults to false).
381         *       If included, the column will have the name "~~Update~~". The underlying table/query must support update links
382         *       or the column will be omitted in the response.
383         * @param {String} [config.selectionKey] Unique string used by selection APIs as a key when storing or retrieving the selected items for a grid.
384         *         Not used unless <code>config.showRows</code> is 'selected' or 'unselected'.
385         * @param {Boolean} [config.ignoreFilter] If true, the command will ignore any filter that may be part of the chosen view.
386         * @param {Integer} [config.timeout] The maximum number of milliseconds to allow for this operation before
387         *       generating a timeout error (defaults to 30000).
388         * @param {Double} [config.requiredVersion] If not set, or set to "8.3", the success handler will be passed a {@link LABKEY.Query.SelectRowsResults}
389         *        object. If set to "9.1" the success handler will be passed a {@link LABKEY.Query.ExtendedSelectRowsResults}
390         *        object. If greater than "13.2" the success handler will be passed a {@link LABKEY.Query.Response} object.
391         *        The main difference between SelectRowsResults and ExtendedSelectRowsResults is that each column in each row
392         *        will be another object (not just a scalar value) with a "value" property as well as other related properties
393         *        (url, mvValue, mvIndicator, etc.). In the LABKEY.Query.Response format each row will an instance of
394         *        {@link LABKEY.Query.Row}.
395          *       In the "16.2" format, multi-value columns will be returned as an array of values, each of which may have a value, displayValue, and url.
396          *       In the "17.1" format, "formattedValue" may be included in the response as the display column's value formatted with the display column's format or folder format settings.
397         * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
398          * @returns {Mixed} In client-side scripts, this method will return a transaction id
399          * for the async request that can be used to cancel the request
400          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
401          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
402         * @example Example: <pre name="code" class="xml">
403 <script type="text/javascript">
404 	function onFailure(errorInfo, options, responseObj)
405 	{
406 	    if (errorInfo && errorInfo.exception)
407 	        alert("Failure: " + errorInfo.exception);
408 	    else
409 	        alert("Failure: " + responseObj.statusText);
410 	}
411 
412 	function onSuccess(data)
413 	{
414 	    alert("Success! " + data.rowCount + " rows returned.");
415 	}
416 
417 	LABKEY.Query.selectRows({
418             schemaName: 'lists',
419             queryName: 'People',
420             columns: ['Name', 'Age'],
421             success: onSuccess,
422             failure: onFailure
423         });
424 </script> </pre>
425 		* @see LABKEY.Query.SelectRowsOptions
426 		* @see LABKEY.Query.SelectRowsResults
427         * @see LABKEY.Query.ExtendedSelectRowsResults
428         * @see LABKEY.Query.Response
429 		*/
430         selectRows : function(config)
431         {
432             //check for old-style separate arguments
433             if (arguments.length > 1)
434             {
435                 config = {
436                     schemaName: arguments[0],
437                     queryName: arguments[1],
438                     success: arguments[2],
439                     errorCallback: arguments[3],
440                     filterArray: arguments[4],
441                     sort: arguments[5],
442                     viewName: arguments[6]
443                 };
444             }
445 
446             if (!config.schemaName)
447                 throw "You must specify a schemaName!";
448             if (!config.queryName)
449                 throw "You must specify a queryName!";
450 
451             config.dataRegionName = config.dataRegionName || "query";
452 
453             var dataObject = LABKEY.Query.buildQueryParams(
454                     config.schemaName,
455                     config.queryName,
456                     config.filterArray,
457                     config.sort,
458                     config.dataRegionName
459             );
460 
461             if (!config.showRows || config.showRows == 'paginated')
462             {
463                 if (config.offset)
464                     dataObject[config.dataRegionName + '.offset'] = config.offset;
465 
466                 if (config.maxRows != undefined)
467                 {
468                     if (config.maxRows < 0)
469                         dataObject[config.dataRegionName + '.showRows'] = "all";
470                     else
471                         dataObject[config.dataRegionName + '.maxRows'] = config.maxRows;
472                 }
473             }
474             else if (config.showRows in {'all':true, 'selected':true, 'unselected':true, 'none':true})
475             {
476                 dataObject[config.dataRegionName + '.showRows'] = config.showRows;
477             }
478 
479 
480             if (config.viewName)
481                 dataObject[config.dataRegionName + '.viewName'] = config.viewName;
482 
483             if (config.columns)
484                 dataObject[config.dataRegionName + '.columns'] = LABKEY.Utils.isArray(config.columns) ? config.columns.join(",") : config.columns;
485 
486             if (config.selectionKey)
487                 dataObject[config.dataRegionName + '.selectionKey'] = config.selectionKey;
488 
489             if (config.ignoreFilter)
490                 dataObject[config.dataRegionName + '.ignoreFilter'] = 1;
491 
492             if (config.parameters)
493             {
494                 for (var propName in config.parameters)
495                 {
496                     if (config.parameters.hasOwnProperty(propName))
497                         dataObject[config.dataRegionName + '.param.' + propName] = config.parameters[propName];
498                 }
499             }
500 
501             if (config.requiredVersion)
502                 dataObject.apiVersion = config.requiredVersion;
503 
504             if (config.containerFilter)
505                 dataObject.containerFilter = config.containerFilter;
506 
507             if (config.includeTotalCount)
508                 dataObject.includeTotalCount = config.includeTotalCount;
509 
510             if (config.includeDetailsColumn)
511                 dataObject.includeDetailsColumn = config.includeDetailsColumn;
512 
513             if (config.includeUpdateColumn)
514                 dataObject.includeUpdateColumn = config.includeUpdateColumn;
515 
516             if (config.includeStyle)
517                 dataObject.includeStyle = config.includeStyle;
518 
519             var requestConfig = {
520                 url : LABKEY.ActionURL.buildURL('query', 'getQuery.api', config.containerPath),
521                 method : getMethod(config.method),
522                 success: getSuccessCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.stripHiddenColumns, config.scope, config.requiredVersion),
523                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
524                 params : dataObject
525             };
526 
527             if (LABKEY.Utils.isDefined(config.timeout))
528                 requestConfig.timeout = config.timeout;
529 
530             return LABKEY.Ajax.request(requestConfig);
531         },
532 
533         /**
534          * Select Distinct Rows
535          * @param {Object} config An object which contains the following configuration properties.
536          * @param {String} config.schemaName Name of a schema defined within the current container. See also: <a class="link"
537                         href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
538                         How To Find schemaName, queryName & viewName</a>.
539          * @param {String} config.queryName Name of a query table associated with the chosen schema.  See also: <a class="link"
540                         href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
541                         How To Find schemaName, queryName & viewName</a>.
542          * @param {String} config.column A single column for which the distinct results will be requested. This column
543          *              must exist within the specified query.
544          * @param {String} [config.containerFilter] One of the values of {@link LABKEY.Query.containerFilter} that sets
545          *       the scope of this query. Defaults to containerFilter.current, and is interpreted relative to
546          *       config.containerPath.
547          * @param {Object} [config.parameters] Map of name (string)/value pairs for the values of parameters if the SQL
548          *        references underlying queries that are parameterized. For example, the following passes two parameters to the query: {'Gender': 'M', 'CD4': '400'}.
549          *        The parameters are written to the request URL as follows: query.param.Gender=M&query.param.CD4=400.  For details on parameterized SQL queries, see
550          *        <a href="https://www.labkey.org/Documentation/wiki-page.view?name=paramsql">Parameterized SQL Queries</a>.
551          * @param {Array} [config.filterArray] Array of objects created by {@link LABKEY.Filter.create}.
552          * @param {String} [config.viewName] Name of a view to use.  This is potentially important if this view contains filters on the data.
553          * @param {Function} config.success
554          * @param {Function} config.failure
555          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
556          */
557         selectDistinctRows : function(config)
558         {
559             if (!config.schemaName)
560                 throw "You must specify a schemaName!";
561             if (!config.queryName)
562                 throw "You must specify a queryName!";
563             if (!config.column)
564                 throw "You must specify a column!";
565 
566             config.dataRegionName = config.dataRegionName || "query";
567 
568             var dataObject = LABKEY.Query.buildQueryParams(
569                     config.schemaName,
570                     config.queryName,
571                     config.filterArray,
572                     config.sort,
573                     config.dataRegionName
574             );
575 
576             dataObject[config.dataRegionName + '.columns'] = config.column;
577 
578             if (config.viewName)
579                 dataObject[config.dataRegionName + '.viewName'] = config.viewName;
580 
581             if (config.maxRows && config.maxRows >= 0)
582                 dataObject.maxRows = config.maxRows;
583 
584             if (config.containerFilter)
585                 dataObject.containerFilter = config.containerFilter;
586 
587             if (config.parameters)
588             {
589                 for (var propName in config.parameters)
590                 {
591                     if (config.parameters.hasOwnProperty(propName))
592                         dataObject[config.dataRegionName + '.param.' + propName] = config.parameters[propName];
593                 }
594             }
595 
596             if (config.ignoreFilter)
597             {
598                 dataObject[config.dataRegionName + '.ignoreFilter'] = true;
599             }
600 
601             return LABKEY.Ajax.request({
602                 url : LABKEY.ActionURL.buildURL('query', 'selectDistinct.api', config.containerPath),
603                 method : getMethod(config.method),
604                 success: getSuccessCallbackWrapper(LABKEY.Utils.getOnSuccess(config), false, config.scope),
605                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
606                 params : dataObject
607             });
608         },
609 
610 
611         /**
612          * Returns a list of reports, views and/or datasets in a container
613          * @param config
614          * @param {String} [config.containerPath] A container path in which to execute this command.  If not provided, the current container will be used
615          * @param {Array} [config.dataTypes] An array of data types to return, which can be any of: 'reports', 'datasets' or 'queries'.  If null, all will be returned
616          * @param {Function} [config.success] A function called on success.  It will be passed a single argument with the following properties:
617          * <ul>
618          * <li>data: An array with one element per dataview.  Each view is a map with the following properties:
619          * <ul>
620          * <li>access:
621          * <li>allowCustomThumbnail: A flag indicating whether the thumbnail can be customized
622          * <li>category: The category to which this item has been assigned
623          * <li>categoryDisplayOrder: The display order within that category
624          * <li>container: The container where this dataView is defined
625          * <li>created: The displayName of the user who created the item
626          * <li>createdByUserId: The user Id of the user who created the item
627          * <li>dataType: The dataType of this item, either queries, reports or datasets
628          * <li>detailsUrl: The url that will display additional details about this item
629          * <li>icon: The url of the icon for this report
630          * <li>id: The unique Id of this item
631          * <li>reportId: The unique report Id if this item is a report. Value is null if this item is not a report.
632          * <li>modified: The date this item was last modified
633          * <li>name: The display name of this item
634          * <li>runUrl: The url that can be used to execute this report
635          * <li>shared: A flag indicating whether this item is shared
636          * <li>thumbnail: The url of this item's thumbnail image
637          * <li>type: The display string for the Data Type.
638          * <li>visible: A flag indicating whether this report is visible or hidden
639          * </ul>
640          * <li>types: a map of each dataType, and a boolean indicating whether it was included in the results (this is based on the dataTypes param in the config)
641          * </ul>
642          * @param {Function} [config.failure] A function called when execution of "getDataViews" fails.
643          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
644          */
645         getDataViews : function(config)
646         {
647             var dataObject = {
648                 includeData: true,
649                 includeMetadata: false
650             };
651             if(config.dataTypes)
652                 dataObject.dataTypes = config.dataTypes;
653 
654             var callbackFn = LABKEY.Utils.getOnSuccess(config);
655             var success = LABKEY.Utils.getCallbackWrapper(function(data, response, options){
656                                             if (callbackFn)
657                                                 callbackFn.call(config.scope || this, data.data, options, response);
658                                         }, this);
659 
660             return LABKEY.Ajax.request({
661                 url : LABKEY.ActionURL.buildURL('reports', 'browseData.api', config.containerPath),
662                 method : 'POST',
663                 success: success,
664                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
665                 jsonData : dataObject,
666                 headers : {
667                     'Content-Type' : 'application/json'
668                 }
669             });
670         },
671 
672         /**
673         * Update rows.
674         * @param {Object} config An object which contains the following configuration properties.
675         * @param {String} config.schemaName Name of a schema defined within the current container. See also: <a class="link"
676 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
677 					How To Find schemaName, queryName & viewName</a>.
678         * @param {String} config.queryName Name of a query table associated with the chosen schema.  See also: <a class="link"
679 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
680 					How To Find schemaName, queryName & viewName</a>.
681         * @param {Array} config.rows Array of record objects in which each object has a property for each field.
682         *               The row array must include the primary key column values and values for
683         *               other columns you wish to update.
684         * @param {Object} [config.extraContext] <b>Experimental:</b> Optional extra context object passed into the transformation/validation script environment.
685         * @param {Function} config.success Function called when the "updateRows" function executes successfully.
686         	    Will be called with arguments:
687                 the parsed response data ({@link LABKEY.Query.ModifyRowsResults}), the XMLHttpRequest object and
688                 (optionally) the "options" object ({@link LABKEY.Query.ModifyRowsOptions}).
689         * @param {Function} [config.failure] Function called when execution of the "updateRows" function fails.
690         *                   See {@link LABKEY.Query.selectRows} for more information on the parameters passed to this function.
691         * @param {String} [config.containerPath] The container path in which the schema and query name are defined.
692         *              If not supplied, the current container path will be used.
693         * @param {Integer} [config.timeout] The maximum number of milliseconds to allow for this operation before
694         *       generating a timeout error (defaults to 30000).
695         * @param {boolean} [config.transacted] Whether all of the updates should be done in a single transaction, so they all succeed or all fail. Defaults to true
696         * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
697          * @returns {Mixed} In client-side scripts, this method will return a transaction id
698          * for the async request that can be used to cancel the request
699          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
700          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
701 		* @see LABKEY.Query.ModifyRowsResults
702 		* @see LABKEY.Query.ModifyRowsOptions
703         */
704         updateRows : function(config)
705         {
706             if (arguments.length > 1)
707                 config = configFromArgs(arguments);
708             config.action = "updateRows.api";
709             return sendJsonQueryRequest(config);
710         },
711 
712         /**
713         * Save inserts, updates, and/or deletes to potentially multiple tables with a single request.
714         * @param {Object} config An object which contains the following configuration properties.
715         * @param {Array} config.commands An array of all of the update/insert/delete operations to be performed.
716         * Each command has the following structure:
717         * @param {String} config.commands[].schemaName Name of a schema defined within the current container. See also: <a class="link"
718 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
719 					How To Find schemaName, queryName & viewName</a>.
720         * @param {String} config.commands[].queryName Name of a query table associated with the chosen schema.  See also: <a class="link"
721 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
722 					How To Find schemaName, queryName & viewName</a>.
723         * @param {String} config.commands[].command Name of the command to be performed. Must be one of "insert", "update", or "delete".
724         * @param {Array} config.commands[].rows An array of data for each row to be changed. See {@link LABKEY.Query.insertRows},
725         * {@link LABKEY.Query.updateRows}, or {@link LABKEY.Query.deleteRows} for requirements of what data must be included for each row.
726         * @param {Object} [config.commands[].extraContext] <b>Experimental:</b> Optional extra context object passed into the transformation/validation script environment.
727         * @param {Object} [config.extraContext] <b>Experimental:</b> Optional extra context object passed into the transformation/validation script environment.
728         * The extraContext at the command-level will be merged with the extraContext at the top-level of the config.
729         * @param {Function} config.success Function called when the "saveRows" function executes successfully.
730         	    Called with arguments:
731                 <ul>
732                     <li>an object with the following properties:
733                     <ul>
734                         <li><strong>result</strong>: an array of parsed response data ({@link LABKEY.Query.ModifyRowsResults}) (one for each command in the request)
735                         <li><strong>errorCount</strong>: an integer, with the total number of errors encountered during the operation
736                         <li><strong>committed</strong>: a boolean, indicating if the changes were actually committed to the database
737                     </ul>
738                     <li>the XMLHttpRequest object</li>
739                     <li>(optionally) the "options" object ({@link LABKEY.Query.ModifyRowsOptions})</li>
740                 </ul>
741         * @param {Function} [config.failure] Function called if execution of the "saveRows" function fails.
742         *                   See {@link LABKEY.Query.selectRows} for more information on the parameters passed to this function.
743         * @param {String} [config.containerPath] The container path in which the changes are to be performed.
744         *              If not supplied, the current container path will be used.
745         * @param {Integer} [config.timeout] The maximum number of milliseconds to allow for this operation before
746         *       generating a timeout error (defaults to 30000).
747         * @param {Double} [config.apiVersion] Version of the API. If this is 13.2 or higher, a request that fails
748         * validation will be returned as a successful response. Use the 'errorCount' and 'committed' properties in the
749         * response to tell if it committed or not. If this is 13.1 or lower (or unspecified), the failure callback
750         * will be invoked instead in the event of a validation failure.
751         * @param {boolean} [config.transacted] Whether all of the row changes for all of the tables
752         * should be done in a single transaction, so they all succeed or all fail. Defaults to true
753         * @param {boolean} [config.validateOnly] Whether or not the server should attempt proceed through all of the
754         * commands, but not actually commit them to the database. Useful for scenarios like giving incremental
755         * validation feedback as a user fills out a UI form, but not actually save anything until they explicitly request
756         * a save.
757         * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
758          * @returns {Mixed} In client-side scripts, this method will return a transaction id
759          * for the async request that can be used to cancel the request
760          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
761          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
762 		* @see LABKEY.Query.ModifyRowsResults
763 		* @see LABKEY.Query.ModifyRowsOptions
764         */
765         saveRows : function(config)
766         {
767             if (arguments.length > 1)
768                 config = configFromArgs(arguments);
769 
770             var dataObject = {
771                 commands: config.commands,
772                 containerPath: config.containerPath,
773                 validateOnly : config.validateOnly,
774                 transacted : config.transacted,
775                 extraContext : config.extraContext,
776                 apiVersion : config.apiVersion
777             };
778 
779             var requestConfig = {
780                 url : LABKEY.ActionURL.buildURL("query", "saveRows.api", config.containerPath),
781                 method : 'POST',
782                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
783                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
784                 jsonData : dataObject,
785                 headers : {
786                     'Content-Type' : 'application/json'
787                 }
788             };
789 
790             if (LABKEY.Utils.isDefined(config.timeout))
791                 requestConfig.timeout = config.timeout;
792 
793             return LABKEY.Ajax.request(requestConfig);
794 
795         },
796 
797         /**
798         * Insert rows.
799         * @param {Object} config An object which contains the following configuration properties.
800         * @param {String} config.schemaName Name of a schema defined within the current container.  See also: <a class="link"
801 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
802 					How To Find schemaName, queryName & viewName</a>.
803         * @param {String} config.queryName Name of a query table associated with the chosen schema. See also: <a class="link"
804 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
805 					How To Find schemaName, queryName & viewName</a>.
806         * @param {Array} config.rows Array of record objects in which each object has a property for each field.
807         *                  The row data array must include all column values except for the primary key column.
808         *                  However, you will need to include the primary key column values if you defined
809         *                  them yourself instead of relying on auto-number.
810         * @param {Object} [config.extraContext] <b>Experimental:</b> Optional extra context object passed into the transformation/validation script environment.
811         * @param {Function} config.success Function called when the "insertRows" function executes successfully.
812 						Will be called with the following arguments:
813                         the parsed response data ({@link LABKEY.Query.ModifyRowsResults}), the XMLHttpRequest object and
814                         (optionally) the "options" object ({@link LABKEY.Query.ModifyRowsOptions}).
815 		* @param {Function} [config.failure]  Function called when execution of the "insertRows" function fails.
816         *                   See {@link LABKEY.Query.selectRows} for more information on the parameters passed to this function.
817         * @param {String} [config.containerPath] The container path in which the schema and query name are defined.
818         *              If not supplied, the current container path will be used.
819         * @param {Integer} [config.timeout] The maximum number of milliseconds to allow for this operation before
820         *       generating a timeout error (defaults to 30000).
821         * @param {boolean} [config.transacted] Whether all of the inserts should be done in a single transaction, so they all succeed or all fail. Defaults to true
822         * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
823          * @returns {Mixed} In client-side scripts, this method will return a transaction id
824          * for the async request that can be used to cancel the request
825          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
826          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
827         * @example Example, from the Reagent Request <a href="https://www.labkey.org/Documentation/wiki-page.view?name=reagentRequestForm">Tutorial</a> and <a href="https://www.labkey.org/home/Study/demo/wiki-page.view?name=reagentRequest">Demo</a>: <pre name="code" class="xml">
828          // This snippet inserts data from the ReagentReqForm into a list.
829          // Upon success, it moves the user to the confirmation page and
830          // passes the current user's ID to that page.
831          LABKEY.Query.insertRows({
832              containerPath: '/home/Study/demo/guestaccess',
833              schemaName: 'lists',
834              queryName: 'Reagent Requests',
835              rows: [{
836                 "Name":  ReagentReqForm.DisplayName.value,
837                 "Email": ReagentReqForm.Email.value,
838                 "UserID": ReagentReqForm.UserID.value,
839                 "Reagent": ReagentReqForm.Reagent.value,
840                 "Quantity": parseInt(ReagentReqForm.Quantity.value),
841                 "Date": new Date(),
842                 "Comments": ReagentReqForm.Comments.value,
843                 "Fulfilled": 'false'
844              }],
845              successCallback: function(data){
846                  window.location =
847                     '/home/Study/demo/wiki-page.view?name=confirmation&userid='
848                     + LABKEY.Security.currentUser.id;
849              },
850          });  </pre>
851 		* @see LABKEY.Query.ModifyRowsResults
852 		* @see LABKEY.Query.ModifyRowsOptions
853         */
854         insertRows : function(config)
855         {
856             if (arguments.length > 1)
857                 config = configFromArgs(arguments);
858             config.action = "insertRows.api";
859             return sendJsonQueryRequest(config);
860         },
861 
862         /**
863         * Delete rows.
864         * @param {Object} config An object which contains the following configuration properties.
865         * @param {String} config.schemaName Name of a schema defined within the current container. See also: <a class="link"
866 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
867 					How To Find schemaName, queryName & viewName</a>.
868         * @param {String} config.queryName Name of a query table associated with the chosen schema. See also: <a class="link"
869 					href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
870 					How To Find schemaName, queryName & viewName</a>.
871         * @param {Object} [config.extraContext] <b>Experimental:</b> Optional extra context object passed into the transformation/validation script environment.
872         * @param {Function} config.success Function called when the "deleteRows" function executes successfully.
873                      Will be called with the following arguments:
874                      the parsed response data ({@link LABKEY.Query.ModifyRowsResults}), the XMLHttpRequest object and
875                      (optionally) the "options" object ({@link LABKEY.Query.ModifyRowsOptions}).
876 		* @param {Function} [config.failure] Function called when execution of the "deleteRows" function fails.
877          *                   See {@link LABKEY.Query.selectRows} for more information on the parameters passed to this function.
878         * @param {Array} config.rows Array of record objects in which each object has a property for each field.
879         *                  The row data array needs to include only the primary key column value, not all columns.
880         * @param {String} [config.containerPath] The container path in which the schema and query name are defined.
881         *              If not supplied, the current container path will be used.
882         * @param {Integer} [config.timeout] The maximum number of milliseconds to allow for this operation before
883         *       generating a timeout error (defaults to 30000).
884         * @param {boolean} [config.transacted] Whether all of the deletes should be done in a single transaction, so they all succeed or all fail. Defaults to true
885         * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
886          * @returns {Mixed} In client-side scripts, this method will return a transaction id
887          * for the async request that can be used to cancel the request
888          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
889          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
890 		* @see LABKEY.Query.ModifyRowsResults
891 		* @see LABKEY.Query.ModifyRowsOptions
892         */
893         deleteRows : function(config)
894         {
895             if (arguments.length > 1)
896             {
897                 config = configFromArgs(arguments);
898             }
899             config.action = "deleteRows.api";
900             return sendJsonQueryRequest(config);
901         },
902 
903         /**
904          * Delete a query view.
905          * @param config An object that contains the following configuration parameters
906          * @param {String} config.schemaName The name of the schema.
907          * @param {String} config.queryName the name of the query.
908          * @param {String} [config.viewName] the name of the view. If a viewName is not specified, the default view will be deleted/reverted.
909          * @param {boolean} [config.revert] Optionally, the view can be reverted instead of deleted. Defaults to false.
910          */
911         deleteQueryView : function(config) {
912             if (!config) {
913                 throw 'You must specify a configuration!'
914             }
915             if (!config.schemaName) {
916                 throw 'You must specify a schemaName!'
917             }
918             if (!config.queryName) {
919                 throw 'You must specify a queryName!'
920             }
921 
922             var params = {
923                 schemaName: config.schemaName,
924                 queryName: config.queryName
925             };
926 
927             if (config.viewName) {
928                 params.viewName = config.viewName;
929             }
930 
931             if (config.revert !== undefined) {
932                 params.complete = config.revert !== true;
933             }
934 
935             return LABKEY.Ajax.request({
936                 url: LABKEY.ActionURL.buildURL('query', 'deleteView.api', config.containerPath),
937                 method: 'POST',
938                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
939                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
940                 jsonData: params
941             });
942         },
943 
944         /**
945          * Build and return an object suitable for passing to the
946          * <a href = "http://www.extjs.com/deploy/dev/docs/?class=Ext.Ajax">Ext.Ajax</a> 'params' configuration property.
947          * @param {string} schemaName Name of a schema defined within the current container.  See also: <a class="link"
948          href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
949          How To Find schemaName, queryName & viewName</a>.
950          * @param {string} queryName Name of a query table associated with the chosen schema.   See also: <a class="link"
951          href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
952          How To Find schemaName, queryName & viewName</a>.
953          * @param {LABKEY.Filter[]} [filterArray] Array of objects created by {@link LABKEY.Filter.create}.
954          * @param {string} [sort]  String description of the sort.  It includes the column names
955          *       listed in the URL of a sorted data region (with an optional minus prefix to indicate
956          *       descending order). In the case of a multi-column sort, up to three column names can be
957          *       included, separated by commas.
958          * @param {string} [dataRegionName=query]
959          * @returns {Object} Object suitable for passing to the
960          * <a href = "http://extjs.com/deploy/ext-2.2.1/docs/?class=Ext.Ajax">Ext.Ajax</a> 'params' configuration property.
961          */
962         buildQueryParams: function(schemaName, queryName, filterArray, sort, dataRegionName)
963         {
964             dataRegionName = dataRegionName || "query";
965             var params = {};
966             params.dataRegionName = dataRegionName;
967             params[dataRegionName + '.queryName'] = queryName;
968             params.schemaName = schemaName;
969             if (sort)
970             {
971                 params[dataRegionName + '.sort'] = sort;
972             }
973 
974             LABKEY.Filter.appendFilterParams(params, filterArray, dataRegionName);
975 
976             return params;
977         },
978 
979         /**
980          * Returns the set of schemas available in the specified container.
981          * @param config An object that contains the following configuration parameters
982          * @param {String} config.schemaName Get schemas under the given schemaName.
983          * @param {String} config.apiVersion Version of the API. Changed the structure of the server's response.
984          * @param {String} config.includeHidden Default true.
985          * @param {function} config.success The function to call when the function finishes successfully.
986          * This function will be called with the following parameters:
987          * <ul>
988          * <li><b>schemasInfo:</b> An object with a property called "schemas". If no apiVersion is specified, or it is
989          * less than 9.3, it will be an array of schema names. If apiVersion is 9.3 or greater, it will be a map where
990          * the keys are schemaNames and the values are objects with the following properties:
991          *     <ul>
992          *         <li><b>schemaName</b>: the short name of the schema</li>
993          *         <li><b>fullyQualifiedName</b>: the fully qualified name of the schema, encoded as a string with
994          *         "." separators as described in {@link LABKEY.SchemaKey}</li>
995          *         <li><b>description</b>: a short description of the schema</li>
996          *         <li><b>schemas</b>: a map of child schemas, with values in the same structure as this object</li>
997          *     </ul>
998          * </li>
999          * </ul>
1000          * @param {function} [config.failure] The function to call if this function encounters an error.
1001          * This function will be called with the following parameters:
1002          * <ul>
1003          * <li><b>errorInfo:</b> An object with a property called "exception," which contains the error message.</li>
1004          * </ul>
1005          * @param {String} [config.containerPath] A container path in which to execute this command. If not supplied,
1006          * the current container will be used.
1007          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
1008          * @returns {Mixed} In client-side scripts, this method will return a transaction id
1009          * for the async request that can be used to cancel the request
1010          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
1011          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
1012          */
1013         getSchemas : function(config)
1014         {
1015             var params = {};
1016             if (config.apiVersion)
1017                 params.apiVersion = config.apiVersion;
1018             if (config.schemaName)
1019                 params.schemaName = config.schemaName;
1020 
1021             if (config.hasOwnProperty("includeHidden"))
1022                 params.includeHidden = config.includeHidden;
1023 
1024             return LABKEY.Ajax.request({
1025                 url : LABKEY.ActionURL.buildURL('query', 'getSchemas.api', config.containerPath),
1026                 method : 'GET',
1027                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
1028                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
1029                 params: params
1030             });
1031         },
1032 
1033         /**
1034          * Returns the set of queries available in a given schema.
1035          * @param config An object that contains the following configuration parameters
1036          * @param {String} config.schemaName The name of the schema.
1037          * @param {function} config.success The function to call when the function finishes successfully.
1038          * This function will be called with the following parameters:
1039          * <ul>
1040          * <li><b>queriesInfo:</b> An object with the following properties
1041          *  <ul>
1042          *      <li><b>schemaName:</b> the name of the requested schema</li>
1043          *      <li><b>queries:</b> an array of objects, each of which has the following properties
1044          *          <ul>
1045          *              <li><b>name:</b> the name of the query</li>
1046          *              <li><b>title:</b> this is the label used when displaying this table. If the table has no title, this will be the same as the name.</li>
1047          *              <li><b>hidden:</b> true if this is a hidden query or table.
1048          *              <li><b>inherit:</b> true if this query is marked as inheritable in sub-folders.
1049          *              <li><b>isUserDefined:</b> true if this is a user-defined query</li>
1050          *              <li><b>canEdit:</b> true if the current user can edit this query</li>
1051          *              <li><b>isMetadataOverrideable:</b> true if the current user may override the query's metadata</li>
1052          *              <li><b>moduleName:</b> the module that defines this query</li>
1053          *              <li><b>isInherited:</b> true if this query is defined in a different container.</li>
1054          *              <li><b>containerPath:</b> if <code>isInherited</code>, the container path where this query is defined.</li>
1055          *              <li><b>description:</b> A description for this query (if provided)</li>
1056          *              <li><b>viewDataUrl:</b> the server-relative URL where this query's data can be viewed.
1057          *                  Available in LabKey Server version 10.2 and later.</li>
1058          *              <li><b>columns:</b> if config.includeColumns is not false, this will contain an array of
1059          *                 objects with the following properties
1060          *                  <ul>
1061          *                      <li><b>name:</b> the name of the column</li>
1062          *                      <li><b>caption:</b> the caption of the column (may be undefined)</li>
1063          *                      <li><b>description:</b> the description of the column (may be undefined)</li>
1064          *                  </ul>
1065          *              </li>
1066          *          </ul>
1067          *      </li>
1068          *  </ul>
1069          * </li>
1070          * </ul>
1071          * @param {function} [config.failure] The function to call if this function encounters an error.
1072          * This function will be called with the following parameters:
1073          * <ul>
1074          * <li><b>errorInfo:</b> An object with a property called "exception," which contains the error message.</li>
1075          * </ul>
1076          * @param {Boolean} [config.includeUserQueries] If set to false, user-defined queries will not be included in
1077          * the results. Default is true.
1078          * @param {Boolean} [config.includeSystemQueries] If set to false, system-defined queries will not be included in
1079          * the results. Default is true.
1080          * @param {Boolean} [config.includeColumns] If set to false, information about the available columns in this
1081          * query will not be included in the results. Default is true.
1082          * @param {String} [config.containerPath] A container path in which to execute this command. If not supplied,
1083          * the current container will be used.
1084          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
1085          * @returns {Mixed} In client-side scripts, this method will return a transaction id
1086          * for the async request that can be used to cancel the request
1087          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
1088          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
1089          */
1090         getQueries : function(config)
1091         {
1092             var params = {};
1093             // Only pass the parameters that the server supports, and exclude ones like successCallback
1094             LABKEY.Utils.applyTranslated(params, config,
1095             {
1096                 schemaName: 'schemaName',
1097                 includeColumns: 'includeColumns',
1098                 includeUserQueries: 'includeUserQueries',
1099                 includeSystemQueries: 'includeSystemQueries'
1100             }, false, false);
1101 
1102             return LABKEY.Ajax.request({
1103                 url: LABKEY.ActionURL.buildURL('query', 'getQueries.api', config.containerPath),
1104                 method : 'GET',
1105                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
1106                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
1107                 params: params
1108             });
1109         },
1110 
1111         /**
1112          * Returns the set of views available for a given query in a given schema.
1113          * @param config An object that contains the following configuration parameters
1114          * @param {String} config.schemaName The name of the schema.
1115          * @param {String} config.queryName the name of the query.
1116          * @param {String} [config.viewName] A view name (empty string for the default view), otherwise return all views for the query.
1117          * @param {Boolean} [config.metadata] Include view column field metadata.
1118          * @param {function} config.success The function to call when the function finishes successfully.
1119          * This function will be called with the following parameters:
1120          * <ul>
1121          * <li><b>viewsInfo:</b> An object with the following properties
1122          *  <ul>
1123          *      <li><b>schemaName:</b> the name of the requested schema</li>
1124          *      <li><b>queryName:</b> the name of the requested query</li>
1125          *      <li><b>views:</b> an array of objects, each of which has the following properties
1126          *          <ul>
1127          *              <li><b>name:</b> the name of the view (default view's name is empty string)</li>
1128          *              <li><b>label:</b> the label of the view</li>
1129          *              <li><b>default:</b> true if this is the default view info</li>
1130          *              <li><b>viewDataUrl:</b> the server-relative URL where this view's data can be viewed.
1131          *                  Available in LabKey Server version 10.2 and later.</li>
1132          *              <li><b>columns:</b> this will contain an array of objects with the following properties
1133          *                  <ul>
1134          *                      <li><b>name:</b> the name of the column</li>
1135          *                      <li><b>fieldKey:</b> the field key for the column (may include join column names, e.g. 'State/Population')</li>
1136          *                  </ul>
1137          *              </li>
1138          *              <li><b>filter:</b> TBD
1139          *                  Available in LabKey Server version 10.3 and later.</li>
1140          *              <li><b>sort:</b> TBD
1141          *                  Available in LabKey Server version 10.3 and later.</li>
1142          *              <li><b>fields:</b> TBD if metadata
1143          *                  Available in LabKey Server version 10.3 and later.</li>
1144          *          </ul>
1145          *      </li>
1146          *  </ul>
1147          * </li>
1148          * </ul>
1149          * @param {function} [config.failure] The function to call if this function encounters an error.
1150          * This function will be called with the following parameters:
1151          * <ul>
1152          * <li><b>errorInfo:</b> An object with a property called "exception," which contains the error message.</li>
1153          * </ul>
1154          * @param {String} [config.containerPath] A container path in which to execute this command. If not supplied,
1155          * the current container will be used.
1156          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
1157          * @returns {Mixed} In client-side scripts, this method will return a transaction id
1158          * for the async request that can be used to cancel the request
1159          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
1160          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
1161          */
1162         getQueryViews : function(config)
1163         {
1164             var params = {};
1165             if (config.schemaName)
1166                 params.schemaName = config.schemaName;
1167             if (config.queryName)
1168                 params.queryName = config.queryName;
1169             if (config.viewName != undefined)
1170                 params.viewName = config.viewName;
1171             if (config.metadata)
1172                 params.metadata = config.metadata;
1173 
1174             return LABKEY.Ajax.request({
1175                 url: LABKEY.ActionURL.buildURL('query', 'getQueryViews.api', config.containerPath),
1176                 method : 'GET',
1177                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
1178                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
1179                 params: params
1180             });
1181         },
1182 
1183         /**
1184          * Creates or updates a custom view or views for a given query in a given schema.  The config
1185          * object matches the viewInfos parameter of the getQueryViews.successCallback.
1186          * @param config An object that contains the following configuration parameters
1187          * @param {String} config.schemaName The name of the schema.
1188          * @param {String} config.queryName The name of the query.
1189          * @param {String} config.views The updated view definitions.
1190          * @param {function} config.success The function to call when the function finishes successfully.
1191          * This function will be called with the same parameters as getQueryViews.successCallback.
1192          * @param {function} [config.failure] The function to call if this function encounters an error.
1193          * This function will be called with the following parameters:
1194          * <ul>
1195          * <li><b>errorInfo:</b> An object with a property called "exception," which contains the error message.</li>
1196          * </ul>
1197          * @param {String} [config.containerPath] A container path in which to execute this command. If not supplied,
1198          * the current container will be used.
1199          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
1200          * @returns {Mixed} In client-side scripts, this method will return a transaction id
1201          * for the async request that can be used to cancel the request
1202          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
1203          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
1204          */
1205         saveQueryViews : function (config)
1206         {
1207             var params = {};
1208             if (config.schemaName)
1209                 params.schemaName = config.schemaName;
1210             if (config.queryName)
1211                 params.queryName = config.queryName;
1212             if (config.views)
1213                 params.views = config.views;
1214 
1215             return LABKEY.Ajax.request({
1216                 url: LABKEY.ActionURL.buildURL('query', 'saveQueryViews.api', config.containerPath),
1217                 method: 'POST',
1218                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
1219                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
1220                 jsonData : params,
1221                 headers : {
1222                     'Content-Type' : 'application/json'
1223                 }
1224             });
1225         },
1226 
1227         /**
1228          * Returns details about a given query including detailed information about result columns
1229          * @param {Object} config An object that contains the following configuration parameters
1230          * @param {String} config.schemaName The name of the schema.
1231          * @param {String} config.queryName The name of the query.
1232          * @param {String} [config.viewName] A view name or Array of view names to include custom view details. Use '*' to include all views for the query.
1233          * @param {String} [config.fields] A field key or Array of field keys to include in the metadata.
1234          * @param {Boolean} [config.initializeMissingView] Initialize the view based on the default view iff the view doesn't yet exist.
1235          * @param {function} config.success The function to call when the function finishes successfully.
1236          * This function will be called with the following parameters:
1237          * <ul>
1238          * <li><b>queryInfo:</b> An object with the following properties
1239          *  <ul>
1240          *      <li><b>schemaName:</b> the name of the requested schema</li>
1241          *      <li><b>name:</b> the name of the requested query</li>
1242          *      <li><b>isUserDefined:</b> true if this is a user-defined query</li>
1243          *      <li><b>canEdit:</b> true if the current user can edit this query</li>
1244          *      <li><b>isMetadataOverrideable:</b> true if the current user may override the query's metadata</li>
1245          *      <li><b>moduleName:</b> the module that defines this query</li>
1246          *      <li><b>isInherited:</b> true if this query is defined in a different container.</li>
1247          *      <li><b>containerPath:</b> if <code>isInherited</code>, the container path where this query is defined.</li>
1248          *      <li><b>viewDataUrl:</b> The URL to navigate to for viewing the data returned from this query</li>
1249          *      <li><b>title:</b> If a value has been set, this is the label used when displaying this table</li>
1250          *      <li><b>description:</b> A description for this query (if provided)</li>
1251          *      <li><b>columns:</b> Information about all columns in this query. This is an array of LABKEY.Query.FieldMetaData objects.</li>
1252          *      <li><b>defaultView:</b> An array of column information for the columns in the current user's default view of this query.
1253          *      The shape of each column info is the same as in the columns array.</li>
1254          *      <li><b>views:</b> An array of view info (XXX: same as views.getQueryViews()
1255          *  </ul>
1256          * </li>
1257          * </ul>
1258          * @see LABKEY.Query.FieldMetaData
1259          * @param {function} [config.failure] The function to call if this function encounters an error.
1260          * This function will be called with the following parameters:
1261          * <ul>
1262          * <li><b>errorInfo:</b> An object with a property called "exception," which contains the error message.</li>
1263          * </ul>
1264          * @param {String} [config.containerPath] A container path in which to execute this command. If not supplied,
1265          * the current container will be used.
1266          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
1267          * @returns {Mixed} In client-side scripts, this method will return a transaction id
1268          * for the async request that can be used to cancel the request
1269          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
1270          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
1271          */
1272         getQueryDetails : function(config)
1273         {
1274             var params = {};
1275             if (config.schemaName)
1276                 params.schemaName = config.schemaName;
1277 
1278             if (config.queryName)
1279                 params.queryName = config.queryName;
1280 
1281             if (config.viewName != undefined)
1282                 params.viewName = config.viewName;
1283 
1284             if (config.fields)
1285                 params.fields = config.fields;
1286 
1287             if (config.fk)
1288                 params.fk = config.fk;
1289 
1290             if (config.initializeMissingView)
1291                 params.initializeMissingView = config.initializeMissingView;
1292 
1293             return LABKEY.Ajax.request({
1294                 url: LABKEY.ActionURL.buildURL('query', 'getQueryDetails.api', config.containerPath),
1295                 method : 'GET',
1296                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
1297                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
1298                 params: params
1299             });
1300         },
1301 
1302         /**
1303          * Validates the specified query by ensuring that it parses and executes without an exception.
1304          * @param config An object that contains the following configuration parameters
1305          * @param {String} config.schemaName The name of the schema.
1306          * @param {String} config.queryName the name of the query.
1307          * @param {Boolean} config.includeAllColumns If set to false, only the columns in the user's default view
1308          * of the specific query will be tested (defaults to true).
1309          * @param {Boolean} config.validateQueryMetadata If true, the query metadata and custom views will also be validated.
1310          * @param {function} config.success The function to call when the function finishes successfully.
1311          * This function will be called with a simple object with one property named "valid" set to true.
1312          * @param {function} [config.failure] The function to call if this function encounters an error.
1313          * This function will be called with the following parameters:
1314          * <ul>
1315          * <li><b>errorInfo:</b> An object with a property called "exception," which contains the error message. If validateQueryMetadata was used, this will also hae a property called 'errors', which is an array of objects describing each error.</li>
1316          * </ul>
1317          * @param {String} [config.containerPath] A container path in which to execute this command. If not supplied,
1318          * the current container will be used.
1319          * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
1320          * @returns {Mixed} In client-side scripts, this method will return a transaction id
1321          * for the async request that can be used to cancel the request
1322          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
1323          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
1324          */
1325         validateQuery : function(config)
1326         {
1327             var params = {};
1328 
1329             LABKEY.Utils.applyTranslated(params, config, {
1330                 successCallback: false,
1331                 errorCallback: false,
1332                 scope: false
1333             });
1334 
1335             return LABKEY.Ajax.request({
1336                 url: LABKEY.ActionURL.buildURL('query', (config.validateQueryMetadata ? 'validateQueryMetadata.api' : 'validateQuery.api'), config.containerPath),
1337                 method : 'GET',
1338                 success: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnSuccess(config), config.scope),
1339                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope, true),
1340                 params: params
1341             });
1342         },
1343 
1344         /**
1345          * Returns the current date/time on the LabKey server.
1346          * @param config An object that contains the following configuration parameters
1347          * @param {function} config.success The function to call when the function finishes successfully.
1348          * This function will be called with a single parameter of type Date.
1349          * @param {function} [config.failure] The function to call if this function encounters an error.
1350          * This function will be called with the following parameters:
1351          * <ul>
1352          * <li><b>errorInfo:</b> An object with a property called "exception," which contains the error message.</li>
1353          * </ul>
1354          * @returns {Mixed} In client-side scripts, this method will return a transaction id
1355          * for the async request that can be used to cancel the request
1356          * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
1357          * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
1358          */
1359         getServerDate : function(config)
1360         {
1361             return LABKEY.Ajax.request({
1362                 url: LABKEY.ActionURL.buildURL('query', 'getServerDate.api'),
1363                 failure: LABKEY.Utils.getCallbackWrapper(LABKEY.Utils.getOnFailure(config), config.scope),
1364                 success: LABKEY.Utils.getCallbackWrapper(function(json){
1365                     var d;
1366                     var onSuccess = LABKEY.Utils.getOnSuccess(config);
1367                     if (json && json.date && onSuccess)
1368                     {
1369                         d = new Date(json.date);
1370                         onSuccess(d);
1371                     }
1372                 }, this)
1373             });
1374         },
1375 
1376 
1377         /**
1378          * Converts a javascript date into a format suitable for using in a LabKey SQL query, includes time but not milliseconds.
1379          * @param {Date} date JavaScript date
1380          * @param {Boolean} withMS include milliseconds
1381          * @returns {String} a date and time literal formatted to be used in a LabKey query
1382          */
1383         sqlDateTimeLiteral : function(date, withMS)
1384         {
1385             if (date === undefined || date === null || !date)
1386                 return "NULL";
1387             if (typeof date == "string")
1388             {
1389                 try { date = new Date(date); } catch (x) { }
1390             }
1391             if (typeof date == "object" && typeof date.toISOString == "function")
1392             {
1393                 var fmt2 = function(a) {return (a>=10 ?  ""+a : "0"+a);};
1394                 var fmt3 = function(a) {return (a>=100 ? ""+a : "0"+fmt2(a));};
1395                 return "{ts '" +
1396                         date.getFullYear() + "-" + fmt2(date.getMonth()+1) + "-" +fmt2(date.getDate()) + " " + fmt2(date.getHours()) + ":" + fmt2(date.getMinutes()) + ":" + fmt2(date.getSeconds()) +
1397                         (withMS ? "." + fmt3(date.getMilliseconds()) : "")
1398                         + "'}";
1399             }
1400             return "{ts '" + this.sqlStringLiteral(date) + "'}";
1401         },
1402 
1403 
1404         /**
1405          * Converts a JavaScript date into a format suitable for using in a LabKey SQL query, does not include time.
1406          * @param {Date} date JavaScript date
1407          * @returns {String} a date literal formatted to be used in a LabKey query
1408          */
1409         sqlDateLiteral : function(date)
1410         {
1411             if (date === undefined || date === null || !date)
1412                 return "NULL";
1413             if (typeof date == "string")
1414             {
1415                 try { date = new Date(date); } catch (x) { }
1416             }
1417             if (typeof date == "object" && typeof date.toISOString == "function")
1418             {
1419                 var fmt2 = function(a) {return (a>=10 ? a : "0"+a);};
1420                 var fmt3 = function(a) {return (a>=999 ? a : "0"+fmt2(a));};
1421                 return "{d '" +
1422                         date.getFullYear() + "-" + fmt2(date.getMonth()+1) + "-" +fmt2(date.getDate())
1423                         + "'}";
1424             }
1425             return "{d '" + this.sqlStringLiteral(date) + "'}";
1426         },
1427 
1428 
1429         /**
1430          * Converts a JavaScript string into a format suitable for using in a LabKey SQL query.
1431          * @param {string} str String to use in query
1432          * @returns {string} value formatted for use in a LabKey query.  Will properly escape single quote characters.
1433          */
1434         sqlStringLiteral : function(str)
1435         {
1436             if (str === undefined || str === null || str == '')
1437                 return "NULL";
1438             str = str.toString();
1439             return "'" + str.replace("'","''") + "'";
1440         },
1441 
1442         URL_COLUMN_PREFIX: "_labkeyurl_"
1443     };
1444 };
1445 
1446 /**
1447  * @class This class is used to construct filters when using APIs such as {@link LABKEY.Query.GetData.getRawData},
1448  *      {@link LABKEY.Query.selectRows}, or {@link LABKEY.Query.executeSql}. This is the base filter class, which requires
1449  *      the user specify a filter type from {@link LABKEY.Filter#Types}. Users can avoid the need for specifying a filter
1450  *      type by using a subclass of Filter such as {@link LABKEY.Query.Filter.Equals} or {@link LABKEY.Query.Filter.GreaterThan}, which
1451  *      will automatically set the type for the user.
1452  * @param {String} columnName Required. The name of the column the filter will be applied  Can be a string, array of strings,
1453  * or a {@link LABKEY.FieldKey}
1454  * @param value Value used as the filter criterion or an Array of values.
1455  * @param {LABKEY.Filter#Types} filterType Type of filter to apply to the 'column' using the 'value'
1456  * @constructor
1457  */
1458 LABKEY.Query.Filter = function (columnName, value, filterType)
1459 {
1460     if (columnName) {
1461         if (columnName instanceof LABKEY.FieldKey) {
1462             columnName = columnName.toString();
1463         }
1464         else if (columnName instanceof Array) {
1465             columnName = columnName.join('/');
1466         }
1467     }
1468 
1469     if (!filterType)
1470     {
1471         filterType = LABKEY.Filter.Types.EQUAL;
1472     }
1473 
1474     /**
1475      * @private
1476      */
1477     this.columnName = columnName;
1478 
1479     /**
1480      * @private
1481      */
1482     this.value = value;
1483 
1484     /**
1485      * @private
1486      */
1487     this.filterType = filterType;
1488 };
1489 
1490 /**
1491  * Gets the column name used in the filter.
1492  * @returns {String}
1493  */
1494 LABKEY.Query.Filter.prototype.getColumnName = function ()
1495 {
1496     return this.columnName
1497 };
1498 
1499 /**
1500  * Gets the filter type used to construct the filter.
1501  * @returns {LABKEY.Filter#Types}
1502  */
1503 LABKEY.Query.Filter.prototype.getFilterType = function ()
1504 {
1505     return this.filterType
1506 };
1507 
1508 /**
1509  * Returns the value of the filter.
1510  * @returns {*}
1511  */
1512 LABKEY.Query.Filter.prototype.getValue = function ()
1513 {
1514     return this.value
1515 };
1516 
1517 /**
1518  * Returns the value that will be put on URL.
1519  * @returns {String}
1520  */
1521 LABKEY.Query.Filter.prototype.getURLParameterValue = function ()
1522 {
1523     return this.filterType.isDataValueRequired() ? this.value : ''
1524 };
1525 
1526 /**
1527  * Returns the URL parameter name used for the filter.
1528  * @param dataRegionName The dataRegionName the filter is associated with.
1529  * @returns {String}
1530  */
1531 LABKEY.Query.Filter.prototype.getURLParameterName = function (dataRegionName)
1532 {
1533     return (dataRegionName || "query") + "." + this.columnName + "~" + this.filterType.getURLSuffix();
1534 };
1535 
1536 LABKEY.Query.Filter.HasAnyValue = function (columnName)
1537 {
1538     LABKEY.Query.Filter.call(this, columnName, null, LABKEY.Filter.Types.HAS_ANY_VALUE);
1539 };
1540 LABKEY.Query.Filter.HasAnyValue.prototype = new LABKEY.Query.Filter;
1541 
1542 /**
1543  * @class LABKEY.Query.Filter.Equal subclass of {@link LABKEY.Query.Filter}.
1544  *      Finds rows where the column value matches the given filter value. Case-sensitivity depends upon how your
1545  *      underlying relational database was configured.
1546  * @augments LABKEY.Query.Filter
1547  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1548  * or a {@link LABKEY.FieldKey}
1549  * @param value Value used as the filter criterion or an Array of values.
1550  * @constructor
1551  */
1552 LABKEY.Query.Filter.Equal = function (columnName, value)
1553 {
1554     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.EQUAL);
1555 };
1556 LABKEY.Query.Filter.Equal.prototype = new LABKEY.Query.Filter;
1557 
1558 /**
1559  * @class LABKEY.Query.Filter.DateEqual subclass of {@link LABKEY.Query.Filter}.
1560  *      Finds rows where the date portion of a datetime column matches the filter value (ignoring the time portion).
1561  * @augments LABKEY.Query.Filter
1562  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1563  * or a {@link LABKEY.FieldKey}
1564  * @param value Value used as the filter criterion or an Array of values.
1565  * @constructor
1566  */
1567 LABKEY.Query.Filter.DateEqual = function (columnName, value)
1568 {
1569     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.DATE_EQUAL);
1570 };
1571 LABKEY.Query.Filter.DateEqual.prototype = new LABKEY.Query.Filter;
1572 
1573 /**
1574  * @class LABKEY.Query.Filter.DateNotEqual subclass of {@link LABKEY.Query.Filter}.
1575  *      Finds rows where the date portion of a datetime column does not match the filter value (ignoring the time portion).
1576  * @augments LABKEY.Query.Filter
1577  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1578  * or a {@link LABKEY.FieldKey}
1579  * @param value Value used as the filter criterion or an Array of values.
1580  * @constructor
1581  */
1582 LABKEY.Query.Filter.DateNotEqual = function (columnName, value)
1583 {
1584     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.DATE_NOT_EQUAL);
1585 };
1586 LABKEY.Query.Filter.DateNotEqual.prototype = new LABKEY.Query.Filter;
1587 
1588 /**
1589  * @class LABKEY.Query.Filter.NotEqualOrNull subclass of {@link LABKEY.Query.Filter}.
1590  *      Finds rows where the column value does not equal the filter value, or is missing (null).
1591  * @augments LABKEY.Query.Filter
1592  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1593  * or a {@link LABKEY.FieldKey}
1594  * @param value Value used as the filter criterion or an Array of values.
1595  * @constructor
1596  */
1597 LABKEY.Query.Filter.NotEqualOrNull = function (columnName, value)
1598 {
1599     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.NEQ_OR_NULL);
1600 };
1601 LABKEY.Query.Filter.NotEqualOrNull.prototype = new LABKEY.Query.Filter;
1602 
1603 /**
1604  * @class LABKEY.Query.Filter.NotEqualOrMissing subclass of {@link LABKEY.Query.Filter}.
1605  *      Finds rows where the column value does not equal the filter value, or is missing (null).
1606  * @augments LABKEY.Query.Filter
1607  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1608  * or a {@link LABKEY.FieldKey}
1609  * @param value Value used as the filter criterion or an Array of values.
1610  * @constructor
1611  */
1612 LABKEY.Query.Filter.NotEqualOrMissing = function (columnName, value)
1613 {
1614     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.NOT_EQUAL_OR_MISSING);
1615 };
1616 LABKEY.Query.Filter.NotEqualOrMissing.prototype = new LABKEY.Query.Filter;
1617 
1618 /**
1619  * @class LABKEY.Query.Filter.NotEqual subclass of {@link LABKEY.Query.Filter}.
1620  *      Finds rows where the column value does not equal the filter value.
1621  * @augments LABKEY.Query.Filter
1622  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1623  * or a {@link LABKEY.FieldKey}
1624  * @param value Value used as the filter criterion or an Array of values.
1625  * @constructor
1626  */
1627 LABKEY.Query.Filter.NotEqual = function (columnName, value)
1628 {
1629     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.NOT_EQUAL);
1630 };
1631 LABKEY.Query.Filter.NotEqual.prototype = new LABKEY.Query.Filter;
1632 
1633 /**
1634  * @class LABKEY.Query.Filter.Neq subclass of {@link LABKEY.Query.Filter}.
1635  *      Finds rows where the column value does not equal the filter value.
1636  * @augments LABKEY.Query.Filter
1637  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1638  * or a {@link LABKEY.FieldKey}
1639  * @param value Value used as the filter criterion or an Array of values.
1640  * @constructor
1641  */
1642 LABKEY.Query.Filter.Neq = function (columnName, value)
1643 {
1644     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.NEQ);
1645 };
1646 LABKEY.Query.Filter.Neq.prototype = new LABKEY.Query.Filter;
1647 
1648 /**
1649  * @class LABKEY.Query.Filter.Neq subclass of {@link LABKEY.Query.Filter}.
1650  *      Finds rows where the column value is blank.
1651  * @augments LABKEY.Query.Filter
1652  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1653  * or a {@link LABKEY.FieldKey}
1654  * @constructor
1655  */
1656 LABKEY.Query.Filter.IsBlank = function (columnName)
1657 {
1658     LABKEY.Query.Filter.call(this, columnName, null, LABKEY.Filter.Types.ISBLANK);
1659 };
1660 LABKEY.Query.Filter.IsBlank.prototype = new LABKEY.Query.Filter;
1661 
1662 /**
1663  * @class LABKEY.Query.Filter.Missing subclass of {@link LABKEY.Query.Filter}.
1664  *      Finds rows where the column value is missing (null). Note that no filter value is required with this operator.
1665  * @augments LABKEY.Query.Filter
1666  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1667  * or a {@link LABKEY.FieldKey}
1668  * @constructor
1669  */
1670 LABKEY.Query.Filter.Missing = function (columnName)
1671 {
1672     LABKEY.Query.Filter.call(this, columnName, null, LABKEY.Filter.Types.MISSING);
1673 };
1674 LABKEY.Query.Filter.Missing.prototype = new LABKEY.Query.Filter;
1675 
1676 /**
1677  * @class LABKEY.Query.Filter.NonBlank subclass of {@link LABKEY.Query.Filter}.
1678  *      Finds rows where the column value is not blank.
1679  * @augments LABKEY.Query.Filter
1680  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1681  * or a {@link LABKEY.FieldKey}
1682  * @constructor
1683  */
1684 LABKEY.Query.Filter.NonBlank = function (columnName)
1685 {
1686     LABKEY.Query.Filter.call(this, columnName, null, LABKEY.Filter.Types.NONBLANK);
1687 };
1688 LABKEY.Query.Filter.NonBlank.prototype = new LABKEY.Query.Filter;
1689 
1690 /**
1691  * @class LABKEY.Query.Filter.NotMissing subclass of {@link LABKEY.Query.Filter}.
1692  *      Finds rows where the column value is not missing.
1693  * @augments LABKEY.Query.Filter
1694  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1695  * or a {@link LABKEY.FieldKey}
1696  * @constructor
1697  */
1698 LABKEY.Query.Filter.NotMissing = function (columnName)
1699 {
1700     LABKEY.Query.Filter.call(this, columnName, null, LABKEY.Filter.Types.NOT_MISSING);
1701 };
1702 LABKEY.Query.Filter.NotMissing.prototype = new LABKEY.Query.Filter;
1703 
1704 /**
1705  * @class LABKEY.Query.Filter.Gt subclass of {@link LABKEY.Query.Filter}.
1706  *      Finds rows where the column value is greater than the filter value.
1707  * @augments LABKEY.Query.Filter
1708  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1709  * or a {@link LABKEY.FieldKey}
1710  * @param value Value used as the filter criterion or an Array of values.
1711  * @constructor
1712  */
1713 LABKEY.Query.Filter.Gt = function (columnName, value)
1714 {
1715     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.GT);
1716 };
1717 LABKEY.Query.Filter.Gt.prototype = new LABKEY.Query.Filter;
1718 
1719 /**
1720  * @class LABKEY.Query.Filter.GreaterThan subclass of {@link LABKEY.Query.Filter}.
1721  *      Finds rows where the column value is greater than the filter value.
1722  * @augments LABKEY.Query.Filter
1723  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1724  * or a {@link LABKEY.FieldKey}
1725  * @param value Value used as the filter criterion or an Array of values.
1726  * @constructor
1727  */
1728 LABKEY.Query.Filter.GreaterThan = function (columnName, value)
1729 {
1730     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.GREATER_THAN);
1731 };
1732 LABKEY.Query.Filter.GreaterThan.prototype = new LABKEY.Query.Filter;
1733 
1734 /**
1735  * @class LABKEY.Query.Filter.Lt subclass of {@link LABKEY.Query.Filter}.
1736  *      Finds rows where the column value is less than the filter value.
1737  * @augments LABKEY.Query.Filter
1738  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1739  * or a {@link LABKEY.FieldKey}
1740  * @param value Value used as the filter criterion or an Array of values.
1741  * @constructor
1742  */
1743 LABKEY.Query.Filter.Lt = function (columnName, value)
1744 {
1745     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.LT);
1746 };
1747 LABKEY.Query.Filter.Lt.prototype = new LABKEY.Query.Filter;
1748 
1749 /**
1750  * @class LABKEY.Query.Filter.LessThan subclass of {@link LABKEY.Query.Filter}.
1751  *      Finds rows where the column value is less than the filter value.
1752  * @augments LABKEY.Query.Filter
1753  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1754  * or a {@link LABKEY.FieldKey}
1755  * @param value Value used as the filter criterion or an Array of values.
1756  * @constructor
1757  */
1758 LABKEY.Query.Filter.LessThan = function (columnName, value)
1759 {
1760     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.LESS_THAN);
1761 };
1762 LABKEY.Query.Filter.LessThan.prototype = new LABKEY.Query.Filter;
1763 
1764 /**
1765  * @class LABKEY.Query.Filter.DateLessThan subclass of {@link LABKEY.Query.Filter}.
1766  *      Finds rows where the date portion of a datetime column is less than the filter value (ignoring the time portion).
1767  * @augments LABKEY.Query.Filter
1768  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1769  * or a {@link LABKEY.FieldKey}
1770  * @param value Value used as the filter criterion or an Array of values.
1771  * @constructor
1772  */
1773 LABKEY.Query.Filter.DateLessThan = function (columnName, value)
1774 {
1775     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.DATE_LESS_THAN);
1776 };
1777 LABKEY.Query.Filter.DateLessThan.prototype = new LABKEY.Query.Filter;
1778 
1779 /**
1780  * @class LABKEY.Query.Filter.Gte subclass of {@link LABKEY.Query.Filter}.
1781  *      Finds rows where the column value is greater than or equal to the filter value.
1782  * @augments LABKEY.Query.Filter
1783  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1784  * or a {@link LABKEY.FieldKey}
1785  * @param value Value used as the filter criterion or an Array of values.
1786  * @constructor
1787  */
1788 LABKEY.Query.Filter.Gte = function (columnName, value)
1789 {
1790     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.GTE);
1791 };
1792 LABKEY.Query.Filter.Gte.prototype = new LABKEY.Query.Filter;
1793 
1794 /**
1795  * @class LABKEY.Query.Filter.GreaterThanOrEqual subclass of {@link LABKEY.Query.Filter}.
1796  *      Finds rows where the column value is greater than or equal to the filter value.
1797  * @augments LABKEY.Query.Filter
1798  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1799  * or a {@link LABKEY.FieldKey}
1800  * @param value Value used as the filter criterion or an Array of values.
1801  * @constructor
1802  */
1803 LABKEY.Query.Filter.GreaterThanOrEqual = function (columnName, value)
1804 {
1805     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.GREATER_THAN_OR_EQUAL);
1806 };
1807 LABKEY.Query.Filter.GreaterThanOrEqual.prototype = new LABKEY.Query.Filter;
1808 
1809 /**
1810  * @class LABKEY.Query.Filter.GreaterThanOrEqual subclass of {@link LABKEY.Query.Filter}.
1811  *      Finds rows where the date portion of a datetime column is greater than or equal to the filter value
1812  *      (ignoring the time portion).
1813  * @augments LABKEY.Query.Filter
1814  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1815  * or a {@link LABKEY.FieldKey}
1816  * @param value Value used as the filter criterion or an Array of values.
1817  * @constructor
1818  */
1819 LABKEY.Query.Filter.DateGreaterThanOrEqual = function (columnName, value)
1820 {
1821     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.DATE_GREATER_THAN_OR_EQUAL);
1822 };
1823 LABKEY.Query.Filter.DateGreaterThanOrEqual.prototype = new LABKEY.Query.Filter;
1824 
1825 /**
1826  * @class LABKEY.Query.Filter.Lte subclass of {@link LABKEY.Query.Filter}.
1827  *      Finds rows where the column value is less than or equal to the filter value.
1828  * @augments LABKEY.Query.Filter
1829  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1830  * or a {@link LABKEY.FieldKey}
1831  * @param value Value used as the filter criterion or an Array of values.
1832  * @constructor
1833  */
1834 LABKEY.Query.Filter.Lte = function (columnName, value)
1835 {
1836     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.LTE);
1837 };
1838 LABKEY.Query.Filter.Lte.prototype = new LABKEY.Query.Filter;
1839 
1840 /**
1841  * @class LABKEY.Query.Filter.LessThanOrEqual subclass of {@link LABKEY.Query.Filter}.
1842  *      Finds rows where the column value is less than or equal to the filter value.
1843  * @augments LABKEY.Query.Filter
1844  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1845  * or a {@link LABKEY.FieldKey}
1846  * @param value Value used as the filter criterion or an Array of values.
1847  * @constructor
1848  */
1849 LABKEY.Query.Filter.LessThanOrEqual = function (columnName, value)
1850 {
1851     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.LESS_THAN_OR_EQUAL);
1852 };
1853 LABKEY.Query.Filter.LessThanOrEqual.prototype = new LABKEY.Query.Filter;
1854 
1855 /**
1856  * @class LABKEY.Query.Filter.DateLessThanOrEqual subclass of {@link LABKEY.Query.Filter}.
1857  *      Finds rows where the date portion of a datetime column is less than or equal to the filter value
1858  *      (ignoring the time portion).
1859  * @augments LABKEY.Query.Filter
1860  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1861  * or a {@link LABKEY.FieldKey}
1862  * @param value Value used as the filter criterion or an Array of values.
1863  * @constructor
1864  */
1865 LABKEY.Query.Filter.DateLessThanOrEqual = function (columnName, value)
1866 {
1867     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.DATE_LESS_THAN_OR_EQUAL);
1868 };
1869 LABKEY.Query.Filter.DateLessThanOrEqual.prototype = new LABKEY.Query.Filter;
1870 
1871 /**
1872  * @class LABKEY.Query.Filter.Contains subclass of {@link LABKEY.Query.Filter}.
1873  *      Finds rows where the column value contains the filter value. Note that this may result in a slow query as this
1874  *      cannot use indexes.
1875  * @augments LABKEY.Query.Filter
1876  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1877  * or a {@link LABKEY.FieldKey}
1878  * @param value Value used as the filter criterion or an Array of values.
1879  * @constructor
1880  */
1881 LABKEY.Query.Filter.Contains = function (columnName, value)
1882 {
1883     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.CONTAINS);
1884 };
1885 LABKEY.Query.Filter.Contains.prototype = new LABKEY.Query.Filter;
1886 
1887 /**
1888  * @class LABKEY.Query.Filter.DoesNotContain subclass of {@link LABKEY.Query.Filter}.
1889  *      Finds rows where the column value does not contain the filter value. Note that this may result in a slow query
1890  *      as this cannot use indexes.
1891  * @augments LABKEY.Query.Filter
1892  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1893  * or a {@link LABKEY.FieldKey}
1894  * @param value Value used as the filter criterion or an Array of values.
1895  * @constructor
1896  */
1897 LABKEY.Query.Filter.DoesNotContain = function (columnName, value)
1898 {
1899     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.DOES_NOT_CONTAIN);
1900 };
1901 LABKEY.Query.Filter.DoesNotContain.prototype = new LABKEY.Query.Filter;
1902 
1903 /**
1904  * @class LABKEY.Query.Filter.StartsWith subclass of {@link LABKEY.Query.Filter}.
1905  *      Finds rows where the column value starts with the filter value.
1906  * @augments LABKEY.Query.Filter
1907  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1908  * or a {@link LABKEY.FieldKey}
1909  * @param value Value used as the filter criterion or an Array of values.
1910  * @constructor
1911  */
1912 LABKEY.Query.Filter.StartsWith = function (columnName, value)
1913 {
1914     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.STARTS_WITH);
1915 };
1916 LABKEY.Query.Filter.StartsWith.prototype = new LABKEY.Query.Filter;
1917 
1918 /**
1919  * @class LABKEY.Query.Filter.In subclass of {@link LABKEY.Query.Filter}.
1920  *      Finds rows where the column value equals one of the supplied filter values. The values should be supplied as a
1921  *      semi-colon-delimited list (example usage: a;b;c).
1922  * @augments LABKEY.Query.Filter
1923  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1924  * or a {@link LABKEY.FieldKey}
1925  * @param value Value used as the filter criterion or an Array of values.
1926  * @constructor
1927  */
1928 LABKEY.Query.Filter.In = function (columnName, value)
1929 {
1930     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.IN);
1931 };
1932 LABKEY.Query.Filter.In.prototype = new LABKEY.Query.Filter;
1933 
1934 /**
1935  * @class LABKEY.Query.Filter.EqualsOneOf subclass of {@link LABKEY.Query.Filter}.
1936  *      Finds rows where the column value equals one of the supplied filter values. The values should be supplied as a
1937  *      semi-colon-delimited list (example usage: a;b;c).
1938  * @augments LABKEY.Query.Filter
1939  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1940  * or a {@link LABKEY.FieldKey}
1941  * @param value Value used as the filter criterion or an Array of values.
1942  * @constructor
1943  */
1944 LABKEY.Query.Filter.EqualsOneOf = function (columnName, value)
1945 {
1946     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.EQUALS_ONE_OF);
1947 };
1948 LABKEY.Query.Filter.EqualsOneOf.prototype = new LABKEY.Query.Filter;
1949 
1950 /**
1951  * @class LABKEY.Query.Filter.EqualsNoneOf subclass of {@link LABKEY.Query.Filter}.
1952  *      Finds rows where the column value does not equal one of the supplied filter values. The values should be supplied as a
1953  *      semi-colon-delimited list (example usage: a;b;c).
1954  * @augments LABKEY.Query.Filter
1955  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1956  * or a {@link LABKEY.FieldKey}
1957  * @param value Value used as the filter criterion or an Array of values.
1958  * @constructor
1959  */
1960 LABKEY.Query.Filter.EqualsNoneOf = function (columnName, value)
1961 {
1962     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.EQUALS_NONE_OF);
1963 };
1964 LABKEY.Query.Filter.EqualsNoneOf.prototype = new LABKEY.Query.Filter;
1965 
1966 /**
1967  * @class LABKEY.Query.Filter.NotIn subclass of {@link LABKEY.Query.Filter}.
1968  *      Finds rows where the column value is not in any of the supplied filter values. The values should be supplied as
1969  *      a semi-colon-delimited list (example usage: a;b;c).
1970  * @augments LABKEY.Query.Filter
1971  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1972  * or a {@link LABKEY.FieldKey}
1973  * @param value Value used as the filter criterion or an Array of values.
1974  * @constructor
1975  */
1976 LABKEY.Query.Filter.NotIn = function (columnName, value)
1977 {
1978     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.NOT_IN);
1979 };
1980 LABKEY.Query.Filter.NotIn.prototype = new LABKEY.Query.Filter;
1981 
1982 /**
1983  * @class LABKEY.Query.Filter.ContainsOneOf subclass of {@link LABKEY.Query.Filter}.
1984  *      Finds rows where the column value contains any of the supplied filter values. The values should be supplied as a
1985  *      semi-colon-delimited list (example usage: a;b;c).
1986  * @augments LABKEY.Query.Filter
1987  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
1988  * or a {@link LABKEY.FieldKey}
1989  * @param value Value used as the filter criterion or an Array of values.
1990  * @constructor
1991  */
1992 LABKEY.Query.Filter.ContainsOneOf = function (columnName, value)
1993 {
1994     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.CONTAINS_ONE_OF);
1995 };
1996 LABKEY.Query.Filter.ContainsOneOf.prototype = new LABKEY.Query.Filter;
1997 
1998 /**
1999  * @class LABKEY.Query.Filter.MemberOf subclass of {@link LABKEY.Query.Filter}.
2000  *      Finds rows where the column value corresponds to a user that is a member of a group with the id of the supplied filter value.
2001  * @augments LABKEY.Query.Filter
2002  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
2003  * or a {@link LABKEY.FieldKey}
2004  * @param value Value used as the filter criterion.
2005  * @constructor
2006  */
2007 LABKEY.Query.Filter.MemberOf = function (columnName, value)
2008 {
2009     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.MEMBER_OF);
2010 };
2011 LABKEY.Query.Filter.ContainsOneOf.prototype = new LABKEY.Query.Filter;
2012 
2013 /**
2014  * @class LABKEY.Query.Filter.ContainsNoneOf subclass of {@link LABKEY.Query.Filter}.
2015  *      Finds rows where the column value does not contain any of the supplied filter values. The values should be supplied
2016  *      as a semi-colon-delimited list (example usage: a;b;c).
2017  * @augments LABKEY.Query.Filter
2018  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
2019  * or a {@link LABKEY.FieldKey}
2020  * @param value Value used as the filter criterion or an Array of values.
2021  * @constructor
2022  */
2023 LABKEY.Query.Filter.ContainsNoneOf = function (columnName, value)
2024 {
2025     LABKEY.Query.Filter.call(this, columnName, value, LABKEY.Filter.Types.CONTAINS_NONE_OF);
2026 };
2027 LABKEY.Query.Filter.ContainsNoneOf.prototype = new LABKEY.Query.Filter;
2028 
2029 /**
2030  * @class LABKEY.Query.Filter.HasMissingValue subclass of {@link LABKEY.Query.Filter}.
2031  *      Finds rows that have a missing value indicator.
2032  * @augments LABKEY.Query.Filter
2033  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
2034  * or a {@link LABKEY.FieldKey}
2035  * @constructor
2036  */
2037 LABKEY.Query.Filter.HasMissingValue = function (columnName)
2038 {
2039     LABKEY.Query.Filter.call(this, columnName, null, LABKEY.Filter.Types.HAS_MISSING_VALUE);
2040 };
2041 LABKEY.Query.Filter.HasMissingValue.prototype = new LABKEY.Query.Filter;
2042 
2043 /**
2044  * @class LABKEY.Query.Filter.DoesNotHaveMissingValue subclass of {@link LABKEY.Query.Filter}.
2045  *      Finds rows that do not have a missing value indicator.
2046  * @augments LABKEY.Query.Filter
2047  * @param columnName Required. The name of the column the filter will be applied to. Can be a string, array of strings,
2048  * or a {@link LABKEY.FieldKey}
2049  * @constructor
2050  */
2051 LABKEY.Query.Filter.DoesNotHaveMissingValue = function (columnName)
2052 {
2053     LABKEY.Query.Filter.call(this, columnName, null, LABKEY.Filter.Types.DOES_NOT_HAVE_MISSING_VALUE);
2054 };
2055 LABKEY.Query.Filter.DoesNotHaveMissingValue.prototype = new LABKEY.Query.Filter;
2056 
2057 (function(){
2058     /**
2059      * @class LABKEY.Query.Row The class used to wrap each row object returned from the server during a GetData, executeSql,
2060      * or selectRows request. Most users will not instantiate these themselves. Instead they will interact with them during
2061      * the success handler of the API they are using.
2062      * @see LABKEY.Query.Response
2063      * @param row The raw row from a GetData or executeSQL, selectRows (version 13.2 and above) request.
2064      * @constructor
2065      */
2066     LABKEY.Query.Row = function(row){
2067         this.links = null;
2068 
2069         if(row.links){
2070             this.links = row.links;
2071         }
2072 
2073         for (var attr in row.data) {
2074             if (row.data.hasOwnProperty(attr)) {
2075                 this[attr] = row.data[attr];
2076             }
2077         }
2078     };
2079 
2080     /**
2081      * Gets the requested column from the row. Includes extended values such as display value, URL, etc.
2082      * When requested version is >16.2, multi-value columns will return an array of objects containing "value" and other properties.
2083      * In the "17.1" format, "formattedValue" may be included in the response as the column display value formatted with the display column's format or folder format settings.
2084      * @param {String} columnName The column name requested. Used to do a case-insensitive match to find the column.
2085      * @returns {Object} For the given columnName, returns an object in the common case or an array of objects for multi-value columns.
2086      * The object will always contain a property named "value" that is the column's value, but it may also contain other properties about that column's value. For
2087      * example, if the column was setup to track missing value information, it will also contain a property named mvValue
2088      * (which is the raw value that is considered suspect), and a property named mvIndicator, which will be the string MV
2089      * indicator (e.g., "Q").
2090      */
2091     LABKEY.Query.Row.prototype.get = function(columnName){
2092         columnName = columnName.toLowerCase();
2093 
2094         for (var attr in this) {
2095             if (attr.toLowerCase() === columnName && this.hasOwnProperty(attr) && !(this[attr] instanceof Function)) {
2096                 return this[attr];
2097             }
2098         }
2099 
2100         return null;
2101     };
2102 
2103     /**
2104      * Gets the simple value for the requested column. Equivalent of doing Row.get(columnName).value.
2105      * For multi-value columns, the result is an array of values.
2106      * @param {String} columnName The column name requested. Used to do a case-insensitive match to find the column.
2107      * @returns {*} Returns the simple value for the given column.
2108      */
2109     LABKEY.Query.Row.prototype.getValue = function(columnName){
2110         columnName = columnName.toLowerCase();
2111 
2112         for (var attr in this) {
2113             if (attr.toLowerCase() === columnName && this.hasOwnProperty(attr) && !(this[attr] instanceof Function)) {
2114                 if (LABKEY.Utils.isArray(this[attr])) {
2115                     return this[attr].map(function (i) { return i.value; });
2116                 }
2117                 if (this[attr].hasOwnProperty('value')) {
2118                     return this[attr].value;
2119                 }
2120             }
2121         }
2122 
2123         return null;
2124     };
2125 
2126     /**
2127      * Gets all of the links for a row (details, update, etc.).
2128      * @returns {Object} Returns an object with all of the links types (details, update, etc.) for a row.
2129      */
2130     LABKEY.Query.Row.prototype.getLinks = function(){
2131         return this.links;
2132     };
2133 
2134     /**
2135      * Gets a specific link type for a row (details, update, etc.).
2136      * @param linkType Required. The name of the link type to be returned.
2137      * @returns {Object} Returns an object with the display text and link value.
2138      */
2139     LABKEY.Query.Row.prototype.getLink = function(linkType){
2140         if (this.links[linkType]) {
2141             return this.links[linkType];
2142         }
2143 
2144         return null;
2145     };
2146 
2147     /**
2148      * @private
2149      */
2150     var generateColumnModel = function(fields) {
2151         var i, columns = [];
2152 
2153         for (i = 0; i < fields.length; i++) {
2154             columns.push({
2155                 scale: fields[i].scale,
2156                 hidden: fields[i].hidden,
2157                 sortable: fields[i].sortable,
2158                 align: fields[i].align,
2159                 width: fields[i].width,
2160                 dataIndex: fields[i].fieldKey.toString(),
2161                 required: fields[i].nullable, // Not sure if this is correct.
2162                 editable: fields[i].userEditable,
2163                 header: fields[i].shortCaption
2164             })
2165         }
2166 
2167         return columns;
2168     };
2169 
2170     /**
2171      * @private
2172      */
2173     var generateGetDisplayField = function(fieldKeyToFind, fields) {
2174         return function() {
2175             var fieldString = fieldKeyToFind.toString();
2176             for (var i = 0; i < fields.length; i++) {
2177                 if (fieldString == fields[i].fieldKey.toString()) {
2178                     return fields[i];
2179                 }
2180             }
2181             return null;
2182         };
2183     };
2184 
2185     /**
2186      * @class The class used to wrap the response object from {@link LABKEY.Query.GetData.getRawData},
2187      *      {@link LABKEY.Query.selectRows}, and {@link LABKEY.Query.executeSql}.
2188      * @param response The raw JSON response object returned from the server when executing {@link LABKEY.Query.GetData.getRawData},
2189      *      {@link LABKEY.Query.selectRows}, or {@link LABKEY.Query.executeSql} when requiredVersion is greater than 13.2.
2190      * @see LABKEY.Query.GetData.getRawData
2191      * @see LABKEY.Query.selectRows
2192      * @see LABKEY.Query.executeSql
2193      * @constructor
2194      */
2195     LABKEY.Query.Response = function(response) {
2196         // response = response;
2197         var i, attr;
2198 
2199         // Shallow copy the response.
2200         for (attr in response) {
2201             if (response.hasOwnProperty(attr)) {
2202                 this[attr] = response[attr];
2203             }
2204         }
2205 
2206         // Wrap the Schema, Lookup, and Field Keys.
2207         this.schemaKey = LABKEY.SchemaKey.fromParts(response.schemaName);
2208 
2209         for (i = 0; i < response.metaData.fields.length; i++) {
2210             var field = response.metaData.fields[i],
2211                 lookup = field.lookup;
2212 
2213             field.fieldKey = LABKEY.FieldKey.fromParts(field.fieldKey);
2214 
2215             if (lookup && lookup.schemaName) {
2216                 lookup.schemaName = LABKEY.SchemaKey.fromParts(lookup.schemaName);
2217             }
2218 
2219             if (field.displayField) {
2220                 field.displayField = LABKEY.FieldKey.fromParts(field.displayField);
2221                 field.getDisplayField = generateGetDisplayField(field.displayField, response.metaData.fields);
2222             }
2223 
2224             // Only parse the 'extFormatFn' if ExtJS is present
2225             // checking to see if the fn ExtJS version and the window ExtJS version match
2226             if (field.extFormatFn) {
2227                 var ext4Index = field.extFormatFn.indexOf('Ext4.'),
2228                     isExt4Fn = ext4Index == 0 || ext4Index == 1,
2229                     canEvalExt3 = !isExt4Fn && window && window.Ext !== undefined,
2230                     canEvalExt4 = isExt4Fn && window && window.Ext4 !== undefined;
2231 
2232                 if (canEvalExt3 || canEvalExt4) {
2233                     field.extFormatFn = eval(field.extFormatFn);
2234                 }
2235             }
2236         }
2237 
2238         // Generate Column Model
2239         this.columnModel = generateColumnModel(this.metaData.fields);
2240 
2241         // Wrap the rows -- may not be in the response (e.g. maxRows: 0)
2242         if (this.rows !== undefined) {
2243             for (i = 0; i < this.rows.length; i++) {
2244                 this.rows[i] = new LABKEY.Query.Row(this.rows[i]);
2245             }
2246         }
2247         else {
2248             this.rows = [];
2249         }
2250 
2251         return this;
2252     };
2253 
2254     /**
2255      * Gets the metaData object from the response.
2256      * @returns {Object} Returns an object with the following properties:
2257      * <ul>
2258      *     <li><strong>fields</strong>: {Object[]}
2259      *     Each field has the following properties:
2260      *          <ul>
2261      *              <li><strong>name</strong>: {String} The name of the field</li>
2262      *              <li><strong>type</strong>: {String} JavaScript type name of the field</li>
2263      *              <li><strong>shownInInsertView</strong>: {Boolean} whether this field is intended to be shown in insert views</li>
2264      *              <li><strong>shownInUpdateView</strong>: {Boolean} whether this field is intended to be shown in update views</li>
2265      *              <li><strong>shownInDetailsView</strong>: {Boolean} whether this field is intended to be shown in details views</li>
2266      *              <li>
2267      *                  <strong>measure</strong>: {Boolean} whether this field is a measure.  Measures are fields that contain data
2268      *                  subject to charting and other analysis.
2269      *              </li>
2270      *              <li>
2271      *                  <strong>dimension</strong>: {Boolean} whether this field is a dimension.  Data dimensions define logical groupings
2272      *                  of measures.
2273      *              </li>
2274      *              <li><strong>hidden</strong>: {Boolean} whether this field is hidden and not normally shown in grid views</li>
2275      *              <li><strong>lookup</strong>: {Object} If the field is a lookup, there will
2276      *                  be four sub-properties listed under this property:
2277      *                  schema, table, displayColumn, and keyColumn, which describe the schema, table, and
2278      *                  display column, and key column of the lookup table (query).
2279      *              </li>
2280      *              <li>
2281      *                  <strong>displayField</strong>: {{@link LABKEY.FieldKey}} If the field has a display field this is
2282      *                  the field key for that field.
2283      *              </li>
2284      *              <li>
2285      *                  <strong>getDisplayField</strong>: {Function} If the field has a display field this function will
2286      *                  return the metadata field object for that field.
2287      *              </li>
2288      *          </ul>
2289      *     </li>
2290      *
2291      *     <li><strong>id</strong>: Name of the primary key column.</li>
2292      *     <li>
2293      *         <strong>root</strong>: Name of the property containing rows ("rows"). This is mainly for the Ext
2294      *         grid component.
2295      *     </li>
2296      *     <li><strong>title</strong>:</li>
2297      *     <li>
2298      *         <strong>totalProperty</strong>: Name of the top-level property containing the row count ("rowCount") in our case.
2299      *         This is mainly for the Ext grid component.
2300      *     </li>
2301      * </ul>
2302      */
2303     LABKEY.Query.Response.prototype.getMetaData = function() {
2304         return this.metaData;
2305     };
2306 
2307     /**
2308      * Returns the schema name from the Response.
2309      * @param {Boolean} asString
2310      * @returns {*} If asString is true it returns a string, otherwise it returns a {@link LABKEY.FieldKey} object.
2311      */
2312     LABKEY.Query.Response.prototype.getSchemaName = function(asString) {
2313         return asString ? this.schemaKey.toString() : this.schemaName;
2314     };
2315 
2316     /**
2317      * Returns the query name from the Response.
2318      * @returns {String}
2319      */
2320     LABKEY.Query.Response.prototype.getQueryName = function() {
2321         return this.queryName;
2322     };
2323 
2324     /**
2325      * Returns an array of objects that can be used to assist in creating grids using ExtJs.
2326      * @returns {Array} Returns an array of Objects that can be used to assist in creating Ext Grids to
2327      *      render the data.
2328      */
2329     LABKEY.Query.Response.prototype.getColumnModel = function() {
2330         return this.columnModel;
2331     };
2332 
2333     /**
2334      * Returns the array of row objects.
2335      * @returns {Array} Returns an array of {@link LABKEY.Query.Row} objects.
2336      */
2337     LABKEY.Query.Response.prototype.getRows = function() {
2338         return this.rows;
2339     };
2340 
2341     /**
2342      * Get a specific row from the row array.
2343      * @param {Integer} idx The index of the row you need.
2344      * @returns {LABKEY.Query.Row}
2345      */
2346     LABKEY.Query.Response.prototype.getRow = function(idx) {
2347         if (this.rows[idx] !== undefined) {
2348             return this.rows[idx];
2349         }
2350 
2351         throw new Error('No row found for index ' + idx);
2352     };
2353 
2354     /**
2355      * Gets the row count from the response, which is the total number of rows in the query, not necessarily the number
2356      * of rows returned. For example, if setting maxRows to 100 on a query that has 5,000 rows, getRowCount will return
2357      * 5,000, not 100.
2358      * @returns {Integer}
2359      */
2360     LABKEY.Query.Response.prototype.getRowCount = function() {
2361         return this.rowCount;
2362     };
2363 })();
2364 
2365 /**
2366 * @name LABKEY.Query.ModifyRowsOptions
2367 * @class   ModifyRowsOptions class to describe
2368             the third object passed to the successCallback function
2369             by {@link LABKEY.Query.updateRows}, {@link LABKEY.Query.insertRows} or
2370             {@link LABKEY.Query.deleteRows}. This object's properties are useful for
2371             matching requests to responses, as HTTP requests are typically
2372             processed asynchronously.
2373  *            <p>Additional Documentation:
2374  *              <ul>
2375  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2376  *                      How To Find schemaName, queryName & viewName</a></li>
2377  *              </ul>
2378  *           </p>
2379   * @see LABKEY.Query.updateRows
2380   * @see LABKEY.Query.insertRows
2381   * @see LABKEY.Query.deleteRows
2382 */
2383 
2384 /**#@+
2385 * @memberOf LABKEY.Query.ModifyRowsOptions#
2386 * @field
2387 */
2388 
2389 /**
2390 * @name headers
2391 * @description  An object containing one property for each HTTP header sent to the server.
2392 * @type Object
2393 */
2394 
2395 /**
2396 * @name method
2397 * @description The HTTP method used for the request (typically 'GET' or 'POST').
2398 * @type String
2399  */
2400 
2401 /**
2402 * @name url
2403 * @description  The URL that was requested.
2404 * @type String
2405 */
2406 
2407 /**
2408 * @name jsonData
2409 * @description  The data object sent to the server. This will contain the following properties:
2410           <ul>
2411             <li><b>schemaName</b>: String. The schema name being modified.  This is the same schemaName
2412                 the client passed to the calling function. </li>
2413             <li><b>queryName</b>: String. The query name being modified. This is the same queryName
2414                 the client passed to the calling function.  </li>
2415             <li><b>rows</b>: Object[]. Array of row objects that map the names of the row fields to their values.
2416             The fields required for inclusion for each row depend on the which LABKEY.Query method you are
2417             using (updateRows, insertRows or deleteRows). </li>
2418          </ul>
2419  <p/>
2420  <b>For {@link LABKEY.Query.updateRows}:</b> <p/>
2421  For the 'updateRows' method, each row in the rows array must include its primary key value
2422  as one of its fields.
2423  <p/>
2424  An example of a ModifyRowsOptions object for the 'updateRows' successCallback:
2425  <pre name="code" class="xml">
2426  {"schemaName": "lists",
2427   "queryName": "API Test List",
2428   "rows": [
2429  {"Key": 1,
2430  "FirstName": "Z",
2431  "Age": "100"}]
2432  } </pre></code>
2433 
2434  <p/>
2435  <b>For {@link LABKEY.Query.insertRows}:</b> <p/>
2436  For the 'insertRows' method, the fields of the rows should look the same as
2437  they do for the 'updateRows' method, except that primary key values for new rows
2438  need not be supplied if the primary key columns are auto-increment.
2439  <p/>
2440  An example of a ModifyRowsOptions object for the 'insertRows' successCallback:
2441  <pre name="code" class="xml">
2442  {"schemaName": "lists",
2443   "queryName": "API Test List",
2444   "rows": [
2445   {"FirstName": "C",
2446  "Age": "30"}]
2447  } </pre></code>
2448 
2449  <p/>
2450  <b>For {@link LABKEY.Query.deleteRows}:</b> <p/>
2451  For the 'deleteRows' method, the fields of the rows should look the
2452  same as they do for the 'updateRows' method, except that the 'deleteRows'
2453  method needs to supply only the primary key values for the rows. All
2454  other row data will be ignored.
2455  <p/>
2456  An example of a ModifyRowsOptions object for the 'deleteRows' successCallback:
2457  <pre name="code" class="xml">
2458  {"schemaName": "lists",
2459   "queryName": "API Test List",
2460   "rows": [
2461 {"Key": 3}]
2462  } </pre></code>
2463 * @type  Object
2464 */
2465 
2466 /**#@-*/
2467 
2468  /**
2469 * @name LABKEY.Query.ModifyRowsResults
2470 * @class  ModifyRowsResults class to describe
2471             the first object passed to the successCallback function
2472             by {@link LABKEY.Query.updateRows}, {@link LABKEY.Query.insertRows} or
2473             {@link LABKEY.Query.deleteRows}. This object's properties are useful for
2474             matching requests to responses, as HTTP requests are typically
2475             processed asynchronously.
2476   *            <p>Additional Documentation:
2477   *              <ul>
2478   *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2479   *                      How To Find schemaName, queryName & viewName</a></li>
2480   *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=javascriptTutorial">LabKey JavaScript API Tutorial</a> and
2481   *                      <a href="https://www.labkey.org/home/Study/demo/wiki-page.view?name=reagentRequest">Demo</a></li>
2482   *              </ul>
2483   *           </p>
2484 * @example For example:
2485         <pre name="code" class="xml">
2486         {  "schemaName": "lists",
2487            "queryName": "API Test List"
2488            "rowsAffected": 1,
2489            "command": "insert",
2490            "errors": [],
2491            "rows": [{ Key: 3, StringField: 'NewValue'}]
2492         } </pre></code>
2493 * @see LABKEY.Query.updateRows
2494 * @see LABKEY.Query.insertRows
2495 * @see LABKEY.Query.deleteRows
2496 * @see LABKEY.Query.saveRows
2497 */
2498 
2499 /**#@+
2500 * @memberOf LABKEY.Query.ModifyRowsResults#
2501 * @field
2502 */
2503 
2504 /**
2505 * @name LABKEY.Query.ModifyRowsResults#schemaName
2506 * @description  Contains the same schemaName the client passed to the calling function.
2507 * @type  String
2508 */
2509 
2510 /**
2511 * @name     LABKEY.Query.ModifyRowsResults#queryName
2512 * @description  Contains the same queryName the client passed to the calling function.
2513 * @type     String
2514 */
2515 
2516 /**
2517 * @name    command
2518 * @description   Will be "update", "insert", or "delete" depending on the API called.
2519 * @type    String
2520 */
2521 
2522 /**
2523 * @name    errors
2524 * @description   Objects will contain the properties 'id' (the field to which the error is related, if any),
2525 *                and 'msg' (the error message itself).
2526 * @type    Array
2527 */
2528 
2529 /**
2530 * @name  rowsAffected
2531 * @description  Indicates the number of rows affected by the API action.
2532             This will typically be the same number of rows passed in to the calling function.
2533 * @type        Integer
2534 */
2535 
2536 /**
2537 * @name LABKEY.Query.ModifyRowsResults#rows
2538 * @description   Array of rows with field values for the rows updated, inserted,
2539             or deleted, in the same order as the rows supplied in the request. For insert, the
2540             new key value for an auto-increment key will be in the returned row's field values.
2541             For insert or update, the other field values may also be different than those supplied
2542             as a result of database default expressions, triggers, or LabKey's automatic tracking
2543             feature, which automatically adjusts columns of certain names (e.g., Created, CreatedBy,
2544             Modified, ModifiedBy, etc.).
2545 * @type    Object[]
2546 */
2547 
2548 /**#@-*/
2549 
2550 /**
2551 * @name LABKEY.Query.SelectRowsOptions
2552 * @class  SelectRowsOptions class to describe
2553            the third object passed to the successCallback function by
2554            {@link LABKEY.Query.selectRows}.  This object's properties are useful for
2555            matching requests to responses, as HTTP requests are typically
2556            processed asynchronously.
2557  *            <p>Additional Documentation:
2558  *              <ul>
2559  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2560  *                      How To Find schemaName, queryName & viewName</a></li>
2561  *              </ul>
2562  *           </p>
2563 * @see LABKEY.Query.selectRows
2564 */
2565 
2566 /**#@+
2567 * @memberOf LABKEY.Query.SelectRowsOptions#
2568 * @field
2569 */
2570 
2571 /**
2572 * @name   query.schemaName
2573 * @description   Contains the same schemaName the client passed to the
2574             calling function. See <a class="link"
2575             href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2576             How To Find schemaName, queryName & viewName</a>.
2577 * @type   String
2578 */
2579 
2580 /**
2581 * @name   query.queryName
2582 * @description   Contains the same queryName the client passed
2583             to the calling function. See
2584             <a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2585             How To Find schemaName, queryName & viewName</a>.
2586 * @type   String
2587 */
2588 
2589 /**
2590 * @name    query.viewName
2591 * @description 	Name of a valid custom view for the chosen queryName. See
2592             <a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2593             How To Find schemaName, queryName & viewName</a>.
2594 * @type    String
2595 */
2596 
2597 /**
2598 * @name    query.offset
2599 * @description  Row number at which results should begin.
2600             Use this with maxRows to get pages of results.
2601 * @type   Integer
2602 */
2603 
2604 /**
2605 * @name   query.sort
2606 * @description	Sort specification. This can be a comma-delimited list of
2607             column names, where each column may have an optional dash (-) before the name
2608             to indicate a descending sort.
2609 * @type  String
2610 */
2611 
2612 /**
2613 * @name   maxRows
2614 * @description   Maximum number of rows to return
2615 * @type     Integer
2616 */
2617 
2618 /**
2619 * @name   filters
2620 * @description   An object whose properties are filter specifications, one for each filter you supplied.
2621  *          All filters are combined using AND logic. Each one is of type {@link LABKEY.Filter.FilterDefinition}.
2622  *          The list of valid operators:
2623             <ul><li><b>eq</b> = equals</li>
2624             <li><b>neq</b> = not equals</li>
2625             <li><b>gt</b> = greater-than</li>
2626             <li><b>gte</b> = greater-than or equal-to</li>
2627             <li><b>lt</b> = less-than</li>
2628             <li><b>lte</b> = less-than or equal-to</li>
2629             <li><b>dateeq</b> = date equal</li>
2630             <li><b>dateneq</b> = date not equal</li>
2631             <li><b>neqornull</b> = not equal or null</li>
2632             <li><b>isblank</b> = is null</li>
2633             <li><b>isnonblank</b> = is not null</li>
2634             <li><b>contains</b> = contains</li>
2635             <li><b>doesnotcontain</b> = does not contain</li>
2636             <li><b>startswith</b> = starts with</li>
2637             <li><b>doesnotstartwith</b> = does not start with</li>
2638             <li><b>in</b> = equals one of</li></ul>
2639 * @type    Object
2640 */
2641 
2642 /**#@-*/
2643 
2644 /**
2645 * @name LABKEY.Query.FieldMetaDataLookup
2646 * @class  Lookup metadata about a single field.
2647  *            <p>Additional Documentation:
2648  *              <ul>
2649  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2650  *                      How To Find schemaName, queryName & viewName</a></li>
2651  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=javascriptTutorial">LabKey JavaScript API Tutorial</a> and
2652  *                      <a href="https://www.labkey.org/home/Study/demo/wiki-page.view?name=reagentRequest">Demo</a></li>
2653  *              </ul>
2654  *           </p>
2655  * @see LABKEY.Query.FieldMetaData
2656 */
2657 
2658 /**#@+
2659 * @memberOf LABKEY.Query.FieldMetaDataLookup#
2660 * @field
2661 * @name    containerPath
2662 * @description The path to the container that this lookup points to, if not the current container
2663 * @type    String
2664 */
2665 
2666 /**#@+
2667 * @memberOf LABKEY.Query.FieldMetaDataLookup#
2668 * @field
2669 * @name    public
2670 * @description Whether the target of this lookup is exposed as a top-level query
2671 * @type    boolean
2672 */
2673 
2674 /**#@+
2675 * @memberOf LABKEY.Query.FieldMetaDataLookup#
2676 * @field
2677 * @name queryName
2678 * @description The name of the query that this lookup targets
2679 * @type    String
2680 */
2681 
2682 /**#@+
2683 * @memberOf LABKEY.Query.FieldMetaDataLookup#
2684 * @field
2685 * @name schemaName
2686 * @description The name of the schema that this lookup targets
2687 * @type    String
2688 */
2689 
2690 /**#@+
2691 * @memberOf LABKEY.Query.FieldMetaDataLookup#
2692 * @field
2693 * @name keyColumn
2694 * @description The name of column in the lookup's target that will be joined to the value in the local field
2695 * @type    String
2696 */
2697 
2698 /**#@+
2699 * @memberOf LABKEY.Query.FieldMetaDataLookup#
2700 * @field
2701 * @name displayColumn
2702 * @description The name of the column in the lookup's target that will be shown as its value, instead of the raw key value
2703 * @type    String
2704 */
2705 
2706 /**#@-*/
2707 
2708 /**
2709 * @name LABKEY.Query.FieldMetaData
2710 * @class  Metadata about a single field.
2711  *            <p>Additional Documentation:
2712  *              <ul>
2713  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2714  *                      How To Find schemaName, queryName & viewName</a></li>
2715  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=javascriptTutorial">LabKey JavaScript API Tutorial</a> and
2716  *                      <a href="https://www.labkey.org/home/Study/demo/wiki-page.view?name=reagentRequest">Demo</a></li>
2717  *              </ul>
2718  *           </p>
2719  * @see LABKEY.Query.selectRows
2720  * @see LABKEY.Query.getQueryDetails
2721 */
2722 
2723 /**#@+
2724 * @memberOf LABKEY.Query.FieldMetaData#
2725 * @field
2726 * @name    name
2727 * @description The name of the field
2728 * @type    String
2729 */
2730 
2731 /**#@+
2732 * @memberOf LABKEY.Query.FieldMetaData#
2733 * @field
2734 * @name    friendlyType
2735 * @description A friendlier, more verbose description of the type, like "Text (String)" or "Date and Time"
2736 * @type    String
2737 */
2738 
2739 /**#@+
2740 * @memberOf LABKEY.Query.FieldMetaData#
2741 * @field
2742 * @name    shownInInsertView
2743 * @description Whether this field is intended to be displayed in insert UIs
2744 * @type    boolean
2745 */
2746 
2747 /**#@+
2748 * @memberOf LABKEY.Query.FieldMetaData#
2749 * @field
2750 * @name    shownInDetailView
2751 * @description Whether this field is intended to be displayed in detail UIs
2752 * @type    boolean
2753 */
2754 
2755 /**#@+
2756 * @memberOf LABKEY.Query.FieldMetaData#
2757 * @field
2758 * @name    shownInUpdateView
2759 * @description Whether this field is intended to be displayed in update UIs
2760 * @type    boolean
2761 */
2762 
2763 /**#@+
2764 * @memberOf LABKEY.Query.FieldMetaData#
2765 * @field
2766 * @name    versionField
2767 * @description Whether this field's value stores version information for the row
2768 * @type    boolean
2769 */
2770 
2771 /**#@+
2772 * @memberOf LABKEY.Query.FieldMetaData#
2773 * @field
2774 * @name userEditable
2775 * @description Whether this field is intended to be edited directly by the user, or managed by the system
2776 * @type    boolean
2777 */
2778 
2779 /**#@+
2780 * @memberOf LABKEY.Query.FieldMetaData#
2781 * @field
2782 * @name calculated
2783 * @description Whether this field is a calculated value such as something generated by a SQL expression,
2784 * or a "real"/"physical" column in the database
2785 * @type    boolean
2786 */
2787 
2788 /**#@+
2789 * @memberOf LABKEY.Query.FieldMetaData#
2790 * @field
2791 * @name readOnly
2792 * @description Whether the field's value can be modified
2793 * @type    boolean
2794 */
2795 
2796 /**#@+
2797 * @memberOf LABKEY.Query.FieldMetaData#
2798 * @field
2799 * @name nullable
2800 * @description Whether the field's value is allowed to be null
2801 * @type    boolean
2802 */
2803 
2804 /**#@+
2805 * @memberOf LABKEY.Query.FieldMetaData#
2806 * @field
2807 * @name mvEnabled
2808 * @description Whether this field supports missing value indicators instead of or addition to its standard value
2809 * @type    boolean
2810 */
2811 
2812 /**#@+
2813 * @memberOf LABKEY.Query.FieldMetaData#
2814 * @field
2815 * @name keyField
2816 * @description Whether this field is part of the row's primary key
2817 * @type    boolean
2818 */
2819 
2820 /**#@+
2821 * @memberOf LABKEY.Query.FieldMetaData#
2822 * @field
2823 * @name hidden
2824 * @description Whether this value is intended to be hidden from the user, especially for grid views
2825 * @type    boolean
2826 */
2827 
2828 /**#@+
2829 * @memberOf LABKEY.Query.FieldMetaData#
2830 * @field
2831 * @name autoIncrement
2832 * @description Whether this field's value is automatically assigned by the server, like a RowId whose value is determined by a database sequence
2833 * @type    boolean
2834 */
2835 
2836 /**#@+
2837 * @memberOf LABKEY.Query.FieldMetaData#
2838 * @field
2839 * @name jsonType
2840 * @description The type of JSON object that will represent this field's value: string, boolean, date, int, or float
2841 * @type    String
2842 */
2843 
2844 /**#@+
2845 * @memberOf LABKEY.Query.FieldMetaData#
2846 * @field
2847 * @name importAliases
2848 * @description Alternate names for this field that may appear in data when importing, whose values should be mapped to this field
2849 * @type    String[]
2850 */
2851 
2852 /**#@+
2853 * @memberOf LABKEY.Query.FieldMetaData#
2854 * @field
2855 * @name tsvFormat
2856 * @description The format string to be used for TSV exports
2857 * @type    String
2858 */
2859 
2860 /**#@+
2861 * @memberOf LABKEY.Query.FieldMetaData#
2862 * @field
2863 * @name format
2864 * @description The format string to be used for generating HTML
2865 * @type    String
2866 */
2867 
2868 /**#@+
2869 * @memberOf LABKEY.Query.FieldMetaData#
2870 * @field
2871 * @name excelFormat
2872 * @description The format string to be used for Excel exports
2873 * @type    String
2874 */
2875 
2876 /**#@+
2877 * @memberOf LABKEY.Query.FieldMetaData#
2878 * @field
2879 * @name extFormat
2880 * @description The format string that can be passed to Ext components.  This is currently only supported for dates.
2881 * @type    String
2882 */
2883 
2884 /**#@+
2885 * @memberOf LABKEY.Query.FieldMetaData#
2886 * @field
2887 * @name extFormatFn
2888 * @description A function that can be used to produce the formatted string for this field.  This is currently supported for dates and numeric values.
2889 * Note: this function is returned as a string, so you will need to evaluate it to convert it to a function.  See example below.
2890 * @example <pre name="code" class="xml">
2891 * var formatFn = eval(meta.extFormatFn);
2892 * var formattedValue = formatFn(data);
2893 * </pre></code>
2894 *
2895 * @type    String
2896 */
2897 
2898 /**#@+
2899 * @memberOf LABKEY.Query.FieldMetaData#
2900 * @field
2901 * @name caption
2902 * @description The caption to be shown for this field, typically in a column header, which may differ from its name
2903 * @type    String
2904 */
2905 
2906 /**#@+
2907 * @memberOf LABKEY.Query.FieldMetaData#
2908 * @field
2909 * @name shortCaption
2910 * @description The caption for this field, without any prefix from potential parent lookups. In many cases this will be identical to the caption property.
2911 * @type    String
2912 */
2913 
2914 /**#@+
2915 * @memberOf LABKEY.Query.FieldMetaData#
2916 * @field
2917 * @name description
2918 * @description The description for this field
2919 * @type    String
2920 */
2921 
2922 /**#@+
2923 * @memberOf LABKEY.Query.FieldMetaData#
2924 * @field
2925 * @name inputType
2926 * @description The type of form input to be used when editing this field, such as select, text, textarea, checkbox, or file
2927 * @type    boolean
2928 */
2929 
2930 /**#@+
2931 * @memberOf LABKEY.Query.FieldMetaData#
2932 * @field
2933 * @name lookup
2934 * @description Information about this field's lookup configuration
2935 * @type    LABKEY.Query.FieldMetaDataLookup
2936 */
2937 
2938 /**#@-*/
2939 
2940 /**
2941 * @name LABKEY.Query.SelectRowsResults
2942 * @class  SelectRowsResults class to describe the first
2943             object passed to the successCallback function by
2944             {@link LABKEY.Query.selectRows}. This object's properties are useful for
2945             matching requests to responses, as HTTP requests are typically
2946             processed asynchronously.
2947  *            <p>Additional Documentation:
2948  *              <ul>
2949  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
2950  *                      How To Find schemaName, queryName & viewName</a></li>
2951  *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=javascriptTutorial">LabKey JavaScript API Tutorial</a> and
2952  *                      <a href="https://www.labkey.org/home/Study/demo/wiki-page.view?name=reagentRequest">Demo</a></li>
2953  *              </ul>
2954  *           </p>
2955 * @see LABKEY.Query.selectRows
2956 */
2957 
2958 /**#@+
2959 * @memberOf LABKEY.Query.SelectRowsResults#
2960 * @field
2961 */
2962 
2963 /**
2964 * @name    schemaName
2965 * @description the name of the resultset's source schema.
2966 * @type    String
2967 */
2968 
2969 /**
2970 * @name    queryName
2971 * @description the name of the resultset's source query.  In some cases, such as an 'executeSql' call with 'saveInSession' set to true, the
2972  * query name may refer to temporary query that can be used to re-retrieve data for the duration of the user's session. 
2973 * @type    String
2974 */
2975 
2976 /**
2977 * @name    metaData
2978 * @description Contains type and lookup information about the columns in the resultset.
2979 * @type    Object
2980 */
2981 
2982 /**
2983 * @name    metaData.root
2984 * @description 	Name of the property containing rows ("rows"). This is mainly for the Ext grid component.
2985 * @type     String
2986 */
2987 
2988 /**
2989 * @name    metaData.totalProperty
2990 * @description 	Name of the top-level property
2991             containing the row count ("rowCount") in our case. This is mainly
2992             for the Ext grid component.
2993 * @type   String
2994 */
2995 
2996 /**
2997 * @name   metaData.sortInfo
2998 * @description  Sort specification in Ext grid terms.
2999             This contains two sub-properties, field and direction, which indicate
3000             the sort field and direction ("ASC" or "DESC") respectively.
3001 * @type   Object
3002 */
3003 
3004 /**
3005 * @name    metaData.id
3006 * @description  Name of the primary key column.
3007 * @type     String
3008 */
3009 
3010 /**
3011 * @name    metaData.fields
3012 * @description	Array of field information.
3013 * @type    LABKEY.Query.FieldMetaData[]
3014 */
3015 
3016 /**
3017 * @name    columnModel
3018 * @description   Contains information about how one may interact
3019             with the columns within a user interface. This format is generated
3020             to match the requirements of the Ext grid component. See
3021             <a href="http://extjs.com/deploy/ext-2.2.1/docs/?class=Ext.grid.ColumnModel">
3022             Ext.grid.ColumnModel</a> for further information.
3023 * @type  Object[]
3024 */
3025 
3026 /**
3027 * @name   rows
3028 * @description    An array of rows, each of which is a
3029             sub-element/object containing a property per column.
3030 * @type   Object[]
3031 */
3032 
3033 /**
3034 * @name rowCount
3035 * @description Indicates the number of total rows that could be
3036             returned by the query, which may be more than the number of objects
3037             in the rows array if the client supplied a value for the query.maxRows
3038             or query.offset parameters. This value is useful for clients that wish
3039             to display paging UI, such as the Ext grid.
3040 * @type   Integer
3041 */
3042 
3043 /**#@-*/
3044 
3045  /**
3046 * @name LABKEY.Query.ExtendedSelectRowsResults
3047 * @class  ExtendedSelectRowsResults class to describe the first
3048             object passed to the successCallback function by
3049             {@link LABKEY.Query.selectRows} if config.requiredVersion is set to "9.1".
3050   *            <p>Additional Documentation:
3051   *              <ul>
3052   *                  <li><a href="https://www.labkey.org/Documentation/wiki-page.view?name=findNames">
3053   *                      How To Find schemaName, queryName & viewName</a></li>
3054   *              </ul>
3055   *           </p>
3056 * @see LABKEY.Query.selectRows
3057  */
3058 
3059 /**#@+
3060 * @memberOf LABKEY.Query.ExtendedSelectRowsResults#
3061 * @field
3062 */
3063 
3064 /**
3065 * @name    LABKEY.Query.ExtendedSelectRowsResults#metaData
3066 * @description Contains type and lookup information about the columns in the resultset.
3067 * @type    Object
3068 */
3069 
3070 /**
3071 * @name    LABKEY.Query.ExtendedSelectRowsResults#metaData.root
3072 * @description 	Name of the property containing rows ("rows"). This is mainly for the Ext grid component.
3073 * @type     String
3074 */
3075 
3076 /**
3077 * @name    LABKEY.Query.ExtendedSelectRowsResults#metaData.totalProperty
3078 * @description 	Name of the top-level property
3079             containing the row count ("rowCount") in our case. This is mainly
3080             for the Ext grid component.
3081 * @type   String
3082 */
3083 
3084 /**
3085 * @name   LABKEY.Query.ExtendedSelectRowsResults#metaData.sortInfo
3086 * @description  Sort specification in Ext grid terms.
3087             This contains two sub-properties, field and direction, which indicate
3088             the sort field and direction ("ASC" or "DESC") respectively.
3089 * @type   Object
3090 */
3091 
3092 /**
3093 * @name    LABKEY.Query.ExtendedSelectRowsResults#metaData.id
3094 * @description  Name of the primary key column.
3095 * @type     String
3096 */
3097 
3098 /**
3099 * @name    LABKEY.Query.ExtendedSelectRowsResults#metaData.fields
3100 * @description	Array of field information.
3101             Each field has the following properties:
3102             <ul><li><b>name</b> -- The name of the field</li>
3103             <li><b>type</b> -- JavaScript type name of the field</li>
3104             <li><b>shownInInsertView</b> -- whether this field is intended to be shown in insert views</li>
3105             <li><b>shownInUpdateView</b> -- whether this field is intended to be shown in update views</li>
3106             <li><b>shownInDetailsView</b> -- whether this field is intended to be shown in details views</li>
3107             <li><b>measure</b> -- whether this field is a measure.  Measures are fields that contain data subject to charting and other analysis.</li>
3108             <li><b>dimension</b> -- whether this field is a dimension.  Data dimensions define logical groupings of measures.</li>
3109             <li><b>hidden</b> -- whether this field is hidden and not normally shown in grid views</li>
3110             <li><b>lookup</b> -- If the field is a lookup, there will
3111                 be four sub-properties listed under this property:
3112                 schema, table, displayColumn, and keyColumn, which describe the schema, table, and
3113                 display column, and key column of the lookup table (query).</li></ul>
3114 * @type    Object[]
3115 */
3116 
3117 /**
3118 * @name    LABKEY.Query.ExtendedSelectRowsResults#columnModel
3119 * @description   Contains information about how one may interact
3120             with the columns within a user interface. This format is generated
3121             to match the requirements of the Ext grid component. See
3122             <a href="http://extjs.com/deploy/ext-2.2.1/docs/?class=Ext.grid.ColumnModel">
3123             Ext.grid.ColumnModel</a> for further information.
3124 * @type  String
3125 */
3126 
3127 /**
3128 * @name   LABKEY.Query.ExtendedSelectRowsResults#rows
3129 * @description    An array of rows, each of which is a
3130             sub-element/object containing an object per column. The
3131             object will always contain a property named "value" that is the
3132             column's value, but it may also contain other properties about
3133             that column's value. For example, if the column was setup to track
3134             missing value information, it will also contain a property named mvValue (which
3135             is the raw value that is considered suspect), and a property named
3136             mvIndicator, which will be the string MV indicator (e.g., "Q").
3137 * @type   Object[]
3138 */
3139 
3140 /**
3141 * @name LABKEY.Query.ExtendedSelectRowsResults#rowCount
3142 * @description Indicates the number of total rows that could be
3143             returned by the query, which may be more than the number of objects
3144             in the rows array if the client supplied a value for the query.maxRows
3145             or query.offset parameters. This value is useful for clients who wish
3146             to display paging UI, such as the Ext grid.
3147 * @type   Integer
3148 */
3149 
3150 /**#@-*/
3151 
3152 /** docs for methods defined in dom/Query.js - primarily here to ensure API docs get generated with combined core/dom versions */
3153 
3154 /**
3155  * Execute arbitrary LabKey SQL and export the results to Excel or TSV. After this method is
3156  * called, the user will be prompted to accept a file from the server, and most browsers will allow
3157  * the user to either save it or open it in an appropriate application.
3158  * For more information, see the
3159  * <a href="https://www.labkey.org/Documentation/wiki-page.view?name=labkeySql">
3160  * LabKey SQL Reference</a>.
3161  *
3162  * @memberOf LABKEY.Query
3163  * @function
3164  * @static
3165  * @name exportSql
3166  * @param config An object which contains the following configuration properties.
3167  * @param {String} config.schemaName name of the schema to query.
3168  * @param {String} config.sql The LabKey SQL to execute.
3169  * @param {String} [config.format] The desired export format. May be either 'excel' or 'tsv'. Defaults to 'excel'.
3170  * @param {String} [config.containerPath] The path to the container in which the schema and query are defined,
3171  *       if different than the current container. If not supplied, the current container's path will be used.
3172  * @param {String} [config.containerFilter] One of the values of {@link LABKEY.Query.containerFilter} that sets
3173  *       the scope of this query. Defaults to containerFilter.current, and is interpreted relative to
3174  *       config.containerPath.
3175  */
3176 
3177 /**
3178  * Load the set of user visible schemas from the given container into a standard <select> input element.
3179  *
3180  * @memberOf LABKEY.Query
3181  * @function
3182  * @static
3183  * @name schemaSelectInput
3184  * @param config An object which contains the following configuration properties.
3185  * @param {String} config.renderTo the id of the <select> input to load the LabKey queries into.
3186  * @param {String} config.initValue the initial value to try and set the <select> element value after it loads.
3187  */
3188 
3189 /**
3190  * Load the set of queries from this container for a given schema into a standard <select> input. The config object
3191  * must define which <select> input is for the schemas and which <select> input is for the queries. This function
3192  * also then associates the two <select> inputs so that a selection change in the schema input will update the
3193  * query input accordingly.
3194  *
3195  * @memberOf LABKEY.Query
3196  * @function
3197  * @static
3198  * @name querySelectInput
3199  * @param config An object which contains the following configuration properties.
3200  * @param {String} config.renderTo the id of the <select> input to load the LabKey queries into.
3201  * @param {String} config.schemaInputId the id of the <select> input to load the LabKey schemas into.
3202  * @param {String} config.initValue the initial value to try and set the <select> element value after it loads.
3203  */
3204 
3205 /**
3206  * Load the set of columns for a given schema/query into a standard <select> input. The config object
3207  * must define the schemaName and queryName to be used to source the column listing.
3208  *
3209  * @memberOf LABKEY.Query
3210  * @function
3211  * @static
3212  * @name columnSelectInput
3213  * @param config An object which contains the following configuration properties.
3214  * @param {String} config.renderTo the id of the <select> input to load the LabKey queries into. Required.
3215  * @param {String} config.schemaName the name of the schema. Required.
3216  * @param {String} config.queryName the name of the query. Required.
3217  * @param {String} config.initValue the initial value to try and set the <select> element value after it loads. Optional.
3218  * @param {String} config.filterFn a function to call to filter the column set (ex. by data type). Optional.
3219  */
3220 
3221 /**
3222  * Bulk import data rows into a table.
3223  * One of 'text', 'path', 'moduleResource', or 'file' is required and cannot be combined.
3224  *
3225  * @memberOf LABKEY.Query
3226  * @function
3227  * @static
3228  * @name importData
3229  * @param {Object} config An object which contains the following configuration properties.
3230  * @param {String} config.schemaName Name of a schema defined within the current container.
3231  * @param {String} config.queryName Name of a query table associated with the chosen schema.
3232  * @param {File} [config.file] A <a href='https://developer.mozilla.org/en-US/docs/DOM/File'><code>File</code></a> object or a file input element to upload to the server.
3233  * @param {String} [config.text] Text to import.
3234  * @param {String} [config.path] Path to resource under webdav tree. E.g. "/_webdav/MyProject/@files/data.tsv"
3235  * @param {String} [config.module] Module name to use when resolving a module resource.
3236  * @param {String} [config.moduleResource] A file resource within the module to import.
3237  * @param {String} [config.importIdentity] When true, auto-increment key columns may be imported from the data.
3238  * @param {String} [config.importLookupByAlternateKey] When true, lookup columns can be imported by their alternate keys instead of the primary key.
3239  *          For example, if a column is a lookup to a SampleSet, the imported value can be the Sample's name since names must be unique within a SampleSet.
3240  * @param {Function} [config.success] Function called when the "importData" function executes successfully.
3241  Will be called with the following arguments:
3242  An object containing success and rowCount properties.
3243  * @param {Function} [config.failure]  Function called importing data fails.
3244  * @param {String} [config.containerPath] The container path in which the schema and query name are defined.
3245  * @param {Integer} [config.timeout] The maximum number of milliseconds to allow for this operation before
3246  *       generating a timeout error (defaults to 30000).
3247  * @param {Object} [config.scope] A scope for the callback functions. Defaults to "this"
3248  * @returns {Mixed} In client-side scripts, this method will return a transaction id
3249  * for the async request that can be used to cancel the request
3250  * (see <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Connection&member=abort" target="_blank">Ext.data.Connection.abort</a>).
3251  * In server-side scripts, this method will return the JSON response object (first parameter of the success or failure callbacks.)
3252  * @example Example, importing tsv data from a module: <pre name="code" class="javascript">
3253  LABKEY.Query.importData({
3254              schemaName: 'lists',
3255              queryName: 'People',
3256              // reference to <input type='file' id='file'>
3257              file: document.getElementById('file')
3258          },
3259  });</pre>
3260  * @example Example, importing tsv data from a module: <pre name="code" class="javascript">
3261  LABKEY.Query.importData({
3262              schemaName: 'lists',
3263              queryName: 'People',
3264              module: 'mymodule',
3265              moduleResource: '/data/lists/People.tsv'
3266          },
3267  });</pre>
3268  */
3269