GeertBellekens / Enterprise-Architect-Toolpack

Addins and tools for Sparx Systems Enterprise Architect
https://bellekens.com/product/bellekens-enterprise-architect-toolpack/
BSD 2-Clause "Simplified" License
97 stars 39 forks source link

EAValidator: filter by branch fails on PostgreSQL #105

Closed rbertucat closed 5 years ago

rbertucat commented 5 years ago

Using EAValidator on PostgreSQL works well after I slightly adapted my SQL queries.

However, when changing the scope of the validation (e.g. by selecting a sub-package in the Scope section > Element), only the current package id is returned when executing the query, and not the whole tree. That means that when selecting a package of higher level in the tree, the validation does not occur on the enclosed packages.

It works well on the EAPX file (correct packageTreeIDString is returned).

https://github.com/GeertBellekens/Enterprise-Architect-Toolpack/blob/6ff237112e23b2849143bf9c905684eb8d86ee7d/EAValidator/EAValidatorController.cs#L149

Somehow, I guess this is related to the Package.cs method to resolve the package tree.

GeertBellekens commented 5 years ago

Yes. The problem is probably related to casing in the database schema in PostgreSQL. The column t_package.Package_ID is lowercase in PostgreSQL t_package.pakage_id That's probably the reason why foreach (XmlNode packageIdNode in queryResult.SelectNodes("//Package_ID")) is not working.

Solution might be to change the query to read select p.Package_ID as Package_ID from t_package...

rbertucat commented 5 years ago

I can test it if you please provide the installer.

However, I'm not sure that's going to work. For EAValidator queries to work with PostgreSQL, I had to quote the table names in the SQL queries in the checks XML files, due to how PostgreSQL handles table names.

GeertBellekens commented 5 years ago

Here a new installer with this change https://drive.google.com/open?id=1o7nCpeXybNyHVQAAvV39q2BTX_n6-9Bc If this doesn't work I'll have to install PostgreSQL on development machine to test.

rbertucat commented 5 years ago

Thanks for the installer. Unfortunately, this version 2.0.13.27324 didn't fix the issue.

GeertBellekens commented 5 years ago

I'll install Postgres and debug...

rbertucat commented 5 years ago

I had to quote the column name actually and not the table name as I previously wrote to make my XML check files work:

SELECT o.ea_guid AS "ItemGuid"

However, that does not seem to work with JET.

What should work is to use lower case for the column name (tried on the SQL Scratch Pad in EA):

string getSubpackageSQL = "select p.Package_ID as package_id from t_package p where p.Parent_ID in (" + parentIDString + ")";
var queryResult = this.EAModel.SQLQuery(getSubpackageSQL);
foreach (XmlNode packageIdNode in queryResult.SelectNodes("//package_id"))
GeertBellekens commented 5 years ago

Found the problem. I forgot to format the XPath. The method formatXPath sets it to lowercase for Postgres repositories. foreach (XmlNode packageIdNode in queryResult.SelectNodes(this.EAModel.formatXPath("//Package_ID")))

Please try https://drive.google.com/open?id=1oAWG7E4JaQ5PvQnFkNRS24Fy6VSlobxk

rbertucat commented 5 years ago

works well, thanks! that fixed the issue.