Class properties from class name
Hi,
I'd like to compare classes in two namespaces, whether the corresponding .cls code exist in both namespaces or not, and if it does exist in both namespaces, whether the CLS code is identical. If there is such a routine out there the better, I'd like to see it. If not, I know how to get a list of classes in each namespace and I can check currClss.TimeChanged. What I cannot find is the following:
- Programmatic access to cls routine code lines given the class name
- cls routine code size in bites as a crude approximation of cls files in two namespaces being different
- Can I compare classes or routines on two different servers?
I has no problem extracting size and code lines info for regular routines via
Thanks in advance,
Anna
Comments
First of all, classes code stored completely differently with plain routines. So, the best way to compare two namespaces is to export all the code in UDL format, which in fact the same as in Studio, usually it was just XML.
From my side I would recommend using VSCode for this task, there you can export any kind of source from InterSystems products with any version since 2016.2. How this process would look there.
- open any empty folder in VSCode
- Configure it to desired server and namespace
- export source code from InterSystems Explorer view
- do, git init, and commit all exported files
- delete all sources
- switch to another namespace, in the same explorer view, by just opening another namespace.
- export all sources again.
git will show the differences.
As I'm a developer of VSCode extension for InterSystems, you can contact me directly, or through public issues
Thanks, Dmitriy! Yes, I saw already that classes are stored differently. Our namespaces are huge and different enough though so looking through all their differences line by line is not necessarily practical.
P.S. I am looking forward to your VSCode add-on progress BTW :-). Tried it some time ago already.
I think this is a task better suited for Version Control System, such as git.
- Export all relevant code from the first namespace
- Commit
- Export all relevant code from the second namespace
- Diff
And for CD/CI systems such as Jenkins, GitHub or GitLab.
That said you can use this SQL to compare class hashes (if hashes are identical than classes are identical)
SELECT
Name,
Hash,
TimeChanged,
TimeCreated
FROM %Dictionary.CompiledClassAfter that you can use this SQL to compare hashes of the individual methods (if classes do not match):
SELECT
parent,
Name,
RuntimeHash
FROM %Dictionary.CompiledMethodThanks, Eduard! Queries look promising. Will they compare INT's or CLS's, given it's about CompiledClass?
Will they compare INT's or CLS's, given it's about CompiledClass?
No idea. Do you think someone might have edited generated int code directly?
Unlikely but could be. I'll look it up.
It looks like
s x=rs.Execute()
f {
s x=rs.Next() q:'x
s TimeChanged=rs.GetDataByName("TimeChanged")
s ClassName=rs.GetDataByName("ClassName")
s Hash1=rs.GetDataByName("Hash1")
s Hash2=rs.GetDataByName("Hash2")
s System=rs.GetDataByName("System")
s ClassType=rs.GetDataByName("ClassType")
s Size=rs.GetDataByName("Size")
}
P.S. Found the answer to my last question: https://cedocs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25Library.RemoteResultSet
Just need to figure out (or take an advice!) how to exclude, say, system classes outright.
Something like this should work:
WHERE 1=1
AND NOT name %STARTSWITH '%'
AND NOT name %STARTSWITH 'CSP'
AND NOT name %STARTSWITH 'Ens'
AND NOT name %STARTSWITH 'INFORMATION.SCHEMA'