Skip to main content
7-Bedrock
December 16, 2022
Solved

Windchill query with INSTR

  • December 16, 2022
  • 2 replies
  • 3462 views

Hello guys,

Could you please share an example of using Windchill Java api with function INSTR .

 

SQL e.g.
SELECT count(*)
FROM LCSPalette, LCSProduct
WHERE INSTR(LCSPalette.PTC_STR_12TYPEINFOLCSPALETTE, LCSProduct.PTC_STR_21TYPEINFOLCSPRODUCT) > 1

Best answer by HelesicPetr

Hi @IvanFeofilov 

The Christmas is coming 😄

 

The sql function what you need is it an IN_STRING? it has just different internal name in the SQLFunction API but it could be what you need.  

 

HelesicPetr_0-1671606087260.png

 

Here I share an example, how the function can be used in querySpec, but with different function types.

 

 

QuerySpec querySpec = new QuerySpec();
			querySpec.setAdvancedQueryEnabled(true);

			int processQueueINT = querySpec.appendClassList(ProcessingQueue.class, true);
			int queryEntryINT = querySpec.appendClassList(QueueEntry.class, true);
			ClassAttribute classAttribute = new ClassAttribute(ProcessingQueue.class, "name");
			SQLFunction sqlFunction1 = SQLFunction.newSQLFunction("LENGTH", new ColumnExpression[]{classAttribute});
			SQLFunction sqlFunction2 = SQLFunction.newSQLFunction("SUB_STRING", new ColumnExpression[]{classAttribute, sqlFunction1, new ConstantExpression(1)});
			SearchCondition not_in = new SearchCondition(sqlFunction2, "NOT IN", new ArrayExpression(new String[]{"H", "L", "M"}));
			SearchCondition like = new SearchCondition(ProcessingQueue.class, "name", "LIKE", "PublisherQueue%");
			SearchCondition procesingID = new SearchCondition(ProcessingQueue.class, "thePersistInfo.theObjectIdentifier.id", QueueEntry.class, "queueRef.key.id");

			querySpec.appendWhere(not_in, processQueueINT);
			querySpec.appendAnd();
			querySpec.appendWhere(like, processQueueINT);
			querySpec.appendAnd();
			querySpec.appendWhere(procesingID, processQueueINT, queryEntryINT);

QueryResult jobQS = PersistenceServerHelper.manager.query(querySpec);

 

 

Hope this can help.

 

PetrH

2 replies

avillanueva
23-Emerald I
23-Emerald I
December 16, 2022

This is not really part of Windchill API per say but core Java. Its the indexOf() method.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#indexOf(java.lang.String)

ahh, but I see you are looking for building a QuerySpec? Then you want wt.query.SQLFunction class. It has all the functions listed there.

In your installation, you can view the JavaDoc API here:

<hostname>/Windchill/wt/clients/library/api/wt/query/SQLFunction.html

HelesicPetr
22-Sapphire II
22-Sapphire II
December 19, 2022

Hi @avillanueva 

He maybe means the wt.query.QuerySpec

 

I've never found documentation for it. @IvanFeofilov needs to experiment with the definition of query conditions.

 

PetrH

7-Bedrock
December 19, 2022

Yes,

Interesting in example of wt.query.SQLFunction with MINUS or INTERSECT Compound Statements (wt.query.CompoundQuerySpec)

joe_morton
18-Opal
18-Opal
December 19, 2022

Are you trying to use the "In String" function in a query builder report? Database Functions for query builder are documented here: http://support.ptc.com/help//wnc/r12.1.0.0/en/index.html#page/Windchill_Help_Center/querybuilder/QBSelectOrConstrainDatabaseFunction.html

 

 

7-Bedrock
December 20, 2022

Yes, but how I can transform QML into Windchill query API?

7-Bedrock
December 20, 2022

Are you kidding?

I mean using Windchill Java QueryStatement