Author Topic: Generic Database Query  (Read 7388 times)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Generic Database Query
« on: July 09, 2014, 07:58:26 pm »
I create a search query to find particular packages.  
I want the query to consider Oracle databases in addition to simple Access (.eap) repositories.

However, the #wc# used as a generic wild-card character, does not work for me.
  
When I execute the following query I get the expected packages.
Code: [Select]
SELECT t_package.Package_ID FROM t_package
WHERE t_package.PackageFlags LIKE '*VCCFG=*CheckedOutTo=*'
 
  
But this generic query gives no results at all:  
Code: [Select]
SELECT t_package.Package_ID FROM t_package
WHERE t_package.PackageFlags LIKE '#WC#VCCFG=#WC#CheckedOutTo=#WC#'
 
  
Any ideas?
« Last Edit: July 09, 2014, 08:17:24 pm by avoda234 »

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Generic Database Query
« Reply #1 on: July 09, 2014, 08:26:10 pm »
Hi,

that should work with all supported database.

But keep in mind: You have to define a Search and not just change the tab from Search Builder to SQL. The SQL have to be in the "Search tab".

The EA standard Search 'My Checked Out Packages' shows it.

The easieast way is to copy an SQL Search like the above and change the SQL string.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Generic Database Query
« Reply #2 on: July 09, 2014, 08:48:44 pm »
Quote
Hi,

that should work with all supported database.

But keep in mind: You have to define a Search and not just change the tab from Search Builder to SQL. The SQL have to be in the "Search tab".

The EA standard Search 'My Checked Out Packages' shows it.

The easieast way is to copy an SQL Search like the above and change the SQL string.

Helmut

Why is it necessary to define a search?
I execute these queries programmatically, does it matter?
« Last Edit: July 09, 2014, 10:09:29 pm by avoda234 »

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Generic Database Query
« Reply #3 on: July 09, 2014, 09:22:30 pm »
Hi,

ask SPARX why it is this way.

Macros like #WC# only works in EA Searches. Quick search via SQL tab or via API only works with poor SQL for the database you work against.

If you choose API you may change the SQL string dependent the current repository you are working with.

A good introduction to SQL-Query for EA you find in Thomas Kilians eBook InsideEA.  

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Generic Database Query
« Reply #4 on: July 09, 2014, 10:09:31 pm »
You can also run such a user defined query from within the API. Still off-site, so you need to check the help yourself. It's either in Repository or in ProjectInterface.

You'd need to raise a feature request if you want to run such a #-query on the fly from automation.

Figuring out the #WC# is not too difficult after all. Just check the ConnectionString and have a table according to the found RDBMS.

q.
« Last Edit: July 09, 2014, 10:12:43 pm by qwerty »

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Generic Database Query
« Reply #5 on: July 09, 2014, 10:11:24 pm »
Quote
Hi,

ask SPARX why it is this way.

Macros like #WC# only works in EA Searches. Quick search via SQL tab or via API only works with poor SQL for the database you work against.

If you choose API you may change the SQL string dependent the current repository you are working with.

A good introduction to SQL-Query for EA you find in Thomas Kilians eBook InsideEA.  

Helmut

So there is no way to execute a generic query via add-in?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Generic Database Query
« Reply #6 on: July 09, 2014, 10:13:25 pm »
See above :-)

q.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Generic Database Query
« Reply #7 on: July 10, 2014, 09:42:18 am »
Quote
Figuring out the #WC# is not too difficult after all. Just check the ConnectionString and have a table according to the found RDBMS.
Can also use Repository.RepositoryType() to more easily get the type of database you are currently connected to.  According to the release notes this was introduced in EA 10.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Generic Database Query
« Reply #8 on: July 10, 2014, 06:23:30 pm »
Quote
Quote
It looks like I should once again go through the API to find out what it new (to me).

q.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Generic Database Query
« Reply #9 on: July 10, 2014, 08:04:08 pm »
Quote
Quote
Figuring out the #WC# is not too difficult after all. Just check the ConnectionString and have a table according to the found RDBMS.
Can also use Repository.RepositoryType() to more easily get the type of database you are currently connected to.  According to the release notes this was introduced in EA 10.

Thanks.
I thought a local EAP file is Access based, but using  Repository.RepositoryType() returns JET.

Is it incorrect?
How can it help me to figure if it is an Access or Oracle DBMS?
« Last Edit: July 10, 2014, 08:04:35 pm by avoda234 »

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Generic Database Query
« Reply #10 on: July 10, 2014, 10:26:46 pm »
Hi,

as far as I remember is the connection string good for non JET databases. The problems are *.eap shortcuts.

As far as I remember you don't have this problem with repository.RepositoryType().

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Generic Database Query
« Reply #11 on: July 11, 2014, 09:50:16 am »
JET == Access
See: http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine

If RepositoryType() returns "JET", it's a pretty safe bet you are working with an EAP file.

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Generic Database Query
« Reply #12 on: July 11, 2014, 03:52:18 pm »
Hi Helmut,

you are right. If you are using shortcuts, the connection string won't help.

Best regards

Stefan
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Generic Database Query
« Reply #13 on: July 11, 2014, 08:01:08 pm »
Quote
Hi,

as far as I remember is the connection string good for non JET databases. The problems are *.eap shortcuts.

As far as I remember you don't have this problem with repository.RepositoryType().

Helmut
You are right. Now it comes to my mind that before introducing the RepositoryType one needed to look at the file size if it was an EAP and if smaller than 1M assuming it was a shortcut. Then you could read the contents and find the real connection string.

q.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Generic Database Query
« Reply #14 on: July 11, 2014, 08:20:51 pm »
Hi,

that was the way I did until I got aware of repository.RepositoryType().

Helmut

Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)