Chris,
[quote=“chris_d_sanders”]Ok, I believe I understand most of this. Except this part:
selectedIDs = ['%s' % id for id in listComponent.data.IDColumn]
inClause = ','.join(selectedIDs)
Here is what one query MIGHT look like:
SELECT Recipe, t_stamp
FROM Recipe
WHERE Recipe IN ('62886AXA.001', '44246AMA.017')
AND t_stamp
BETWEEN '2009-11-01 00:00:00' AND '2009-11-12 00:00:00'
And this works. I’m just not sure how to get the
WHERE Recipe IN ('62886AXA.001', '44246AMA.017')
How do i [quote]You will need to iterate over the selected items in the list component and add each selected RecipeID to a python list. You would then convert the list to a comma separated list using a stirng join. [/quote][/quote]
I’m sorry, my suggestion was a little cryptic and didn’t have a lot of explanation. I’ll try to explain it better.
The line selectedIDs = ['%s' % id for id in listComponent.data.IDColumn]
is a list comprehension. At first, they’re a little cryptic but they are quite powerful. The basic purpose of a list comprehension is to apply an expression to a list (more technically, an iterative item such as a list or tuple), concatenating the results into another list. It’s sort of an abbreviated for or while loop. List comprehensions also have an optional “if” clause that can limit which items in the iterative item will have the expression applied. (See this for more discussion: http://books.google.com/books?id=VnGkf92gQh4C&pg=PA58&lpg=PA58&dq=jython+list+comprehension&source=bl&ots=y1G54gg6fM&sig=gmJ9BegCd5oF70CPjFO1SUdDctY&hl=en&ei=hewCS56DD8utlAeZveXcAQ&sa=X&oi=book_result&ct=result&resnum=6&ved=0CBkQ6AEwBQ#v=onepage&q=jython%20list%20comprehension&f=false)
Dissecting the line, the beginning and ending square brackets define the start and end of the list comprehension. The code before the ‘for’ is the expression that gets applied to each item in the iterative item following the ‘for’.
In my pseudo-code, I made the assumption that the ids were integers which needed to be converted to strings. So the purpose of the list comprehension was to convert the integers to strings. The “’%s’ % id” simply applied the % operator to each id in the list of ids.
But it looks like the ids are alphanumeric strings already and therefore would not need to be converted. You don’t need the list comprehension in your particular case.
The line “inClause = ‘,’.join(selectedIDs)” simply generates a comma separated list of the ids. So if selectedIDs = [‘62886AXA.001’, ‘44246AMA.017’], it would generate the string “‘62886AXA.001’, ‘44246AMA.017’”. I prefer to use the string join method because one doesn’t have to worry about any trailing commas as Step7 pointed out in his example.
Regarding your question about assigning the query to a dynamic property: You can assign the resulting query string to a dynamic property. You don’t have to use it in a query directly. Your script would end with something like this:
event.source.parent.DynamicProperty = query
The exact syntax for the dynamic property reference will depend on where it is defined and from which component the event was generated.
The following assumes that you’re firing a script from an event. But is you’re wanting to generate the query with a FPMI expression, that’s a different ball of wax which I don’t have time to address right now. If that’s the case, just let me know and I, or someone else, will work up an example of that later.