Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Stenvang on July 12, 2016, 11:48:26 pm
-
I'm trying to get all the Elements with object type "Class" within a single project root.
However the following SQL query finds the elements from every project root within my project.
SELECT * FROM t_object WHERE Object_Type = 'Class'
Couldn't find a solution in the documentation.
-
See here:
http://sparxsystems.com/forums/smf/index.php/topic,31067.0.html
That might help you.
-
Adding
and Package_ID in (#Branch#)
Will limit the results to only elements in the selected package and its subpackages.
So if you select the correct root the results will be limited to that root.
Geert
-
SELECT * FROM t_object
WHERE Object_Type = 'Class'
AND Package_ID in (#Branch#)
I run this from Find In Project/Builder/SQL and get the following error:
"Microsoft OLE DB Provider for ODBC Drivers. [MySQL] [ODBC 5.3(a) Driver][mysqld-5.5.27-log] You have an error in your SQL syntax; check the manual that corresponds to you MySQL server version for the right syntax to use near '' at line 3"
-
It only works in an actual SQL search.
Geert
-
So there is no way to do it from the Builder/SQL or Repository.SQLQuery() from the API?
I guess I just have to loop through the packages by code and then perform
SELECT * FROM t_object WHERE Object_Type = 'Class' AND t_object.Package_ID = <ID>
on each package then.
-
No, you'll have to do that yourself when using the API.
Here's the code I use:
'returns an ArrayList of the given package and all its subpackages recursively
function getPackageTree(package)
dim packageList
set packageList = CreateObject("System.Collections.ArrayList")
addPackagesToList package, packageList
set getPackageTree = packageList
end function
'add the given package and all subPackges to the list (recursively
function addPackagesToList(package, packageList)
dim subPackage as EA.Package
'add the package itself
packageList.Add package
'add subpackages
for each subPackage in package.Packages
addPackagesToList subPackage, packageList
next
end function
'make an id string out of the package ID of the given packages
function makePackageIDString(packages)
dim package as EA.Package
dim idString
idString = ""
dim addComma
addComma = false
for each package in packages
if addComma then
idString = idString & ","
else
addComma = true
end if
idString = idString & package.PackageID
next
'if there are no packages then we return "0"
if packages.Count = 0 then
idString = "0"
end if
'return idString
makePackageIDString = idString
end function
Geert