$loadcols $colcount
Kelly Burgess
kellyb at montana.com
Mon Apr 18 08:07:48 UTC 2022
Hi Martin,
> I could not figure out what you are trying to do in this line:
> Calculate define as con("$definefromsqlclass('",tableName,"',columns,tSessionRef)")
> Do outList.[define]
If you want to dynamically define a list, for example, it might be nice if you could
Calculate cols as 'name,address,city,state,zipcode'
Do peopleList.$define([cols])
But that doesn't work. What does work is to include the notation verb in the string:
Calculate cols as 'name,address,city,state,zipcode'
Calculate define as con('$define(',cols,')')
Do peopleList.[define]
So I was doing that, but with $definefromsqlclass(). Expanding the define variable produces
Do outList.$definefromsqlclass('tPeople',columns,tSessionRef)
.. which allows me dynamic control over the table class name that I use in this generic export code.
> Is it possible to define a list from another list variable?
There's an old technique dating back to Omnis 5 or 7 that still works for ordinary lists, where you can use the Define list command and rather than supply a list of column fields, you can pass a list variable preceded by ^, and that will define a column for each list line, using the first list column as the name.
Do colList.$define(colName)
Do colList.$add('name')
Do colList.$add('address')
Do colList.$add('zip')
Set current list dynamicList
Define list {^colList} ## dynamicList is now defined for name,address,zip
But I think the only way to do that for $definefromsqlclass() is by using the second parameter containing a row whose column names identify the subset of schema columns to use. I think that you can also pass multiple column name parameters instead of a row, but I think you then lose the ability to pass any parameters through to your table class $construct. So I use a row, or an empty second parameter if I want the complete set of the table's schema columns. That way the session reference in the third parameter gets passed to my table superclass's $construct.
So if you're not interested in passing anything through to the table $construct, then you could adapt the define calculation above using $definefromsqlclass -
Calculate define as con("$definefromsqlclass('",tableName,"',columns,tSessionRef)")
and instead of ending it with 'columns,tSessionRef' and building that columns row variable, you could just concatenate each of the user-selected columns onto the end, delimited by commas and closed with a ).
Kelly
More information about the omnisdev-en
mailing list