Author Topic: SQL Search - how to include search term in query?  (Read 5221 times)

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
SQL Search - how to include search term in query?
« on: March 13, 2008, 01:39:05 pm »
Any ideas?  or am I just not reading the help properly.

For example, I want to return the types and number of diagrams that have the search term in their name as follows:

select t_diagram.diagram_type, count(*)
from t_diagram
where name like '<search_term>'
group by t_diagram.diagram_type

Questions are:
1. Can I include the users search term in the query?
2. What syntax does EA expect so it can substitute the search term?

Cheers,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: SQL Search - how to include search term in que
« Reply #1 on: March 13, 2008, 09:54:13 pm »
What exactly do you mean?

I've recently plugged one of these into an automation project, and it worked like a charm. I just treated it as plain old SQL - and didn't make any assumptions about syntax; nothing even remotely fancy - and it seemed to work right out of the box.

Are you trying to set this up as something in the UI. Sort of 'click and go?'

David
No, you can't have it!

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: SQL Search - how to include search term in que
« Reply #2 on: March 14, 2008, 06:51:13 am »
Hi David,

I'm using the native EA search facility.  3 options - query builder, SQL editor or add-in.

For the SQL editor - you get a dialogue in EA where you can paste in a SQL statement.  That's great and I can put in something like

select * from t_object.

My question is - Does the EA UI apply your search term "after" the result set is retured the client and filters the resut set on any column where the term is contained:
or
can you specify the search term within your query. ie:

select * from t_object where name = :search_term

or similar.

If I do

select * from t_object

The search term never seems to be applied to the results, ie. whatever I type in the search term when I run the query just dumps the whole of the t_object table to the search window unfilterred.

Hope that makes sense.

The same issue would apply to an add-in search method.... how do you pass in the user entered search term to the add-in method call?  What syntax do you use?

Cheers,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: SQL Search - how to include search term in que
« Reply #3 on: March 14, 2008, 08:29:28 am »
I'll answer the last question now; I've not thought the first part out yet.

I just construct a string, which I can do at run-time, since my user needs to pick something from a list, which I use to filter. [Sometimes it is a package, other times a diagram.] The string is a normal SQL command. Something like:

Dim foo as String = "SELECT * FROM t_object WHERE Package_ID = '" & MyPackage.Package_ID.ToString & "'"

I then use this as the parameter to Repository.SQLQuery. I load the resulting string into an XML document and I'm all set.

I find this much less of a bother than trying to use RunModelSearch.

HTH, David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: SQL Search - how to include search term in que
« Reply #4 on: March 14, 2008, 10:36:42 am »
The search term can be directly substituted in your search sql for the string '<Search Term>' (without quotes).

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: SQL Search - how to include search term in que
« Reply #5 on: March 14, 2008, 02:02:10 pm »
Thanks Simon - that's exactly what I wanted.  Suggest Roy etc.. add this to the help (I couldn't find it).

Thanks again - (tell your boss to give you a bonus)
David.
 :)
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Re: SQL Search - how to include search term in que
« Reply #6 on: March 14, 2008, 03:07:13 pm »
I have changed the initial example SQL statement in Create Search Definitions to:

SELECT * FROM t_object WHERE NAME='<Search Term>'

Not sure if Simon meant that the quotes were not needed for the actual substituted search term, but they are need in the above statement.

Can I have a bonus too?
Best Regards, Roy

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: SQL Search - how to include search term in que
« Reply #7 on: March 14, 2008, 03:44:33 pm »
To clarify what I said,

If you ran a search with the following sql and the search term Bah

SELECT * FROM t_object WHERE NAME='Foo<Search Term>'

The actual sql that will be executed is

SELECT * FROM t_object WHERE NAME='FooBah'