change display name on a query

LabKey Support Forum (Inactive)
change display name on a query Ben Bimber  2010-03-30 17:33
Status: Closed
 
is there an xml property to change the display name on a query? i have a ton of these stored in a file based module and i've named them things like demographicsAge.sql for the Age query based on the demographics dataset. It makes sense for file organization, but users would probably prefer to see if called 'Age'.

I looked through tableinfo.xsd, but the obvious properties like tableTitle did not seem to work. is there something i'm missing? thanks.
 
 
daves responded:  2010-03-31 10:18
You can give the query a different display name using a meta-data XML file that has the same base-name as your .sql file, but with a .query.xml extension. So for your particular example, create a file named demographicsAge.query.xml, and set the contents to this:

<query name="Age">
</query>

The <query> element may also contain a <description> sub-element and/or a <metadata> sub-element (which would contain the table info schema). See the query.xsd in the /schemas directory of the source for a complete schema definition.
 
Ben Bimber responded:  2010-03-31 11:19
thanks dave. that all makes sense, but 'name' does not actually seem to change anything. see example below. the other metadata that i alter is working (like URLs), just not the name.

Name of query file:
assignmentTotalCoAssigned.sql

Name of XML file:
assignmentTotalCoAssigned.query.xml

Contents of XML:
<query xmlns="http://labkey.org/data/xml/query" name="TotalCoAssigned">
    <metadata>
        <tables xmlns="http://labkey.org/data/xml">
<!-- Changing tableName below also does not seem to do anything !-->
            <table tableName="assignmentTotalCoAssigned" tableDbType="NOT_IN_DB">
                <columns>
                    <column columnName="objectId">
                        <isKeyField>true</isKeyField>
                    </column>
                    <column columnName="OverlappingAssignments">
                        <url>/query/executeQuery.view?schemaName=study&amp;
                            query.queryName=assignmentCoAssignedAnimals&amp;
                            query.pno~eq=${pno}&amp;
                            query.objectid~eq=${ObjectId}
                        </url>
                    </column>
                    <column columnName="ConcurrentAssignments">
                        <url>/query/executeQuery.view?schemaName=study&amp;
                            query.queryName=Assignments&amp;
                            query.Id~eq=${Id}&amp;
                            query.sort=-Date
                        </url>
                    </column>
                </columns>
                <titleColumn>OverlappingAssignments</titleColumn>
            </table>
        </tables>
    </metadata>
</query>
 
daves responded:  2010-04-01 10:51
OK, I'll check this out. It might be a bug, as this was the intended way to provide a name that would be different than the file name.
 
Ben Bimber responded:  2010-04-01 10:55
ok, thanks. i can provide a url if you need to see an example.

also, will changing the name impact SQL statements that reference this query? in a perfect world, there would be a param that behaved like 'columnTitle'. you could still use the less friendly name in code, while providing a user friendly title (possibly with spaces) that users see.
 
daves responded:  2010-04-01 14:19
Hi Ben,

This was indeed a bug, and I just checked in a fix for it on the trunk. I've also attached a patch file to this response in case you are building from 10.1 sources and want to include this fix. If not, then you'll have to rename your .sql file to change the name until 10.2 is released.

I agree that it would be nice to have a programmatic name vs user-displayed name for query definitions. The core query architecture doesn't allow for that currently, but it would be a relatively simply addition if you'd like to add that to your feature list for 10.2. Talk with Mark about getting this on the list and prioritized.

So for now, a query has a name, and that name is used both in queries that reference it and in the user interface.