Book a Demo

Author Topic: Repository method SQLQuery() with aggregate function in select statement  (Read 3824 times)

wzr

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Hello,

I'm currently trying to use COUNT or AVG functions in my query for the the Repository.SQLQuery() call.
Even though the very simple query works fine using the SQL Scratch Pad by GUI, it leads to a kind of scaring Error Popup when using it with the API method.

The simple (and useless) example
Code: [Select]
SELECT AVG(t_object.Object_ID) FROM t_object
leads to the messange "Error processing XML document:" and additional in german (system language) something like "to create nodes of type 'ELEMENT' you need to declare a valid name".

I wasnt aware of processing a XML document at all and even more I dont want to create an Element-Node  :-\

Does anyone know whats happening here?
The DB is running on a MS SQL Server. After transfering the same DB to a local project (MS JET?) the same call creates a proper result without the error message.

Thank you!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Repository method SQLQuery() with aggregate function in select statement
« Reply #1 on: February 13, 2022, 08:42:25 pm »
The reason is that you haven't specified a column name for your calculated result.
EA is trying to convert the results to an xml string, but can't because nodes need a valid name

Try this:

Code: [Select]
SELECT AVG(t_object.Object_ID) as myAverage FROM t_object
Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Repository method SQLQuery() with aggregate function in select statement
« Reply #2 on: February 13, 2022, 08:50:32 pm »
Muhaha. Sunday morning. I just was about to propose the same xD

q.

wzr

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Repository method SQLQuery() with aggregate function in select statement
« Reply #3 on: February 13, 2022, 08:53:03 pm »
Thank you Geert, it's working now!

I was just checking the XML result without column name in the local DB which looks like that
Code: [Select]
<Expr1000>44134,134468</Expr1000>
Is it possible that the SQL Server is trying to process this somehow because the node is called Expr...?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Repository method SQLQuery() with aggregate function in select statement
« Reply #4 on: February 13, 2022, 11:44:39 pm »
Thank you Geert, it's working now!

I was just checking the XML result without column name in the local DB which looks like that
Code: [Select]
<Expr1000>44134,134468</Expr1000>
Is it possible that the SQL Server is trying to process this somehow because the node is called Expr...?
I don't think that's it. I think the problem is that the resulting column actually doesn't have a name.
If I execute such a query in SSMS I get "no column name)" as heading, but presumably that is not in the actual resultset, but something the GUI makes of it.

Now if EA gets the resultset of the query, and blindly tries to create XML nodes based upon the column names in the resultset, you would get an error if a certain column in the resultset doesn't have a name.

One could argue that this is a bug in EA, but the workaround is easy enough, so I wouldn't bother sending in a bug report.
There are more serious bugs that need fixing.

Geert