LABKEY SQL capability to decode URI ?

LabKey Support Forum (Inactive)
LABKEY SQL capability to decode URI ? Leo Dashevskiy  2013-05-16 12:51
Status: Closed
 
Hi, guys!

Is there built-in syntax to convert a raw db entry such as:

/home/ldashevs/Labkey/flowFiles/RV144/@files/XML%20files/RV144%20Batch%201022.xml

into the 'proper' form of

/home/ldashevs/Labkey/flowFiles/RV144/@files/XML files/RV144 Batch 1022.xml

?

I could not find one. And if there isn't a built-in way, is there a mechanism to define a custom function in LABKEY SQL? If so, how? (Right now within my .sql file, which is the query source for a LABKEY.ext.Store, I just have a SELECT statement...)

Thanks.
-Leo
 
 
Matthew Bellew responded:  2013-05-16 13:14
There is not a SQL function that will do this. I think it shouldn't be too hard to add a load event on the store that translates these values in javascript using unescape().
 
Leo Dashevskiy responded:  2013-05-16 14:28
Thanks, Matt!

Yes, that's what I currently have to do, use the decodeURI() method in JavaScript in fact.

The thing is that I use the data from the same store/db table on several occasions and so must go through such a conversion each time I do - so instead wanted to convert at the source of it once.

Though, what you are suggesting is to convert the store's data once, right? And then I would be able to use it multiple times but already converted. I like that suggestion. I think there is a convert(record) way of doing it (not sure if it's within the load callback, I will dive into this...)
 
Leo Dashevskiy responded:  2013-05-20 08:23
Yeah, seems like decoding the data on load is the best option after all.

Specifying 'fields' config in either the store or within the reader seems to work initially, but the way the extended json reader works is if there is meta data passed in along with the data, then the initial configs get overwritten and I could not for the world of me figure out how to cancel such an overwrite...
 
Ben Bimber responded:  2013-05-20 08:38
hi leo,

are you using Ext3 or 4? The store will always override metadata on load (which generally makes sense); however, you can investigate one of these depending on your Ext version:

1) In either Ext version, listen for the Store's load event and iterate the records to make changes. this is less efficient, and I dont think there is a guarantee your listener will be called before other load listeners, but by far the easiest.

2) Either the store or reader should have an event that is something like 'metadatachange' (this name might be incorrect'), which is triggered when metadata loads. Your handler is passed the fields metadata object and you could modify it accordingly. This is sorta digging into the guts of Ext to make this work, but it is relatively clean if you get it working.
 
Leo Dashevskiy responded:  2013-05-21 10:02
Thanks, Ben!

I'm using Ext3 still.

Like I said, I ended up per Matt's suggestion decoding data on load, like you suggested in 1) (not sure why I would care if there is a guarantee my listener will be called before other load listeners...)

I did try fiddling with it like you mentioned in 2), but to no success: there is indeed 'metachange' even being fired by the store, but AFTER all reconfiguration already took place:

            if(this.reader.onMetaChange){
                this.reader.onMetaChange = this.reader.onMetaChange.createSequence(this.onMetaChange, this);
            }

where DataReader's this.reader.onMetaChange deletes the configuration from the passed in configs and reconfigures it based on the received metadata, then Store's this.onMetaChange fires the 'metachange' event. So I'm not sure what the proper approach here should be...